devise_invitable 1.4.0 → 1.4.1

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: 49059f27df2618f9c0491fd1b7578b33619f2ef5
4
- data.tar.gz: da0b1ff3962cba2784b8c082c013fb483ee0517e
3
+ metadata.gz: 3baf83979bda300001727d86af188f93a91bf95c
4
+ data.tar.gz: 74d6ac1f55c041e7075e4c1e8ec026e470fdfe12
5
5
  SHA512:
6
- metadata.gz: 56e5cc31bd011a67887ea3338ee66682dc398008f4a18f094fec9084b0635efc8684d5251aca72a9d7daecf228ea06aeec84bca49a8dd24bd3750c063f7b2e56
7
- data.tar.gz: 162bc6c70f81f0b65ca73233a5ebb5ac53895b5e6c57f4085d522807592feccb29ce93c113e1d67d974fa95ebf026054d137a6a5c01c1af3913bf84df14d2f7a
6
+ metadata.gz: 0b08b0b990d88fd99aed53e4d3082db8354bda2e5046fad13901debde5ecb614ba5cdcea7e11709798ea16d4dc99dac27dbd622534179cf1d9a3cbaaaba38bda
7
+ data.tar.gz: 3ca119718132addd0b7b331ac4fe81c4e21852b6480ef10c3ed742492b82e86e6fbd01f84957e5a7b6426aba2bbd5eaeb8f65460730399f3e286e125355ca77f
@@ -15,13 +15,15 @@ class Devise::InvitationsController < DeviseController
15
15
  # POST /resource/invitation
16
16
  def create
17
17
  self.resource = invite_resource
18
+ resource_invited = resource.errors.empty?
18
19
 
19
- if resource.errors.empty?
20
- yield resource if block_given?
20
+ yield resource if block_given?
21
+
22
+ if resource_invited
21
23
  if is_flashing_format? && self.resource.invitation_sent_at
22
24
  set_flash_message :notice, :send_instructions, :email => self.resource.email
23
25
  end
24
- respond_with resource, :location => after_invite_path_for(resource)
26
+ respond_with resource, :location => after_invite_path_for(current_inviter)
25
27
  else
26
28
  respond_with_navigational(resource) { render :new }
27
29
  end
@@ -36,9 +38,11 @@ class Devise::InvitationsController < DeviseController
36
38
  # PUT /resource/invitation
37
39
  def update
38
40
  self.resource = accept_resource
41
+ invitation_accepted = resource.errors.empty?
42
+
43
+ yield resource if block_given?
39
44
 
40
- if resource.errors.empty?
41
- yield resource if block_given?
45
+ if invitation_accepted
42
46
  flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
43
47
  set_flash_message :notice, flash_message if is_flashing_format?
44
48
  sign_in(resource_name, resource)
@@ -1,13 +1,13 @@
1
1
  en:
2
2
  devise:
3
3
  failure:
4
- invited: 'You have a pending invitation, accept it to finish creating your account.'
4
+ invited: "You have a pending invitation, accept it to finish creating your account."
5
5
  invitations:
6
- send_instructions: 'An invitation email has been sent to %{email}.'
7
- invitation_token_invalid: 'The invitation token provided is not valid!'
8
- updated: 'Your password was set successfully. You are now signed in.'
6
+ send_instructions: "An invitation email has been sent to %{email}."
7
+ invitation_token_invalid: "The invitation token provided is not valid!"
8
+ updated: "Your password was set successfully. You are now signed in."
9
9
  no_invitations_remaining: "No invitations remaining"
10
- invitation_removed: 'Your invitation was removed.'
10
+ invitation_removed: "Your invitation was removed."
11
11
  new:
12
12
  header: "Send invitation"
13
13
  submit_button: "Send an invitation"
@@ -16,8 +16,8 @@ en:
16
16
  submit_button: "Set my password"
17
17
  mailer:
18
18
  invitation_instructions:
19
- subject: 'Invitation instructions'
20
- hello: 'Hello %{email}'
21
- someone_invited_you: 'Someone has invited you to %{url}, you can accept it through the link below.'
22
- accept: 'Accept invitation'
19
+ subject: "Invitation instructions"
20
+ hello: "Hello %{email}"
21
+ someone_invited_you: "Someone has invited you to %{url}, you can accept it through the link below."
22
+ accept: "Accept invitation"
23
23
  ignore: "If you don't want to accept the invitation, please ignore this email.<br />Your account won't be created until you access the link above and set your password."
@@ -111,9 +111,9 @@ module Devise
111
111
  end
112
112
 
113
113
  yield self if block_given?
114
- generate_invitation_token if self.invitation_token.nil? || (!@skip_invitation || @raw_invitation_token.nil?)
114
+ generate_invitation_token if self.invitation_token.nil? || (!skip_invitation || @raw_invitation_token.nil?)
115
115
  self.invitation_created_at = Time.now.utc
116
- self.invitation_sent_at = self.invitation_created_at unless @skip_invitation
116
+ self.invitation_sent_at = self.invitation_created_at unless skip_invitation
117
117
  self.invited_by = invited_by if invited_by
