devise_invitable 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of devise_invitable might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.rdoc +23 -29
- data/app/controllers/devise/invitations_controller.rb +30 -30
- data/app/controllers/devise_invitable/registrations_controller.rb +11 -11
- data/app/views/devise/invitations/edit.html.erb +1 -1
- data/app/views/devise/mailer/invitation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/invitation_instructions.text.erb +1 -1
- data/lib/devise_invitable.rb +2 -1
- data/lib/devise_invitable/controllers/helpers.rb +3 -4
- data/lib/devise_invitable/inviter.rb +4 -3
- data/lib/devise_invitable/mapping.rb +6 -5
- data/lib/devise_invitable/models.rb +10 -11
- data/lib/devise_invitable/parameter_sanitizer.rb +18 -18
- data/lib/devise_invitable/routes.rb +1 -1
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/devise_invitable/install_generator.rb +4 -3
- data/test/generators/views_generator_test.rb +7 -6
- data/test/integration_tests_helper.rb +0 -1
- data/test/rails_app/app/controllers/admins_controller.rb +4 -3
- data/test/rails_app/app/controllers/application_controller.rb +10 -9
- data/test/rails_app/app/controllers/free_invitations_controller.rb +12 -9
- data/test/rails_app/config/initializers/devise.rb +4 -3
- data/test/test_helper.rb +4 -17
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 60a516052fe7d7f32929e0d35df374e05405951924011c1e7922c046fd8f8f73
         | 
| 4 | 
            +
              data.tar.gz: 4b790b2133f56ecd6dc5ac1736976bc1a689478e2094f093cfcb4ea2d19e1a39
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5fa8ed65bcf5ae7647aa798e9f63bbe20d19e0d87e28e1f0dc44f04dcc406e16980ffaa09cf94bb66ac6219c0d4d29829bafdd4fd3cdd86c2b628647ff05e14d
         | 
| 7 | 
            +
              data.tar.gz: 9fcff0bb96a9c6f81345c772b48ecace9bb446583328ac942d521c292533dae8132078a3593d30419c48abae381a8c87a4519e97d73dca2a76bfb15702334af8
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,6 @@ | |
| 1 | 
            +
            ## 2.0.1
         | 
