devise_invitable 1.3.4 → 1.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.rdoc +20 -2
- data/app/controllers/devise/invitations_controller.rb +24 -18
- data/app/views/devise/mailer/invitation_instructions.html.erb +4 -5
- data/config/locales/en.yml +11 -5
- data/lib/devise_invitable/model.rb +18 -16
- data/lib/devise_invitable/rails.rb +6 -4
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/active_record/devise_invitable_generator.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +4 -0
- data/lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb +1 -1
- data/lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb +1 -1
- data/test/functional/controller_helpers_test.rb +3 -3
- data/test/functional/registrations_controller_test.rb +6 -6
- data/test/generators_test.rb +6 -6
- data/test/integration/invitation_remove_test.rb +1 -1
- data/test/integration/invitation_test.rb +15 -5
- data/test/integration_tests_helper.rb +3 -3
- data/test/models/invitable_test.rb +59 -22
- data/test/rails_app/app/controllers/application_controller.rb +7 -0
- data/test/rails_app/app/controllers/free_invitations_controller.rb +6 -0
- data/test/rails_app/app/views/devise/sessions/new.html.erb +17 -0
- metadata +8 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3baf83979bda300001727d86af188f93a91bf95c
|
|
4
|
+
data.tar.gz: 74d6ac1f55c041e7075e4c1e8ec026e470fdfe12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b08b0b990d88fd99aed53e4d3082db8354bda2e5046fad13901debde5ecb614ba5cdcea7e11709798ea16d4dc99dac27dbd622534179cf1d9a3cbaaaba38bda
|
|
7
|
+
data.tar.gz: 3ca119718132addd0b7b331ac4fe81c4e21852b6480ef10c3ed742492b82e86e6fbd01f84957e5a7b6426aba2bbd5eaeb8f65460730399f3e286e125355ca77f
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
= 1.4.0
|
|
2
|
+
Override active_for_authentication? and inactive_message instead of valid_password?
|
|
3
|
+
To use counter_cache, invited_by_counter_cache must be set, no more checking of invitations_count to enable counter cache
|
|
4
|
+
|
|
1
5
|
= 1.3.0
|
|
2
6
|
Now devise 3.1 compatible, @token must be used instead of @resource.invitation_token in mail views
|
|
3
7
|
|
data/README.rdoc
CHANGED
|
@@ -16,7 +16,7 @@ Install DeviseInvitable gem, it will also install dependencies (such as devise a
|
|
|
16
16
|
Add DeviseInvitable to your Gemfile (and Devise if you weren't using them):
|
|
17
17
|
|
|
18
18
|
gem 'devise', '>= 2.0.0'
|
|
19
|
-
gem 'devise_invitable', '~> 1.
|
|
19
|
+
gem 'devise_invitable', '~> 1.3.4'
|
|
20
20
|
|
|
21
21
|
=== Automatic installation
|
|
22
22
|
|
|
@@ -233,11 +233,16 @@ To send an invitation to a user, use the <tt>invite!</tt> class method. <tt>:ema
|
|
|
233
233
|
|
|
234
234
|
If you want to create the invitation but not send it, you can set <tt>skip_invitation</tt> to true.
|
|
235
235
|
|
|
236
|
-
User.invite!(:email => "new_user@example.com", :name => "John Doe") do |u|
|
|
236
|
+
user = User.invite!(:email => "new_user@example.com", :name => "John Doe") do |u|
|
|
237
237
|
u.skip_invitation = true
|
|
238
238
|
end
|
|
239
239
|
# => the record will be created, but the invitation email will not be sent
|
|
240
240
|
|
|
241
|
+
When generating the <tt>accept_user_invitation_url</tt> yourself, you must use the <tt>raw_invitation_token</tt>
|
|
242
|
+
the value is temporarily available when you invite a user and will be decrypted when recieved.
|
|
243
|
+
|
|
244
|
+
accept_user_invitation_url(:invitation_token => user.raw_invitation_token)
|
|
245
|
+
|
|
241
246
|
When skip_invitation is used, you must also then set the invitation_sent_at field when the user is sent their
|
|
242
247
|
token. Failure to do so will yield "Invalid invitation token" errors when the user attempts to accept the invite.
|
|
243
248
|
You can set it like so:
|
|
@@ -252,6 +257,11 @@ You can add :skip_invitation to attributes hash if skip_invitation is added to a
|
|
|
252
257
|
Skip_invitation skips sending the email, but sets invitation_token, so invited_to_sign_up? on the
|
|
253
258
|
resulting user returns true.
|
|
254
259
|
|
|
260
|
+
**Warning**
|
|
261
|
+
|
|
262
|
+
When using skip_invitation you must send the email with the user object instance that generated the tokens, as
|
|
263
|
+
user.raw_invitation_token is available only to the instance and is not persisted in the database.
|
|
264
|
+
|
|
255
265
|
You can send an invitation to an existing user if your workflow creates them separately:
|
|
256
266
|
|
|
257
267
|
user = User.find(42)
|
|
@@ -261,6 +271,8 @@ You can also set <tt>invited_by</tt> when using the <tt>invite!</tt> class metho
|
|
|
261
271
|
|
|
262
272
|
User.invite!({:email => "new_user@example.com"}, current_user) # current_user will be set as invited_by
|
|
263
273
|
|
|
274
|
+
|
|
275
|
+
|
|
264
276
|
=== Accept an invitation
|
|
265
277
|
|
|
266
278
|
To accept an invitation with a token use the <tt>accept_invitation!</tt> class method. <tt>:invitation_token</tt> must be present in the parameters hash. You can also include other attributes in the hash.
|
|
@@ -369,6 +381,12 @@ Take a look at the generated locale file (in <tt>config/locales/devise_invitable
|
|
|
369
381
|
|
|
370
382
|
DeviseInvitable supports ActiveRecord and Mongoid, like Devise.
|
|
371
383
|
|
|
384
|
+
== Wiki
|
|
385
|
+
|
|
386
|
+
It's possible to find additional information about DeviseInvitable on the Wiki:
|
|
387
|
+
|
|
388
|
+
https://github.com/scambra/devise_invitable/wiki
|
|
389
|
+
|
|
372
390
|
== Testing
|
|
373
391
|
|
|
374
392
|
To test DeviseInvitable for the ActiveRecord ORM with RVM, Ruby 1.9.2, and Rubygems 1.8.17:
|
|
@@ -15,11 +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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
yield resource if block_given?
|
|
21
|
+
|
|
22
|
+
if resource_invited
|
|
23
|
+
if is_flashing_format? && self.resource.invitation_sent_at
|
|
24
|
+
set_flash_message :notice, :send_instructions, :email => self.resource.email
|
|
25
|
+
end
|
|
26
|
+
respond_with resource, :location => after_invite_path_for(current_inviter)
|
|
23
27
|
else
|
|
24
28
|
respond_with_navigational(resource) { render :new }
|
|
25
29
|
end
|
|
@@ -34,50 +38,52 @@ class Devise::InvitationsController < DeviseController
|
|
|
34
38
|
# PUT /resource/invitation
|
|
35
39
|
def update
|
|
36
40
|
self.resource = accept_resource
|
|
41
|
+
invitation_accepted = resource.errors.empty?
|
|
42
|
+
|
|
43
|
+
yield resource if block_given?
|
|
37
44
|
|
|
38
|
-
if
|
|
39
|
-
|
|
40
|
-
flash_message
|
|
41
|
-
set_flash_message :notice, flash_message
|
|
45
|
+
if invitation_accepted
|
|
46
|
+
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
|
47
|
+
set_flash_message :notice, flash_message if is_flashing_format?
|
|
42
48
|
sign_in(resource_name, resource)
|
|
43
49
|
respond_with resource, :location => after_accept_path_for(resource)
|
|
44
50
|
else
|
|
45
51
|
respond_with_navigational(resource){ render :edit }
|
|
46
52
|
end
|
|
47
53
|
end
|
|
48
|
-
|
|
54
|
+
|
|
49
55
|
# GET /resource/invitation/remove?invitation_token=abcdef
|
|
50
56
|
def destroy
|
|
51
57
|
resource.destroy
|
|
52
|
-
set_flash_message :notice, :invitation_removed
|
|
58
|
+
set_flash_message :notice, :invitation_removed if is_flashing_format?
|
|
53
59
|
redirect_to after_sign_out_path_for(resource_name)
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
protected
|
|
57
63
|
|
|
58
|
-
def invite_resource
|
|
59
|
-
resource_class.invite!(invite_params, current_inviter)
|
|
64
|
+
def invite_resource(&block)
|
|
65
|
+
resource_class.invite!(invite_params, current_inviter, &block)
|
|
60
66
|
end
|
|
61
|
-
|
|
67
|
+
|
|
62
68
|
def accept_resource
|
|
63
69
|
resource_class.accept_invitation!(update_resource_params)
|
|
64
70
|
end
|
|
65
71
|
|
|
66
72
|
def current_inviter
|
|
67
|
-
|
|
73
|
+
authenticate_inviter!
|
|
68
74
|
end
|
|
69
75
|
|
|
70
76
|
def has_invitations_left?
|
|
71
77
|
unless current_inviter.nil? || current_inviter.has_invitations_left?
|
|
72
78
|
self.resource = resource_class.new
|
|
73
|
-
set_flash_message :alert, :no_invitations_remaining
|
|
79
|
+
set_flash_message :alert, :no_invitations_remaining if is_flashing_format?
|
|
74
80
|
respond_with_navigational(resource) { render :new }
|
|
75
81
|
end
|
|
76
82
|
end
|
|
77
|
-
|
|
83
|
+
|
|
78
84
|
def resource_from_invitation_token
|
|
79
85
|
unless params[:invitation_token] && self.resource = resource_class.find_by_invitation_token(params[:invitation_token], true)
|
|
80
|
-
set_flash_message(:alert, :invitation_token_invalid)
|
|
86
|
+
set_flash_message(:alert, :invitation_token_invalid) if is_flashing_format?
|
|
81
87
|
redirect_to after_sign_out_path_for(resource_name)
|
|
82
88
|
end
|
|
83
89
|
end
|
|
@@ -89,6 +95,6 @@ class Devise::InvitationsController < DeviseController
|
|
|
89
95
|
def update_resource_params
|
|
90
96
|
devise_parameter_sanitizer.sanitize(:accept_invitation)
|
|
91
97
|
end
|
|
92
|
-
|
|
98
|
+
|
|
93
99
|
end
|
|
94
100
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
<p
|
|
1
|
+
<p><%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %></p>
|
|
2
2
|
|
|
3
|
-
<p
|
|
3
|
+
<p><%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %></p>
|
|
4
4
|
|
|
5
|
-
<p><%= link_to
|
|
5
|
+
<p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, :invitation_token => @token) %></p>
|
|
6
6
|
|
|
7
|
-
<p
|
|
8
|
-
Your account won't be created until you access the link above and set your password.</p>
|
|
7
|
+
<p><%= t("devise.mailer.invitation_instructions.ignore").html_safe %></p>
|
data/config/locales/en.yml
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
en:
|
|
2
2
|
devise:
|
|
3
|
+
failure:
|
|
4
|
+
invited: "You have a pending invitation, accept it to finish creating your account."
|
|
3
5
|
invitations:
|
|
4
|
-
send_instructions:
|
|
5
|
-
invitation_token_invalid:
|
|
6
|
-
updated:
|
|
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."
|
|
7
9
|
no_invitations_remaining: "No invitations remaining"
|
|
8
|
-
invitation_removed:
|
|
10
|
+
invitation_removed: "Your invitation was removed."
|
|
9
11
|
new:
|
|
10
12
|
header: "Send invitation"
|
|
11
13
|
submit_button: "Send an invitation"
|
|
@@ -14,4 +16,8 @@ en:
|
|
|
14
16
|
submit_button: "Set my password"
|
|
15
17
|
mailer:
|
|
16
18
|
invitation_instructions:
|
|
17
|
-
subject:
|
|
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
|
+
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."
|
|
@@ -34,12 +34,8 @@ module Devise
|
|
|
34
34
|
else
|
|
35
35
|
{:polymorphic => true}
|
|
36
36
|
end
|
|
37
|
-
if defined?(ActiveRecord) && self < ActiveRecord::Base
|
|
37
|
+
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && self < ActiveRecord::Base
|
|
38
38
|
counter_cache = Devise.invited_by_counter_cache
|
|
39
|
-
if !counter_cache && Devise.invited_by_class_name
|
|
40
|
-
klass = Devise.invited_by_class_name.constantize
|
|
41
|
-
counter_cache = klass.table_exists? && klass.columns_hash['invitations_count'].try('name')
|
|
42
|
-
end
|
|
43
39
|
belongs_to_options.merge! :counter_cache => counter_cache if counter_cache
|
|
44
40
|
end
|
|
45
41
|
belongs_to :invited_by, belongs_to_options
|
|
@@ -49,7 +45,7 @@ module Devise
|
|
|
49
45
|
|
|
50
46
|
attr_writer :skip_password
|
|
51
47
|
|
|
52
|
-
scope :
|
|
48
|
+
scope :no_active_invitation, lambda { where(:invitation_token => nil) }
|
|
53
49
|
if defined?(Mongoid) && defined?(Mongoid::Document) && self < Mongoid::Document
|
|
54
50
|
scope :invitation_not_accepted, lambda { where(:invitation_accepted_at => nil, :invitation_token.ne => nil) }
|
|
55
51
|
scope :invitation_accepted, lambda { where(:invitation_accepted_at.ne => nil) }
|
|
@@ -114,9 +110,10 @@ module Devise
|
|
|
114
110
|
def self.confirmation_required?; false; end
|
|
115
111
|
end
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
yield self if block_given?
|
|
114
|
+
generate_invitation_token if self.invitation_token.nil? || (!skip_invitation || @raw_invitation_token.nil?)
|
|
118
115
|
self.invitation_created_at = Time.now.utc
|
|
119
|
-
self.invitation_sent_at = self.invitation_created_at unless
|
|
116
|
+
self.invitation_sent_at = self.invitation_created_at unless skip_invitation
|
|
120
117
|
self.invited_by = invited_by if invited_by
|
|
121
118
|
|
|
122
119
|
# Call these before_validate methods since we aren't validating on save
|
|
@@ -125,7 +122,7 @@ module Devise
|
|
|
125
122
|
|
|
126
123
|
if save(:validate => false)
|
|
127
124
|
self.invited_by.decrement_invitation_limit! if !was_invited and self.invited_by.present?
|
|
128
|
-
deliver_invitation unless
|
|
125
|
+
deliver_invitation unless skip_invitation
|
|
129
126
|
end
|
|
130
127
|
end
|
|
131
128
|
|
|
@@ -137,10 +134,14 @@ module Devise
|
|
|
137
134
|
end
|
|
138
135
|
|
|
139
136
|
# Only verify password when is not invited
|
|
140
|
-
def
|
|
137
|
+
def active_for_authentication?
|
|
141
138
|
super unless invited_to_sign_up?
|
|
142
139
|
end
|
|
143
140
|
|
|
141
|
+
def inactive_message
|
|
142
|
+
invited_to_sign_up? ? :invited : super
|
|
143
|
+
end
|
|
144
|
+
|
|
144
145
|
def after_password_reset
|
|
145
146
|
super
|
|
146
147
|
accept_invitation! if invited_to_sign_up?
|
|
@@ -171,10 +172,13 @@ module Devise
|
|
|
171
172
|
protected
|
|
172
173
|
# Overriding the method in Devise's :validatable module so password is not required on inviting
|
|
173
174
|
def password_required?
|
|
174
|
-
|
|
175
|
+
!skip_password && super
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def skip_password
|
|
179
|
+
@skip_password ||= false
|
|
175
180
|
end
|
|
176
181
|
|
|
177
|
-
|
|
178
182
|
# Checks if the invitation for the user is within the limit time.
|
|
179
183
|
# We do this by calculating if the difference between today and the
|
|
180
184
|
# invitation sent date does not exceed the invite for time configured.
|
|
@@ -253,13 +257,11 @@ module Devise
|
|
|
253
257
|
end
|
|
254
258
|
|
|
255
259
|
def invite!(attributes={}, invited_by=nil, &block)
|
|
256
|
-
|
|
257
|
-
invitable
|
|
260
|
+
_invite(attributes.with_indifferent_access, invited_by, &block).first
|
|
258
261
|
end
|
|
259
262
|
|
|
260
263
|
def invite_mail!(attributes={}, invited_by=nil, &block)
|
|
261
|
-
|
|
262
|
-
mail
|
|
264
|
+
_invite(attributes, invited_by, &block).last
|
|
263
265
|
end
|
|
264
266
|
|
|
265
267
|
# Attempt to find a user by it's invitation_token to set it's password.
|
|
@@ -7,12 +7,14 @@ module DeviseInvitable
|
|
|
7
7
|
|
|
8
8
|
# We use to_prepare instead of after_initialize here because Devise is a Rails engine; its
|
|
9
9
|
# mailer is reloaded like the rest of the user's app. Got to make sure that our mailer methods
|
|
10
|
-
# are included each time Devise
|
|
10
|
+
# are included each time Devise.mailer is (re)loaded.
|
|
11
11
|
config.to_prepare do
|
|
12
|
-
|
|
13
|
-
Devise
|
|
12
|
+
Devise.mailer.send :include, DeviseInvitable::Mailer
|
|
13
|
+
unless Devise.mailer.ancestors.include?(Devise::Mailers::Helpers)
|
|
14
|
+
Devise.mailer.send :include, Devise::Mailers::Helpers
|
|
15
|
+
end
|
|
14
16
|
end
|
|
15
|
-
# extend mapping with after_initialize
|
|
17
|
+
# extend mapping with after_initialize because it's not reloaded
|
|
16
18
|
config.after_initialize do
|
|
17
19
|
Devise::Mapping.send :include, DeviseInvitable::Mapping
|
|
18
20
|
Devise::ParameterSanitizer.send :include, DeviseInvitable::ParameterSanitizer
|
|
@@ -6,7 +6,7 @@ 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}"
|
|
9
|
+
migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}.rb"
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -25,5 +25,9 @@ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
|
25
25
|
t.remove_references :invited_by, :polymorphic => true
|
|
26
26
|
t.remove :invitations_count, :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at
|
|
27
27
|
end
|
|
28
|
+
change_column_null :<%= table_name %>, :encrypted_password, false
|
|
29
|
+
<% if class_name.constantize.columns_hash['password_salt'] -%>
|
|
30
|
+
change_column_null :<%= table_name %>, :password_salt,false
|
|
31
|
+
<% end -%>
|
|
28
32
|
end
|
|
29
33
|
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.
|
|
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.
|
|
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
|
|
@@ -25,7 +25,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
|
|
25
25
|
sign_out @issuer
|
|
26
26
|
|
|
27
27
|
@invitee = User.where(:email => invitee_email).first
|
|
28
|
-
|
|
28
|
+
assert @invitee.encrypted_password.blank?, "the password should be unset"
|
|
29
29
|
|
|
30
30
|
# sign_up the invitee
|
|
31
31
|
assert_difference('ActionMailer::Base.deliveries.size') do
|
|
@@ -42,13 +42,13 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
|
|
42
42
|
@invitee.save!
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
assert @invitee.encrypted_password.present?
|
|
46
46
|
assert_not_nil @invitee.invitation_accepted_at
|
|
47
47
|
assert_nil @invitee.invitation_token
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
assert @invitee.invited_by_id.present?
|
|
49
|
+
assert @invitee.invited_by_type.present?
|
|
50
50
|
assert !@invitee.confirmed?
|
|
51
|
-
|
|
51
|
+
assert @invitee.confirmation_token.present?
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
test "not invitable resources can register" do
|
|
@@ -58,7 +58,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
|
|
58
58
|
post :create, :admin => {:email => invitee_email, :password => "1password"}
|
|
59
59
|
|
|
60
60
|
@invitee = Admin.where(:email => invitee_email).first
|
|
61
|
-
|
|
61
|
+
assert @invitee.encrypted_password.present?
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
test "missing params on a create should not cause an error" do
|
data/test/generators_test.rb
CHANGED
|
@@ -17,18 +17,18 @@ class GeneratorsTest < ActiveSupport::TestCase
|
|
|
17
17
|
|
|
18
18
|
test "rails g devise_invitable:install" do
|
|
19
19
|
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
|
|
20
|
-
assert @output.match(%r{(inject|insert)
|
|
21
|
-
assert @output.match(%r|create
|
|
20
|
+
assert @output.match(%r{(inject|insert).* config/initializers/devise\.rb\n})
|
|
21
|
+
assert @output.match(%r|create.* config/locales/devise_invitable\.en\.yml\n|)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
test "rails g devise_invitable Octopussy" do
|
|
25
25
|
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
|
|
26
|
-
assert @output.match(%r{(inject|insert)
|
|
27
|
-
assert @output.match(%r|invoke
|
|
26
|
+
assert @output.match(%r{(inject|insert).* app/models/octopussy\.rb\n})
|
|
27
|
+
assert @output.match(%r|invoke.* #{DEVISE_ORM}\n|)
|
|
28
28
|
if DEVISE_ORM == :active_record
|
|
29
|
-
assert @output.match(%r|create
|
|
29
|
+
assert @output.match(%r|create.* db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
|
30
30
|
elsif DEVISE_ORM == :mongoid
|
|
31
|
-
assert !@output.match(%r|create
|
|
31
|
+
assert !@output.match(%r|create.* db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
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
|
-
|
|
7
|
+
User.invite!(:email => "valid@email.com")
|
|
8
8
|
|
|
9
9
|
# remove!
|
|
10
10
|
visit remove_user_invitation_path(:invitation_token => Thread.current[:token])
|
|
@@ -80,7 +80,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
|
80
80
|
end
|
|
81
81
|
assert_equal user_invitation_path, current_path
|
|
82
82
|
assert page.has_css?('#error_explanation li', :text => /Password .*doesn\'t match/)
|
|
83
|
-
|
|
83
|
+
assert user.encrypted_password.blank?
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
test 'not authenticated user with valid data should be able to change his password' do
|
|
@@ -99,7 +99,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
|
99
99
|
end
|
|
100
100
|
assert_equal user_invitation_path, current_path
|
|
101
101
|
assert page.has_css?('#error_explanation')
|
|
102
|
-
|
|
102
|
+
assert user.encrypted_password.blank?
|
|
103
103
|
|
|
104
104
|
set_password :visit => false
|
|
105
105
|
assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
class
|
|
1
|
+
class ActionDispatch::IntegrationTest
|
|
2
2
|
|
|
3
3
|
def warden
|
|
4
4
|
request.env['warden']
|
|
5
5
|
end
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
def create_full_user
|
|
8
8
|
@user ||= begin
|
|
9
9
|
user = User.create!(
|
|
@@ -24,7 +24,7 @@ class ActionController::IntegrationTest
|
|
|
24
24
|
visit send("new_#{resource_name}_session_path")
|
|
25
25
|
fill_in "#{resource_name}_email", :with => user.email
|
|
26
26
|
fill_in "#{resource_name}_password", :with => user.password
|
|
27
|
-
click_button '
|
|
27
|
+
click_button 'Log in'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# Fix assert_redirect_to in integration sessions because they don't take into
|
|
@@ -28,14 +28,40 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
28
28
|
test 'should regenerate invitation token each time' do
|
|
29
29
|
user = new_user
|
|
30
30
|
user.invite!
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
assert_not_nil user.invitation_token
|
|
33
|
+
assert_not_nil user.raw_invitation_token
|
|
33
34
|
assert_not_nil user.invitation_created_at
|
|
35
|
+
|
|
34
36
|
3.times do
|
|
35
37
|
user = User.find(user.id)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
assert_not_same user.invitation_token, lambda {
|
|
40
|
+
user.invite!
|
|
41
|
+
user.invitation_token
|
|
42
|
+
}.call
|
|
43
|
+
assert_not_nil user.raw_invitation_token
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test 'should regenerate invitation token each time even if "skip_invitation" was true' do
|
|
48
|
+
user = new_user
|
|
49
|
+
user.skip_invitation = true
|
|
50
|
+
user.invite!
|
|
51
|
+
|
|
52
|
+
assert_not_nil user.invitation_token
|
|
53
|
+
assert_not_nil user.invitation_created_at
|
|
54
|
+
|
|
55
|
+
3.times do
|
|
56
|
+
user = User.find(user.id)
|
|
57
|
+
user.skip_invitation = true
|
|
58
|
+
|
|
59
|
+
assert_not_same user.invitation_token, lambda {
|
|
60
|
+
user.invite!
|
|
61
|
+
user.invitation_token
|
|
62
|
+
}.call
|
|
63
|
+
assert_not_nil user.invitation_token
|
|
64
|
+
assert_not_nil user.raw_invitation_token
|
|
39
65
|
end
|
|
40
66
|
end
|
|
41
67
|
|
|
@@ -143,7 +169,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
143
169
|
end
|
|
144
170
|
|
|
145
171
|
test 'should set password and password confirmation from params' do
|
|
146
|
-
|
|
172
|
+
User.invite!(:email => "valid@email.com")
|
|
147
173
|
user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
|
|
148
174
|
assert user.valid_password?('123456789')
|
|
149
175
|
end
|
|
@@ -157,21 +183,21 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
157
183
|
|
|
158
184
|
test 'should clear invitation token and set invitation_accepted_at while accepting the password' do
|
|
159
185
|
user = User.invite!(:email => "valid@email.com")
|
|
160
|
-
|
|
186
|
+
assert user.invitation_token.present?
|
|
161
187
|
assert_nil user.invitation_accepted_at
|
|
162
188
|
user.accept_invitation!
|
|
163
189
|
user.reload
|
|
164
190
|
assert_nil user.invitation_token
|
|
165
|
-
|
|
191
|
+
assert user.invitation_accepted_at.present?
|
|
166
192
|
end
|
|
167
193
|
|
|
168
194
|
test 'should not clear invitation token or set accepted_at if record is invalid' do
|
|
169
195
|
user = User.invite!(:email => "valid@email.com")
|
|
170
|
-
|
|
196
|
+
assert user.invitation_token.present?
|
|
171
197
|
assert_nil user.invitation_accepted_at
|
|
172
198
|
User.accept_invitation!(:invitation_token => user.invitation_token, :password => '123456789', :password_confirmation => '987654321')
|
|
173
199
|
user.reload
|
|
174
|
-
|
|
200
|
+
assert user.invitation_token.present?
|
|
175
201
|
assert_nil user.invitation_accepted_at
|
|
176
202
|
end
|
|
177
203
|
|
|
@@ -182,8 +208,8 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
182
208
|
user.reset_password_sent_at = Time.now.utc
|
|
183
209
|
user.save
|
|
184
210
|
|
|
185
|
-
|
|
186
|
-
|
|
211
|
+
assert user.reset_password_token.present?
|
|
212
|
+
assert user.invitation_token.present?
|
|
187
213
|
User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
|
|
188
214
|
assert_nil user.reload.reset_password_token
|
|
189
215
|
assert_nil user.reload.invitation_token
|
|
@@ -197,11 +223,11 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
197
223
|
user.reset_password_sent_at = Time.now.utc
|
|
198
224
|
user.save
|
|
199
225
|
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
assert user.reset_password_token.present?
|
|
227
|
+
assert user.invitation_token.present?
|
|
202
228
|
User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '12345678')
|
|
203
|
-
|
|
204
|
-
|
|
229
|
+
assert user.reload.reset_password_token.present?
|
|
230
|
+
assert user.reload.invitation_token.present?
|
|
205
231
|
assert user.invited_to_sign_up?
|
|
206
232
|
end
|
|
207
233
|
|
|
@@ -212,7 +238,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
212
238
|
user.reset_password_sent_at = Time.now.utc
|
|
213
239
|
user.save
|
|
214
240
|
|
|
215
|
-
|
|
241
|
+
assert user.reset_password_token.present?
|
|
216
242
|
assert_nil user.invitation_token
|
|
217
243
|
User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
|
|
218
244
|
assert_nil user.reload.invitation_token
|
|
@@ -231,7 +257,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
231
257
|
test 'should return a record with invitation token and no errors to send invitation by email' do
|
|
232
258
|
invited_user = User.invite!(:email => "valid@email.com")
|
|
233
259
|
assert invited_user.errors.blank?
|
|
234
|
-
|
|
260
|
+
assert invited_user.invitation_token.present?
|
|
235
261
|
assert_equal 'valid@email.com', invited_user.email
|
|
236
262
|
assert invited_user.persisted?
|
|
237
263
|
end
|
|
@@ -380,7 +406,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
380
406
|
user = new_user(:password => nil, :password_confirmation => nil)
|
|
381
407
|
user.invite!
|
|
382
408
|
|
|
383
|
-
|
|
409
|
+
User.accept_invitation!(
|
|
384
410
|
:invitation_token => Thread.current[:token],
|
|
385
411
|
:password => 'new_password',
|
|
386
412
|
:password_confirmation => 'new_password'
|
|
@@ -454,13 +480,13 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
454
480
|
|
|
455
481
|
test 'should not send an invitation if we want to skip the invitation' do
|
|
456
482
|
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
|
457
|
-
|
|
483
|
+
User.invite!(:email => "valid@email.com", :username => "a"*50, :skip_invitation => true)
|
|
458
484
|
end
|
|
459
485
|
end
|
|
460
486
|
|
|
461
487
|
test 'should not send an invitation if we want to skip the invitation with block' do
|
|
462
488
|
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
|
463
|
-
|
|
489
|
+
User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
|
|
464
490
|
u.skip_invitation = true
|
|
465
491
|
end
|
|
466
492
|
end
|
|
@@ -472,7 +498,18 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
472
498
|
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
|
473
499
|
user.invite!
|
|
474
500
|
end
|
|
475
|
-
|
|
501
|
+
assert user.invitation_created_at.present?
|
|
502
|
+
assert_nil user.invitation_sent_at
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
test 'user.invite! should not send an invitation if we want to skip the invitation with block' do
|
|
506
|
+
user = new_user
|
|
507
|
+
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
|
508
|
+
user.invite! do |u|
|
|
509
|
+
u.skip_invitation = true
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
assert user.invitation_created_at.present?
|
|
476
513
|
assert_nil user.invitation_sent_at
|
|
477
514
|
end
|
|
478
515
|
|
|
@@ -569,7 +606,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
569
606
|
end
|
|
570
607
|
|
|
571
608
|
test 'should return instance with errors if invitation_token is nil' do
|
|
572
|
-
|
|
609
|
+
User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
|
|
573
610
|
user = User.accept_invitation!
|
|
574
611
|
assert !user.errors.empty?
|
|
575
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
|
+
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:
|
|
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.
|
|
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
|