118
118
 
119
119
  # Call these before_validate methods since we aren't validating on save
@@ -122,7 +122,7 @@ module Devise
122
122
 
123
123
  if save(:validate => false)
124
124
  self.invited_by.decrement_invitation_limit! if !was_invited and self.invited_by.present?
125
- deliver_invitation unless @skip_invitation
125
+ deliver_invitation unless skip_invitation
126
126
  end
127
127
  end
128
128
 
@@ -172,9 +172,12 @@ module Devise
172
172
  protected
173
173
  # Overriding the method in Devise's :validatable module so password is not required on inviting
174
174
  def password_required?
175
- !@skip_password && super
175
+ !skip_password && super
176
176
  end
177
177
 
178
+ def skip_password
179
+ @skip_password ||= false
180
+ end
178
181
 
179
182
  # Checks if the invitation for the user is within the limit time.
180
183
  # We do this by calculating if the difference between today and the
@@ -254,13 +257,11 @@ module Devise
254
257
  end
255
258
 
256
259
  def invite!(attributes={}, invited_by=nil, &block)
257
- invitable, mail = _invite(attributes.with_indifferent_access, invited_by, &block)
258
- invitable
260
+ _invite(attributes.with_indifferent_access, invited_by, &block).first
259
261
  end
260
262
 
261
263
  def invite_mail!(attributes={}, invited_by=nil, &block)
262
- invitable, mail = _invite(attributes, invited_by, &block)
263
- mail
264
+ _invite(attributes, invited_by, &block).last
264
265
  end
265
266
 
266
267
  # Attempt to find a user by it's invitation_token to set it's password.
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
@@ -4,11 +4,11 @@ class ControllerHelpersTest < ActionController::TestCase
4
4
  tests ApplicationController
5
5
 
6
6
  test "after invite path defaults to after sign in path" do
7
- assert_equal @controller.after_sign_in_path_for(:user), @controller.after_invite_path_for(:user)
7
+ assert_equal @controller.send(:after_sign_in_path_for, :user), @controller.after_invite_path_for(:user)
8
8
  end
9
9
 
10
10
  test "after accept path defaults to after sign in path" do
11
- assert_equal @controller.after_sign_in_path_for(:user), @controller.after_accept_path_for(:user)
11
+ assert_equal @controller.send(:after_sign_in_path_for, :user), @controller.after_accept_path_for(:user)
12
12
  end
13
13
 
14
14
  test 'after invite path is customizable from application controller' do
@@ -36,4 +36,4 @@ class ControllerHelpersTest < ActionController::TestCase
36
36
  assert Devise::InvitationsController.method_defined? :after_accept_path_for
37
37
  assert !Devise::InvitationsController.instance_methods(false).include?(:after_accept_path_for)
38
38
  end
39
- end
39
+ end
@@ -4,7 +4,7 @@ require 'integration_tests_helper'
4
4
  class InvitationRemoveTest < ActionDispatch::IntegrationTest
5
5
 
6
6
  test 'invited user can choose to remove his account/invite' do
7
- user = User.invite!(:email => "valid@email.com")
7
+ User.invite!(:email => "valid@email.com")
8
8
 
9
9
  # remove!
10
10
  visit remove_user_invitation_path(:invitation_token => Thread.current[:token])
@@ -107,7 +107,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
107
107
  end
108
108
 
109
109
  test 'sign in user automatically after setting it\'s password' do
110
- user = User.invite!(:email => "valid@email.com")
110
+ User.invite!(:email => "valid@email.com")
111
111
  set_password :invitation_token => Thread.current[:token]
112
112
  assert_equal root_path, current_path
113
113
  end
@@ -213,10 +213,20 @@ class InvitationTest < ActionDispatch::IntegrationTest
213
213
  end
214
214
 
215
215
  test 'authenticated admin should be able to send an admin invitation' do
216
- sign_in_as_user Admin.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
216
+ admin = Admin.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
217
+ sign_in_as_user admin
217
218
 
218
219
  send_invitation new_admin_path
219
- assert_equal root_path, current_path
220
+ assert_equal edit_admin_registration_path(admin), current_path
221
+ assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
222
+ end
223
+
224
+ test 'authenticated admin should be redirected to own page after send a free invitation' do
225
+ admin = Admin.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
226
+ sign_in_as_user admin
227
+
228
+ send_invitation new_free_invitation_path
229
+ assert_equal edit_admin_registration_path(admin), current_path
220
230
  assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
221
231
  end
222
232
  end
@@ -169,7 +169,7 @@ class InvitableTest < ActiveSupport::TestCase
169
169
  end
170
170
 
171
171
  test 'should set password and password confirmation from params' do
172
- invited_user = User.invite!(:email => "valid@email.com")
172
+ User.invite!(:email => "valid@email.com")
173
173
  user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
174
174
  assert user.valid_password?('123456789')
175
175
  end
