devise_invitable 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise_invitable might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a36c592f8c636eb4cf7e704165f41abc0c14c5
4
- data.tar.gz: 9a999cc7bc9523e1b100ce415aee6270d8a9fc66
3
+ metadata.gz: 120262595eb64c2331645be7ee5b72be56cf69dd
4
+ data.tar.gz: 9cf5ffa08b34fe9d69e09272c23f92800b0357f6
5
5
  SHA512:
6
- metadata.gz: ca000182ea194f46655066899e531094801c347461926d8185fa8a039208af55d108c6a35cad22bfa31e60d7cad63b62203cf18b9e39a43702dcedd815cb9c33
7
- data.tar.gz: 66e68e6a7facedfdb0752f4d4b1310e255cdcd33892f816158149154e94a2104d71b88a80af3672fd9a325984666770c66cf115a85758e7b57273d9ef3bee00a
6
+ metadata.gz: 2f73d12b8a22bb35067552438a6fa394e150525c54de6e3d25372b0a0d345b4ec74332cdd190075b1b5f4b82b34413115ec1fb650ab83cf20acc3345906daae4
7
+ data.tar.gz: a24d5a8744f72552413216e8f7947ff58a7be06fcbc2683cd9caaa9fc4a90b4384b4c89f54c2aa9930bf369da289922dbb9b445824de139f685671a9a6e48a1b
@@ -1,15 +1,8 @@
1
1
  class Devise::InvitationsController < DeviseController
2
- if Rails::VERSION::MAJOR >= 5
3
- prepend_before_action :authenticate_inviter!, :only => [:new, :create]
4
- prepend_before_action :has_invitations_left?, :only => [:create]
5
- prepend_before_action :require_no_authentication, :only => [:edit, :update, :destroy]
6
- prepend_before_action :resource_from_invitation_token, :only => [:edit, :destroy]
7
- else
8
- prepend_before_filter :authenticate_inviter!, :only => [:new, :create]
9
- prepend_before_filter :has_invitations_left?, :only => [:create]
10
- prepend_before_filter :require_no_authentication, :only => [:edit, :update, :destroy]
11
- prepend_before_filter :resource_from_invitation_token, :only => [:edit, :destroy]
12
- end
2
+ prepend_before_action :authenticate_inviter!, :only => [:new, :create]
3
+ prepend_before_action :has_invitations_left?, :only => [:create]
4
+ prepend_before_action :require_no_authentication, :only => [:edit, :update, :destroy]
5
+ prepend_before_action :resource_from_invitation_token, :only => [:edit, :destroy]
13
6
 
14
7
  if respond_to? :helper_method
15
8
  helper_method :after_sign_in_path_for
@@ -2,7 +2,7 @@
2
2
 
3
3
  <%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => { :method => :put } do |f| %>
4
4
  <%= devise_error_messages! %>
5
- <%= f.hidden_field :invitation_token %>
5
+ <%= f.hidden_field :invitation_token, readonly: true %>
6
6
 
7
7
  <% if f.object.class.require_password_on_accepting %>
8
8
  <p><%= f.label :password %><br />
@@ -84,4 +84,4 @@ module Devise
84
84
  @@require_password_on_accepting = true
85
85
  end
86
86
 
87
- Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => {:invitation => [nil, :new, :accept]}
87
+ Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/models', :route => {:invitation => [nil, :new, :accept]}
@@ -3,19 +3,20 @@ module DeviseInvitable::Controllers::Helpers
3
3
 
4
4
  included do
5
5
  end
6
-
6
+
7
7
  def after_invite_path_for(inviter, invitee = nil)
8
- after_sign_in_path_for(inviter)
8
+ signed_in_root_path(inviter)
9
9
  end
10
-
10
+
11
11
  def after_accept_path_for(resource)
12
- after_sign_in_path_for(resource)
12
+ signed_in_root_path(resource)
13
13
  end
14
-
14
+
15
15
  protected
16
+
16
17
  def authenticate_inviter!