| 2 | 
            +
            - Use per-model allow_insecure_sign_in_after_accept ([#790](https://github.com/scambra/devise_invitable/pull/790))
         | 
| 3 | 
            +
             | 
| 1 4 | 
             
            ## 2.0.0
         | 
| 2 5 | 
             
            - Remove deprecated devise_error_messages! from templates ([#786](https://github.com/scambra/devise_invitable/pull/785))
         | 
| 3 6 | 
             
            - Drop Devise < 4.6 support ([#786](https://github.com/scambra/devise_invitable/pull/786))
         | 
    
        data/README.rdoc
    CHANGED
    
    | @@ -70,11 +70,6 @@ or for a model that already exists, define a migration to add DeviseInvitable to | |
| 70 70 | 
             
                  add_column :users, :invited_by_id, :integer
         | 
| 71 71 | 
             
                  add_column :users, :invited_by_type, :string
         | 
| 72 72 | 
             
                  add_index :users, :invitation_token, unique: true
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                  # Allow null encrypted_password
         | 
| 75 | 
            -
                  change_column_null :users, :encrypted_password, :string, true
         | 
| 76 | 
            -
                  # Allow null password_salt (add it if you are using Devise's encryptable module)
         | 
| 77 | 
            -
                  change_column_null :users, :password_salt, :string, true
         | 
| 78 73 | 
             
              end
         | 
| 79 74 |  | 
| 80 75 | 
             
            If you previously used devise_invitable with a <tt>:limit</tt> on <tt>:invitation_token</tt>, remove it:
         | 
| @@ -109,13 +104,13 @@ Remember to create indexes within the MongoDB database after deploying your chan | |
| 109 104 |  | 
| 110 105 | 
             
            DeviseInvitable adds some new configuration options:
         | 
| 111 106 |  | 
| 112 | 
            -
            * <tt>invite_for</tt>: The period the generated invitation token is valid | 
| 107 | 
            +
            * <tt>invite_for</tt>: The period the generated invitation token is valid. After this period, the invited resource won't be able to accept the invitation. When <tt>invite_for</tt> is <tt>0</tt> (the default), the invitation won't expire.
         | 
| 113 108 |  | 
| 114 109 | 
             
            You can set this configuration option in the Devise initializer as follow:
         | 
| 115 110 |  | 
| 116 111 | 
             
              # ==> Configuration for :invitable
         | 
| 117 | 
            -
              # The period the generated invitation token is valid | 
| 118 | 
            -
              # this period, the invited resource won't be able to accept the invitation.
         | 
| 112 | 
            +
              # The period the generated invitation token is valid.
         | 
| 113 | 
            +
              # After this period, the invited resource won't be able to accept the invitation.
         | 
| 119 114 | 
             
              # When invite_for is 0 (the default), the invitation won't expire.
         | 
| 120 115 | 
             
              # config.invite_for = 2.weeks
         | 
| 121 116 |  | 
| @@ -186,23 +181,21 @@ To change behaviour of inviting or accepting users, you can simply override two | |
| 186 181 | 
             
              class Users::InvitationsController < Devise::InvitationsController
         | 
| 187 182 | 
             
                private
         | 
| 188 183 |  | 
| 189 | 
            -
             | 
| 190 | 
            -
             | 
| 191 | 
            -
             | 
| 192 | 
            -
             | 
| 193 | 
            -
             | 
| 194 | 
            -
                    u.skip_invitation = true
         | 
| 184 | 
            +
                  # this is called when creating invitation
         | 
| 185 | 
            +
                  # should return an instance of resource class
         | 
| 186 | 
            +
                  def invite_resource
         | 
| 187 | 
            +
                    # skip sending emails on invite
         | 
| 188 | 
            +
                    super { |user| user.skip_invitation = true }
         | 
| 195 189 | 
             
                  end
         | 
| 196 | 
            -
                end
         | 
| 197 190 |  | 
| 198 | 
            -
             | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
             | 
| 203 | 
            -
             | 
| 204 | 
            -
             | 
| 205 | 
            -
             | 
| 191 | 
            +
                  # this is called when accepting invitation
         | 
| 192 | 
            +
                  # should return an instance of resource class
         | 
| 193 | 
            +
                  def accept_resource
         | 
| 194 | 
            +
                    resource = resource_class.accept_invitation!(update_resource_params)
         | 
| 195 | 
            +
                    # Report accepting invitation to analytics
         | 
| 196 | 
            +
                    Analytics.report('invite.accept', resource.id)
         | 
| 197 | 
            +
                    resource
         | 
| 198 | 
            +
                  end
         | 
| 206 199 | 
             
              end
         | 
| 207 200 |  | 
| 208 201 | 
             
            == Strong Parameters
         | 
| @@ -242,12 +235,12 @@ If you want to create the invitation but not send it, you can set <tt>skip_invit | |
| 242 235 | 
             
              # => the record will be created, but the invitation email will not be sent
         | 
| 243 236 |  | 
| 244 237 | 
             
            When generating the <tt>accept_user_invitation_url</tt> yourself, you must use the <tt>raw_invitation_token</tt>
         | 
| 245 | 
            -
            the value is temporarily available when you invite a user and will be decrypted when  | 
| 238 | 
            +
            the value is temporarily available when you invite a user and will be decrypted when received.
         | 
| 246 239 |  | 
| 247 240 | 
             
              accept_user_invitation_url(invitation_token: user.raw_invitation_token)
         | 
| 248 241 |  | 
| 249 242 | 
             
            When <tt>skip_invitation</tt> is used, you must also then set the <tt>invitation_sent_at</tt> field when the user is sent their token. Failure to do so will yield "Invalid invitation token" error when the user attempts to accept the invite.
         | 
| 250 | 
            -
            You can set column, or call <tt>deliver_invitation</tt> to  | 
| 243 | 
            +
            You can set the column, or call <tt>deliver_invitation</tt> to send the invitation and set the column:
         | 
| 251 244 |  | 
| 252 245 | 
             
              user.deliver_invitation
         | 
| 253 246 |  | 
| @@ -335,10 +328,11 @@ Default behavior requires authentication of the same resource as the invited one | |
| 335 328 | 
             
            You would have a <tt>User</tt> model which is configured as invitable and an <tt>Admin</tt> model which is not. If you want to allow only admins to send invitations, simply overwrite the <tt>authenticate_inviter!</tt> method as follow:
         | 
| 336 329 |  | 
| 337 330 | 
             
              class ApplicationController < ActionController::Base
         | 
| 338 | 
            -
             | 
| 339 | 
            -
             | 
| 340 | 
            -
                   | 
| 341 | 
            -
             | 
| 331 | 
            +
                protected
         | 
| 332 | 
            +
             | 
| 333 | 
            +
                  def authenticate_inviter!
         | 
| 334 | 
            +
                    authenticate_admin!(force: true)
         | 
| 335 | 
            +
                  end
         | 
| 342 336 | 
             
              end
         | 
| 343 337 |  | 
| 344 338 | 
             
            And include <tt>DeviseInvitable::Inviter</tt> module into <tt>Admin</tt> model:
         | 
| @@ -51,7 +51,7 @@ class Devise::InvitationsController < DeviseController | |
| 51 51 | 
             
                yield resource if block_given?
         | 
| 52 52 |  | 
| 53 53 | 
             
                if invitation_accepted
         | 
| 54 | 
            -
                  if  | 
| 54 | 
            +
                  if resource.class.allow_insecure_sign_in_after_accept
         | 
| 55 55 | 
             
                    flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
         | 
| 56 56 | 
             
                    set_flash_message :notice, flash_message if is_flashing_format?
         | 
| 57 57 | 
             
                    sign_in(resource_name, resource)
         | 
| @@ -75,42 +75,42 @@ class Devise::InvitationsController < DeviseController | |
| 75 75 |  | 
| 76 76 | 
             
              protected
         | 
| 77 77 |  | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 78 | 
            +
                def invite_resource(&block)
         | 
| 79 | 
            +
                  resource_class.invite!(invite_params, current_inviter, &block)
         | 
| 80 | 
            +
                end
         | 
| 81 81 |  | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 82 | 
            +
                def accept_resource
         | 
| 83 | 
            +
                  resource_class.accept_invitation!(update_resource_params)
         | 
| 84 | 
            +
                end
         | 
| 85 85 |  | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 86 | 
            +
                def current_inviter
         | 
| 87 | 
            +
                  authenticate_inviter!
         | 
| 88 | 
            +
                end
         | 
| 89 89 |  | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 90 | 
            +
                def has_invitations_left?
         | 
| 91 | 
            +
                  unless current_inviter.nil? || current_inviter.has_invitations_left?
         | 
| 92 | 
            +
                    self.resource = resource_class.new
         | 
| 93 | 
            +
                    set_flash_message :alert, :no_invitations_remaining if is_flashing_format?
         | 
| 94 | 
            +
                    respond_with_navigational(resource) { render :new }
         | 
| 95 | 
            +
                  end
         | 
| 95 96 | 
             
                end
         | 
| 96 | 
            -
              end
         | 
| 97 97 |  | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 98 | 
            +
                def resource_from_invitation_token
         | 
| 99 | 
            +
                  unless params[:invitation_token] && self.resource = resource_class.find_by_invitation_token(params[:invitation_token], true)
         | 
| 100 | 
            +
                    set_flash_message(:alert, :invitation_token_invalid) if is_flashing_format?
         | 
| 101 | 
            +
                    redirect_to after_sign_out_path_for(resource_name)
         | 
| 102 | 
            +
                  end
         | 
| 102 103 | 
             
                end
         | 
| 103 | 
            -
              end
         | 
| 104 104 |  | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 105 | 
            +
                def invite_params
         | 
| 106 | 
            +
                  devise_parameter_sanitizer.sanitize(:invite)
         | 
| 107 | 
            +
                end
         | 
| 108 108 |  | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 109 | 
            +
                def update_resource_params
         | 
| 110 | 
            +
                  devise_parameter_sanitizer.sanitize(:accept_invitation)
         | 
| 111 | 
            +
                end
         | 
| 112 112 |  | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 113 | 
            +
                def translation_scope
         | 
| 114 | 
            +
                  'devise.invitations'
         | 
| 115 | 
            +
                end
         | 
| 116 116 | 
             
            end
         | 
| @@ -1,17 +1,17 @@ | |
| 1 1 | 
             
            class DeviseInvitable::RegistrationsController < Devise::RegistrationsController
         | 
| 2 2 | 
             
              protected
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 4 | 
            +
                def build_resource(hash = {})
         | 
| 5 | 
            +
                  if hash[:email]
         | 
| 6 | 
            +
                    self.resource = resource_class.where(email: hash[:email]).first
         | 
| 7 | 
            +
                    if self.resource && self.resource.respond_to?(:invited_to_sign_up?) && self.resource.invited_to_sign_up?
         | 
| 8 | 
            +
                      self.resource.attributes = hash
         | 
| 9 | 
            +
                      self.resource.send_confirmation_instructions if self.resource.confirmation_required_for_invited?
         | 
| 10 | 
            +
                      self.resource.accept_invitation
         | 
| 11 | 
            +
                    else
         | 
| 12 | 
            +
                      self.resource = nil
         | 
| 13 | 
            +
                    end
         | 
| 13 14 | 
             
                  end
         | 
| 15 | 
            +
                  self.resource ||= super
         | 
| 14 16 | 
             
                end
         | 
| 15 | 
            -
                self.resource ||= super
         | 
| 16 | 
            -
              end
         | 
| 17 17 | 
             
            end
         | 
| @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            <p><%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %></p>
         | 
| 4 4 |  | 
| 5 | 
            -
            <p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, : | 
| 5 | 
            +
            <p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) %></p>
         | 
| 6 6 |  | 
| 7 7 | 
             
            <% if @resource.invitation_due_at %>
         | 
| 8 8 | 
             
              <p><%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %></p>
         | 
| @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            <%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %>
         | 
| 4 4 |  | 
| 5 | 
            -
            <%= accept_invitation_url(@resource, : | 
| 5 | 
            +
            <%= accept_invitation_url(@resource, invitation_token: @token) %>
         | 
| 6 6 |  | 
| 7 7 | 
             
            <% if @resource.invitation_due_at %>
         | 
| 8 8 | 
             
              <%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %>
         | 
    
        data/lib/devise_invitable.rb
    CHANGED
    
    | @@ -22,7 +22,8 @@ module Devise | |
| 22 22 | 
             
              mattr_accessor :invite_for
         | 
| 23 23 | 
             
              @@invite_for = 0
         | 
| 24 24 |  | 
| 25 | 
            -
              # Public:  | 
| 25 | 
            +
              # Public: Ensure that invited record is valid.
         | 
| 26 | 
            +
              # The invitation won't be sent if this check fails.
         | 
| 26 27 | 
             
              # (default: false).
         | 
| 27 28 | 
             
              #
         | 
| 28 29 | 
             
              # Examples (in config/initializers/devise.rb)
         | 
| @@ -14,9 +14,8 @@ module DeviseInvitable::Controllers::Helpers | |
| 14 14 |  | 
| 15 15 | 
             
              protected
         | 
| 16 16 |  | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 17 | 
            +
                def authenticate_inviter!
         | 
| 18 | 
            +
                  send(:"authenticate_#{resource_name}!", force: true)
         | 
| 19 | 
            +
                end
         | 
| 21 20 | 
             
            end
         | 
| 22 21 |  | 
| @@ -25,6 +25,7 @@ module DeviseInvitable | |
| 25 25 | 
             
                end
         | 
| 26 26 |  | 
| 27 27 | 
             
                protected
         | 
| 28 | 
            +
             | 
| 28 29 | 
             
                  def decrement_invitation_limit!
         | 
| 29 30 | 
             
                    if self.class.invitation_limit.present?
         | 
| 30 31 | 
             
                      self.invitation_limit ||= self.class.invitation_limit
         | 
| @@ -32,8 +33,8 @@ module DeviseInvitable | |
| 32 33 | 
             
                    end
         | 
| 33 34 | 
             
                  end
         | 
| 34 35 |  | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 36 | 
            +
                  module ClassMethods
         | 
| 37 | 
            +
                    Devise::Models.config(self, :invitation_limit)
         | 
| 38 | 
            +
                  end
         | 
| 38 39 | 
             
              end
         | 
| 39 40 | 
             
            end
         | 
| @@ -1,10 +1,11 @@ | |
| 1 1 | 
             
            module DeviseInvitable
         | 
| 2 2 | 
             
              module Mapping
         | 
| 3 3 | 
             
                private
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                  options | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 4 | 
            +
             | 
| 5 | 
            +
                  def default_controllers(options)
         | 
| 6 | 
            +
                    options[:controllers] ||= {}
         | 
| 7 | 
            +
                    options[:controllers][:registrations] ||= 'devise_invitable/registrations'
         | 
| 8 | 
            +
                    super
         | 
| 9 | 
            +
                  end
         | 
| 9 10 | 
             
              end
         | 
| 10 11 | 
             
            end
         | 
| @@ -10,8 +10,8 @@ module Devise | |
| 10 10 | 
             
                #
         | 
| 11 11 | 
             
                # Configuration:
         | 
| 12 12 | 
             
                #
         | 
| 13 | 
            -
                #   invite_for: The period the generated invitation token is valid | 
| 14 | 
            -
                #               this period, the invited resource won't be able to accept the invitation.
         | 
| 13 | 
            +
                #   invite_for: The period the generated invitation token is valid.
         | 
| 14 | 
            +
                #               After this period, the invited resource won't be able to accept the invitation.
         | 
| 15 15 | 
             
                #               When invite_for is 0 (the default), the invitation won't expire.
         | 
| 16 16 | 
             
                #
         | 
| 17 17 | 
             
                # Examples:
         | 
| @@ -391,15 +391,14 @@ module Devise | |
| 391 391 |  | 
| 392 392 | 
             
                    private
         | 
| 393 393 |  | 
| 394 | 
            -
             | 
| 395 | 
            -
             | 
| 396 | 
            -
             | 
| 397 | 
            -
             | 
| 398 | 
            -
             | 
| 399 | 
            -
             | 
| 400 | 
            -
             | 
| 401 | 
            -
             | 
| 402 | 
            -
             | 
| 394 | 
            +
                      # The random password, as set after an invitation, must conform
         | 
| 395 | 
            +
                      # to any password format validation rules of the application.
         | 
| 396 | 
            +
                      # This default fixes the most common scenarios: Passwords must contain
         | 
| 397 | 
            +
                      # lower + upper case, a digit and a symbol.
         | 
| 398 | 
            +
                      # For more unusual rules, this method can be overridden.
         | 
| 399 | 
            +
                      def random_password
         | 
| 400 | 
            +
                        'aA1!' + Devise.friendly_token[0, 20]
         | 
| 401 | 
            +
                      end
         | 
| 403 402 | 
             
                  end
         | 
| 404 403 | 
             
                end
         | 
| 405 404 | 
             
              end
         | 
| @@ -12,27 +12,27 @@ module DeviseInvitable | |
| 12 12 |  | 
| 13 13 | 
             
                private
         | 
| 14 14 |  | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 15 | 
            +
                  if defined?(Devise::BaseSanitizer)
         | 
| 16 | 
            +
                    def permit(keys)
         | 
| 17 | 
            +
                      default_params.permit(*Array(keys))
         | 
| 18 | 
            +
                    end
         | 
| 19 19 |  | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 20 | 
            +
                    def attributes_for(kind)
         | 
| 21 | 
            +
                      case kind
         | 
| 22 | 
            +
                      when :invite
         | 
| 23 | 
            +
                        resource_class.respond_to?(:invite_key_fields) ? resource_class.invite_key_fields : []
         | 
| 24 | 
            +
                      when :accept_invitation
         | 
| 25 | 
            +
                        [:password, :password_confirmation, :invitation_token]
         | 
| 26 | 
            +
                      else
         | 
| 27 | 
            +
                        super
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
                  else
         | 
| 31 | 
            +
                    def initialize(resource_class, resource_name, params)
         | 
| 27 32 | 
             
                      super
         | 
| 33 | 
            +
                      permit(:invite, keys: (resource_class.respond_to?(:invite_key_fields) ? resource_class.invite_key_fields : []) )
         | 
| 34 | 
            +
                      permit(:accept_invitation, keys: [:password, :password_confirmation, :invitation_token] )
         | 
| 28 35 | 
             
                    end
         | 
| 29 36 | 
             
                  end
         | 
| 30 | 
            -
                else
         | 
| 31 | 
            -
                  def initialize(resource_class, resource_name, params)
         | 
| 32 | 
            -
                    super
         | 
| 33 | 
            -
                    permit(:invite, keys: (resource_class.respond_to?(:invite_key_fields) ? resource_class.invite_key_fields : []) )
         | 
| 34 | 
            -
                    permit(:accept_invitation, keys: [:password, :password_confirmation, :invitation_token] )
         | 
| 35 | 
            -
                  end
         | 
| 36 | 
            -
                end
         | 
| 37 37 | 
             
              end
         | 
| 38 38 | 
             
            end
         | 
| @@ -2,6 +2,7 @@ module ActionDispatch::Routing | |
| 2 2 | 
             
              class Mapper
         | 
| 3 3 |  | 
| 4 4 | 
             
              protected
         | 
| 5 | 
            +
             | 
| 5 6 | 
             
                def devise_invitation(mapping, controllers)
         | 
| 6 7 | 
             
                  resource :invitation, only: [:new, :create, :update],
         | 
| 7 8 | 
             
                    path: mapping.path_names[:invitation], controller: controllers[:invitations] do
         | 
| @@ -9,6 +10,5 @@ module ActionDispatch::Routing | |
| 9 10 | 
             
                    get :destroy, path: mapping.path_names[:remove], as: :remove
         | 
| 10 11 | 
             
                  end
         | 
| 11 12 | 
             
                end
         | 
| 12 | 
            -
             | 
| 13 13 | 
             
              end
         | 
| 14 14 | 
             
            end
         | 
| @@ -15,8 +15,8 @@ module DeviseInvitable | |
| 15 15 | 
             
                        inject_into_file(devise_initializer_path, before: "  # ==> Configuration for :confirmable\n") do
         | 
| 16 16 | 
             
            <<-CONTENT
         | 
| 17 17 | 
             
              # ==> Configuration for :invitable
         | 
| 18 | 
            -
              # The period the generated invitation token is valid | 
| 19 | 
            -
              # this period, the invited resource won't be able to accept the invitation.
         | 
| 18 | 
            +
              # The period the generated invitation token is valid.
         | 
| 19 | 
            +
              # After this period, the invited resource won't be able to accept the invitation.
         | 
| 20 20 | 
             
              # When invite_for is 0 (the default), the invitation won't expire.
         | 
| 21 21 | 
             
              # config.invite_for = 2.weeks
         | 
| 22 22 |  | 
| @@ -35,7 +35,8 @@ module DeviseInvitable | |
| 35 35 | 
             
              # config.invite_key = { email: /\\A[^@]+@[^@]+\\z/ }
         | 
| 36 36 | 
             
              # config.invite_key = { email: /\\A[^@]+@[^@]+\\z/, username: nil }
         | 
| 37 37 |  | 
| 38 | 
            -
              #  | 
| 38 | 
            +
              # Ensure that invited record is valid.
         | 
| 39 | 
            +
              # The invitation won't be sent if this check fails.
         | 
| 39 40 | 
             
              # Default: false
         | 
| 40 41 | 
             
              # config.validate_on_invite = true
         | 
| 41 42 |  | 
| @@ -28,13 +28,14 @@ class ViewsGeneratorTest < ::Rails::Generators::TestCase | |
| 28 28 | 
             
              end
         | 
| 29 29 |  | 
| 30 30 | 
             
              private
         | 
| 31 | 
            -
              def assert_files
         | 
| 32 | 
            -
                assert views = { @invitations_path => %w/edit.html.erb new.html.erb/, @mailer_path => %w/invitation_instructions.html.erb/ }
         | 
| 33 31 |  | 
| 34 | 
            -
                 | 
| 35 | 
            -
                   | 
| 36 | 
            -
             | 
| 32 | 
            +
                def assert_files
         | 
| 33 | 
            +
                  assert views = { @invitations_path => %w/edit.html.erb new.html.erb/, @mailer_path => %w/invitation_instructions.html.erb/ }
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  views.each do |path, files|
         | 
| 36 | 
            +
                    files.each do |file|
         | 
| 37 | 
            +
                      assert_file File.join path, file
         | 
| 38 | 
            +
                    end
         | 
| 37 39 | 
             
                  end
         | 
| 38 40 | 
             
                end
         | 
| 39 | 
            -
              end
         | 
| 40 41 | 
             
            end
         | 
| @@ -29,7 +29,6 @@ class ActionDispatch::IntegrationTest | |
| 29 29 |  | 
| 30 30 | 
             
              # Fix assert_redirect_to in integration sessions because they don't take into
         | 
| 31 31 | 
             
              # account Middleware redirects.
         | 
| 32 | 
            -
              #
         | 
| 33 32 | 
             
              def assert_redirected_to(url)
         | 
| 34 33 | 
             
                assert [301, 302].include?(@integration_session.status),
         | 
| 35 34 | 
             
                       "Expected status to be 301 or 302, got #{@integration_session.status}"
         | 
| @@ -3,15 +3,16 @@ class ApplicationController < ActionController::Base | |
| 3 3 | 
             
              before_action :configure_permitted_parameters, if: :devise_controller?
         | 
| 4 4 |  | 
| 5 5 | 
             
              protected
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                 | 
| 8 | 
            -
                   | 
| 9 | 
            -
             | 
| 10 | 
            -
                   | 
| 6 | 
            +
             | 
| 7 | 
            +
                def after_sign_in_path_for(resource)
         | 
| 8 | 
            +
                  if resource.is_a? Admin
         | 
| 9 | 
            +
                    edit_admin_registration_path(resource)
         | 
| 10 | 
            +
                  else
         | 
| 11 | 
            +
                    super
         | 
| 12 | 
            +
                  end
         | 
| 11 13 | 
             
                end
         | 
| 12 | 
            -
              end
         | 
| 13 14 |  | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 15 | 
            +
                def configure_permitted_parameters
         | 
| 16 | 
            +
                  devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :password, :bio])
         | 
| 17 | 
            +
                end
         | 
| 17 18 | 
             
            end
         | 
| @@ -1,12 +1,15 @@ | |
| 1 1 | 
             
            class FreeInvitationsController < Devise::InvitationsController
         | 
| 2 2 | 
             
              protected
         | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                 | 
| 11 | 
            -
             | 
| 3 | 
            +
             | 
| 4 | 
            +
                def authenticate_inviter!
         | 
| 5 | 
            +
                # everyone can invite
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def current_inviter
         | 
| 9 | 
            +
                  current_admin || current_user
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def after_invite_path_for(resource)
         | 
| 13 | 
            +
                  resource ? super : root_path
         | 
| 14 | 
            +
                end
         | 
| 12 15 | 
             
            end
         | 
| @@ -91,8 +91,8 @@ Devise.setup do |config| | |
| 91 91 | 
             
              # config.pepper = "e31589192aeea8807cb7d8686b0f8484d6cbfaaa65443d45144519ed1d4ffbc6ccb73b21a69ece276d94f2cac95d83990d824f36f301d6f585ededd1bf90d67d"
         | 
| 92 92 |  | 
| 93 93 | 
             
              # ==> Configuration for :invitable
         | 
| 94 | 
            -
              # The period the generated invitation token is valid | 
| 95 | 
            -
              # this period, the invited resource won't be able to accept the invitation.
         | 
| 94 | 
            +
              # The period the generated invitation token is valid.
         | 
| 95 | 
            +
              # After this period, the invited resource won't be able to accept the invitation.
         | 
| 96 96 | 
             
              # When invite_for is 0 (the default), the invitation won't expire.
         | 
| 97 97 | 
             
              # config.invite_for = 2.weeks
         | 
| 98 98 |  | 
| @@ -111,7 +111,8 @@ Devise.setup do |config| | |
| 111 111 | 
             
              # config.invite_key = {:email => /\\A[^@]+@[^@]+\\z/}
         | 
| 112 112 | 
             
              # config.invite_key = {:email => /\\A[^@]+@[^@]+\\z/, :username => nil}
         | 
| 113 113 |  | 
| 114 | 
            -
              #  | 
| 114 | 
            +
              # Ensure that invited record is valid.
         | 
| 115 | 
            +
              # The invitation won't be sent if this check fails.
         | 
| 115 116 | 
             
              # Default: false
         | 
| 116 117 | 
             
              # config.validate_on_invite = true
         | 
| 117 118 |  | 
    
        data/test/test_helper.rb
    CHANGED
    
    | @@ -11,7 +11,7 @@ require 'mocha/setup' | |
| 11 11 |  | 
| 12 12 | 
             
            ActionMailer::Base.delivery_method = :test
         | 
| 13 13 | 
             
            ActionMailer::Base.perform_deliveries = true
         | 
| 14 | 
            -
            ActionMailer::Base.default_url_options[:host] = ' | 
| 14 | 
            +
            ActionMailer::Base.default_url_options[:host] = 'example.com'
         | 
| 15 15 |  | 
| 16 16 | 
             
            ActiveSupport::Deprecation.silenced = true
         | 
| 17 17 | 
             
            $VERBOSE = false
         | 
| @@ -19,28 +19,15 @@ $VERBOSE = false | |
| 19 19 | 
             
            class ActionDispatch::IntegrationTest
         | 
| 20 20 | 
             
              include Capybara::DSL
         | 
| 21 21 | 
             
            end
         | 
| 22 | 
            +
             | 
| 22 23 | 
             
            class ActionController::TestCase
         | 
| 23 24 | 
             
              if defined? Devise::Test
         | 
| 24 25 | 
             
                include Devise::Test::ControllerHelpers
         | 
| 25 26 | 
             
              else
         | 
| 26 27 | 
             
                include Devise::TestHelpers
         | 
| 27 28 | 
             
              end
         | 
| 29 | 
            +
             | 
| 28 30 | 
             
              if defined? ActiveRecord
         | 
| 29 | 
            -
                 | 
| 30 | 
            -
                  self.use_transactional_tests = true
         | 
| 31 | 
            -
                else
         | 
| 32 | 
            -
                  begin
         | 
| 33 | 
            -
                    require 'test_after_commit' 
         | 
| 34 | 
            -
                    self.use_transactional_fixtures = true
         | 
| 35 | 
            -
                  rescue LoadError
         | 
| 36 | 
            -
                  end
         | 
| 37 | 
            -
                end
         | 
| 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
         | 
| 31 | 
            +
                self.use_transactional_tests = true
         | 
| 45 32 | 
             
              end
         | 
| 46 33 | 
             
            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: 2.0. | 
| 4 | 
            +
              version: 2.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sergio Cambra
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-04-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: actionmailer
         |