@@ -406,7 +406,7 @@ class InvitableTest < ActiveSupport::TestCase
406
406
  user = new_user(:password => nil, :password_confirmation => nil)
407
407
  user.invite!
408
408
 
409
- invited_user = User.accept_invitation!(
409
+ User.accept_invitation!(
410
410
  :invitation_token => Thread.current[:token],
411
411
  :password => 'new_password',
412
412
  :password_confirmation => 'new_password'
@@ -480,13 +480,13 @@ class InvitableTest < ActiveSupport::TestCase
480
480
 
481
481
  test 'should not send an invitation if we want to skip the invitation' do
482
482
  assert_no_difference('ActionMailer::Base.deliveries.size') do
483
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50, :skip_invitation => true)
483
+ User.invite!(:email => "valid@email.com", :username => "a"*50, :skip_invitation => true)
484
484
  end
485
485
  end
486
486
 
487
487
  test 'should not send an invitation if we want to skip the invitation with block' do
488
488
  assert_no_difference('ActionMailer::Base.deliveries.size') do
489
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
489
+ User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
490
490
  u.skip_invitation = true
491
491
  end
492
492
  end
@@ -606,7 +606,7 @@ class InvitableTest < ActiveSupport::TestCase
606
606
  end
607
607
 
608
608
  test 'should return instance with errors if invitation_token is nil' do
609
- registered_user = User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
609
+ User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
610
610
  user = User.accept_invitation!
611
611
  assert !user.errors.empty?
612
612
  end
@@ -3,6 +3,13 @@ class ApplicationController < ActionController::Base
3
3
  before_filter :configure_permitted_parameters, :if => :devise_controller?
4
4
 
5
5
  protected
6
+ def after_sign_in_path_for(resource)
7
+ if resource.is_a? Admin
8
+ edit_admin_registration_path(resource)
9
+ else
10
+ super
11
+ end
12
+ end
6
13
 
7
14
  def configure_permitted_parameters
8
15
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :bio) } if defined?(ActionController::StrongParameters)
@@ -3,4 +3,10 @@ class FreeInvitationsController < Devise::InvitationsController
3
3
  def authenticate_inviter!
4
4
  # everyone can invite
5
5
  end
6
+ def current_inviter
7
+ current_admin || current_user
8
+ end
9
+ def after_invite_path_for(resource)
10
+ resource ? super : root_path
11
+ end
6
12
  end
@@ -0,0 +1,17 @@
1
+ <h2>Log in</h2>
2
+
3
+ <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
4
+ <div><%= f.label :email %><br />
5
+ <%= f.email_field :email, autofocus: true %></div>
6
+
7
+ <div><%= f.label :password %><br />
8
+ <%= f.password_field :password, autocomplete: "off" %></div>
9
+
10
+ <% if devise_mapping.rememberable? -%>
11
+ <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
12
+ <% end -%>
13
+
14
+ <div><%= f.submit "Log in" %></div>
15
+ <% end %>
16
+
17
+ <%= render "devise/shared/links" %>
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.4.0
4
+ version: 1.4.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: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,9 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - CHANGELOG
70
+ - LICENSE
71
+ - README.rdoc
69
72
  - app/controllers/devise/invitations_controller.rb
70
73
  - app/controllers/devise_invitable/registrations_controller.rb
71
74
  - app/views/devise/invitations/edit.html.erb
@@ -90,9 +93,6 @@ files:
90
93
  - lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb
91
94
  - lib/generators/devise_invitable/views_generator.rb
92
95
  - lib/generators/mongoid/devise_invitable_generator.rb
93
- - LICENSE
94
- - README.rdoc
95
- - CHANGELOG
96
96
  - test/functional/controller_helpers_test.rb
97
97
  - test/functional/registrations_controller_test.rb
98
98
  - test/generators/views_generator_test.rb
@@ -117,6 +117,7 @@ files:
117
117
  - test/rails_app/app/models/octopussy.rb
118
118
  - test/rails_app/app/models/user.rb
119
119
  - test/rails_app/app/views/admins/new.html.erb
120
+ - test/rails_app/app/views/devise/sessions/new.html.erb
120
121
  - test/rails_app/app/views/free_invitations/new.html.erb
121
122
  - test/rails_app/app/views/home/index.html.erb
122
123
  - test/rails_app/app/views/layouts/application.html.erb
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: 1.3.6
168
169
  requirements: []
169
170
  rubyforge_project:
170
- rubygems_version: 2.1.11
171
+ rubygems_version: 2.4.5
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: An invitation strategy for Devise
@@ -196,6 +197,7 @@ test_files:
196
197
  - test/rails_app/app/models/octopussy.rb
197
198
  - test/rails_app/app/models/user.rb
198
199
  - test/rails_app/app/views/admins/new.html.erb
200
+ - test/rails_app/app/views/devise/sessions/new.html.erb
199
201
  - test/rails_app/app/views/free_invitations/new.html.erb
200
202
  - test/rails_app/app/views/home/index.html.erb
201
203
  - test/rails_app/app/views/layouts/application.html.erb