17
18
  send(:"authenticate_#{resource_name}!", :force => true)
18
19
  end
19
-
20
+
20
21
  end
21
22
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/deprecation'
2
+ require 'devise_invitable/models/authenticatable'
2
3
 
3
4
  module Devise
4
5
  module Models
@@ -96,7 +97,7 @@ module Devise
96
97
  self.accept_invitation
97
98
  self.confirmed_at = self.invitation_accepted_at if self.respond_to?(:confirmed_at)
98
99
  self.save
99
- end
100
+ end.tap { @accepting_invitation = false }
100
101
  end
101
102
  end
102
103
 
@@ -167,6 +168,11 @@ module Devise
167
168
  super unless !accepting_invitation? && block_from_invitation?
168
169
  end
169
170
 
171
+ # Prevent password changed email when accepting invitation
172
+ def send_password_change_notification?
173
+ super && !accepting_invitation?
174
+ end
175
+
170
176
  # Enforce password when invitation is being accepted
171
177
  def password_required?
172
178
  (accepting_invitation? && self.class.require_password_on_accepting) || super
@@ -0,0 +1,11 @@
1
+ module Devise
2
+ module Models
3
+ module Authenticatable
4
+ BLACKLIST_FOR_SERIALIZATION.concat %i[
5
+ invitation_token invitation_created_at invitation_sent_at
6
+ invitation_accepted_at invitation_limit invited_by_type
7
+ invited_by_id invitations_count
8
+ ]
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '1.7.2'
2
+ VERSION = '1.7.3'
3
3
  end
@@ -6,7 +6,13 @@ module ActiveRecord
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
8
  def copy_devise_migration
9
- migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}.rb"
9
+ migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}.rb", migration_version: migration_version
10
+ end
11
+
12
+ def migration_version
13
+ if Rails.version.start_with? '5.'
14
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
15
+ end
10
16
  end
11
17
  end
12
18
  end
@@ -1,4 +1,4 @@
1
- class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
1
+ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
2
  def up
3
3
  change_table :<%= table_name %> do |t|
4
4
  t.string :invitation_token
@@ -31,7 +31,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
31
31
 
32
32
  # sign_up the invitee
33
33
  assert_difference('ActionMailer::Base.deliveries.size') do
34
- post :create, :user => {:email => invitee_email, :password => "1password", :bio => '.'}
34
+ post :create, params: {:user => {:email => invitee_email, :password => "1password", :bio => '.'}}
35
35
  end
36
36
 
37
37
  @invitee = User.where(:email => invitee_email).first
@@ -57,7 +57,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
57
57
  register_email = "invitee@example.org"
58
58
  # sign_up the invitee
59
59
  assert_difference('ActionMailer::Base.deliveries.size') do
60
- post :create, :user => {:email => register_email, :password => "1password", :bio => '.'}
60
+ post :create, params: {:user => {:email => register_email, :password => "1password", :bio => '.'}}
61
61
  end
62
62
  assert_nil @controller.current_user
63
63
 
@@ -85,7 +85,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
85
85
 
86
86
  assert_nil Admin.where(:email => invitee_email).first
87
87
 
88
- post :create, :admin => {:email => invitee_email, :password => "1password"}
88
+ post :create, params: {:admin => {:email => invitee_email, :password => "1password"}}
89
89
 
90
90
  @invitee = Admin.where(:email => invitee_email).first
91
91
  assert @invitee.encrypted_password.present?
@@ -95,14 +95,14 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
95
95
  @request.env["devise.mapping"] = Devise.mappings[:admin]
96
96
  invitee_email = "invitee@example.org"
97
97
 
98
- post :create, :admin => {:email => invitee_email, :password => "1password"}
98
+ post :create, params: {:admin => {:email => invitee_email, :password => "1password"}}
99
99
  assert_response 302
100
100
 
101
101
  @invitee = Admin.where(:email => invitee_email).first
102
102
  assert @invitee.encrypted_password.present?
103
103
 
104
104
  sign_out @invitee
105
- post :create, :admin => {:email => invitee_email, :password => "2password"}
105
+ post :create, params: {:admin => {:email => invitee_email, :password => "2password"}}
106
106
  assert_response 200
107
107
  assert_equal @invitee.encrypted_password, Admin.where(:email => invitee_email).first.encrypted_password
108
108
  assert @controller.send(:resource).errors.present?
@@ -252,7 +252,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
252
252
  sign_in_as_user admin
253
253
 
254
254
  send_invitation new_admin_path
255
- assert_equal edit_admin_registration_path(admin), current_path
255
+ assert_equal root_path, current_path
256
256
  assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
257
257
  end
258
258
 
@@ -261,7 +261,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
261
261
  sign_in_as_user admin
262
262
 
263
263
  send_invitation new_free_invitation_path
264
- assert_equal edit_admin_registration_path(admin), current_path
264
+ assert_equal root_path, current_path
265
265
  assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
266
266
  end
267
267
  end
@@ -619,6 +619,24 @@ class InvitableTest < ActiveSupport::TestCase
619
619
  refute_predicate user, :confirmed?
620
620
  end
621
621
 
622
+ test 'should not send password change notification when accepting invitation' do
623
+ send_password_change_notification = User.send_password_change_notification
624
+
625
+ begin
626
+ User.send_password_change_notification = true
627
+
628
+ user = User.invite!(:email => "valid@email.com")
629
+
630
+ assert_no_difference('ActionMailer::Base.deliveries.size') do
631
+ user.password = user.password_confirmation = '123456789'
632
+ user.accept_invitation!
633
+ end
634
+
635
+ ensure
636
+ User.send_password_change_notification = send_password_change_notification
637
+ end
638
+ end
639
+
622
640
  def assert_callbacks_fired(callback, user)
623
641
  assert_callbacks_status callback, user, true
624
642
  end
@@ -1,6 +1,6 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
- before_filter :configure_permitted_parameters, :if => :devise_controller?
3
+ before_action :configure_permitted_parameters, :if => :devise_controller?
4
4
 
5
5
  protected
6
6
  def after_sign_in_path_for(resource)
@@ -1,5 +1,5 @@
1
1
  class UsersController < ApplicationController
2
- before_filter :authenticate_user!
2
+ before_action :authenticate_user!
3
3
 
4
4
  def index
5
5
  user_session[:cart] = "Cart"
@@ -56,7 +56,7 @@ class User < PARENT_MODEL_CLASS
56
56
  object.after_invitation_accepted_callback_works = true
57
57
  end
58
58
 
59
- def send_devise_notification(method, raw, *args)
59
+ def send_devise_notification(method, raw=nil, *args)
60
60
  Thread.current[:token] = raw
61
61
  super
62
62
  end
@@ -1,4 +1,4 @@
1
- class CreateTables < ActiveRecord::Migration
1
+ class CreateTables < (Rails.version < '5.1' ? ActiveRecord::Migration : ActiveRecord::Migration[5.0])
2
2
  def change
3
3
  create_table :users do |t|
4
4
  ## Database authenticatable
@@ -36,4 +36,11 @@ class ActionController::TestCase
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ if Rails.version < '5.0.0'
41
+ def post(action, *args)
42
+ hash = args[0] || {}
43
+ super action, hash[:params], hash[:session], hash[:flash]
44
+ end
45
+ end
39
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2018-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,8 @@ files:
75
75
  - lib/devise_invitable/inviter.rb
76
76
  - lib/devise_invitable/mailer.rb
77
77
  - lib/devise_invitable/mapping.rb
78
- - lib/devise_invitable/model.rb
78
+ - lib/devise_invitable/models.rb
79
+ - lib/devise_invitable/models/authenticatable.rb
79
80
  - lib/devise_invitable/parameter_sanitizer.rb
80
81
  - lib/devise_invitable/rails.rb
81
82
  - lib/devise_invitable/routes.rb