devise_invitable 1.3.0 → 1.3.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 +7 -0
- data/README.rdoc +18 -1
- data/lib/devise_invitable/model.rb +12 -4
- data/lib/devise_invitable/parameter_sanitizer.rb +17 -2
- data/lib/devise_invitable/version.rb +1 -1
- data/test/models/invitable_test.rb +32 -3
- data/test/models_test.rb +4 -0
- data/test/rails_app/app/models/user.rb +3 -1
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -0
- metadata +7 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: f63e9220602bf9934658384637404fdf89b2dfcd4f7b2b7ed77c31cddfbab70e6ca7fa89a2fa2dccf489db7b2e80ff6634cfadf320ee366769b42000da4e9ac5
|
4
|
+
data.tar.gz: d54dfb69ad95bf58f8a69c5c358ba64e9cfdf569536682f6e8614cc2f10550984657cb74353ab64a9fd59e1fed16991b9e8e4e5d120ec3583ad01f36b961bd1c
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: 861482f2cb8845f6335441e94c3da04912511e1b
|
7
|
+
data.tar.gz: 54799f3b072ffc7dcd3080d5f394fa2c62e64990
|
data/README.rdoc
CHANGED
@@ -124,7 +124,7 @@ or directly as parameters to the <tt>devise</tt> method:
|
|
124
124
|
|
125
125
|
* invitation_limit: The number of invitations users can send. The default value of nil means users can send as many invites as they want, there is no limit for any user, invitation_limit column is not used. A setting of 0 means they can't send invitations. A setting n > 0 means they can send n invitations. You can change invitation_limit column for some users so they can send more or less invitations, even with global invitation_limit = 0.
|
126
126
|
|
127
|
-
* invite_key: The key to be used to check existing users when sending an invitation. You can use multiple keys. This value must be a hash with the invite key as hash keys, and
|
127
|
+
* invite_key: The key to be used to check existing users when sending an invitation. You can use multiple keys. This value must be a hash with the invite key as hash keys, and values that respond to the === operator(includes procs and regexes). The default value is looking for users by email and validating with Devise.email_regexp {:email => Devise.email_regexp}.
|
128
128
|
|
129
129
|
* validate_on_invite: force a record to be valid before being actually invited.
|
130
130
|
|
@@ -181,6 +181,23 @@ There are just two actions in DeviseInvitable that allows any set of parameters
|
|
181
181
|
* invite (Devise::InvitationsController#create) - Permits only the authentication keys (like email)
|
182
182
|
* accept_invitation (Devise::InvitationsController#update) - Permits invitation_token plus password and password_confirmation
|
183
183
|
|
184
|
+
Here is an example of what your application controller might need to include in order to add these parameters to the invitation view:
|
185
|
+
|
186
|
+
before_filter :configure_permitted_parameters, if: :devise_controller?
|
187
|
+
|
188
|
+
protected
|
189
|
+
|
190
|
+
def configure_permitted_parameters
|
191
|
+
# Only add some parameters
|
192
|
+
devise_parameter_sanitizer.for(:accept_invitation).concat [:first_name, :last_name, :phone]
|
193
|
+
# Override accepted parameters
|
194
|
+
devise_parameter_sanitizer.for(:accept_invitation) do |u|
|
195
|
+
u.permit(:first_name, :last_name, :phone, :password, :password_confirmation,
|
196
|
+
:invitation_token)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
184
201
|
== Usage
|
185
202
|
|
186
203
|
=== Send an invitation
|
@@ -25,6 +25,7 @@ module Devise
|
|
25
25
|
|
26
26
|
attr_accessor :skip_invitation
|
27
27
|
attr_accessor :completing_invite
|
28
|
+
attr_reader :raw_invitation_token
|
28
29
|
|
29
30
|
included do
|
30
31
|
include ::DeviseInvitable::Inviter
|
@@ -146,8 +147,8 @@ module Devise
|
|
146
147
|
end
|
147
148
|
|
148
149
|
def clear_errors_on_valid_keys
|
149
|
-
self.class.invite_key.each do |key,
|
150
|
-
self.errors.delete(key) if
|
150
|
+
self.class.invite_key.each do |key, value|
|
151
|
+
self.errors.delete(key) if value === self.send(key)
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
@@ -158,6 +159,11 @@ module Devise
|
|
158
159
|
send_devise_notification(:invitation_instructions, @raw_invitation_token)
|
159
160
|
end
|
160
161
|
|
162
|
+
# provide alias to the encrypted invitation_token stored by devise
|
163
|
+
def encrypted_invitation_token
|
164
|
+
self.invitation_token
|
165
|
+
end
|
166
|
+
|
161
167
|
protected
|
162
168
|
# Overriding the method in Devise's :validatable module so password is not required on inviting
|
163
169
|
def password_required?
|
@@ -221,7 +227,9 @@ module Devise
|
|
221
227
|
invite_key_array = invite_key_fields
|
222
228
|
attributes_hash = {}
|
223
229
|
invite_key_array.each do |k,v|
|
224
|
-
|
230
|
+
attribute = attributes.delete(k)
|
231
|
+
attribute = attribute.to_s.strip if strip_whitespace_keys.include?(k)
|
232
|
+
attributes_hash[k] = attribute
|
225
233
|
end
|
226
234
|
|
227
235
|
invitable = find_or_initialize_with_errors(invite_key_array, attributes_hash)
|
@@ -270,7 +278,7 @@ module Devise
|
|
270
278
|
|
271
279
|
def find_by_invitation_token(original_token, only_valid)
|
272
280
|
invitation_token = Devise.token_generator.digest(self, :invitation_token, original_token)
|
273
|
-
|
281
|
+
|
274
282
|
invitable = find_or_initialize_with_error_by(:invitation_token, invitation_token)
|
275
283
|
if !invitable.persisted? && Devise.allow_insecure_token_lookup
|
276
284
|
invitable = find_or_initialize_with_error_by(:invitation_token, original_token)
|
@@ -1,11 +1,26 @@
|
|
1
1
|
module DeviseInvitable
|
2
2
|
module ParameterSanitizer
|
3
3
|
def invite
|
4
|
-
default_params.permit(
|
4
|
+
default_params.permit self.for(:invite)
|
5
5
|
end
|
6
6
|
|
7
7
|
def accept_invitation
|
8
|
-
default_params.permit(
|
8
|
+
default_params.permit self.for(:accept_invitation)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.alias_method_chain :attributes_for, :invitable
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def attributes_for_with_invitable(kind)
|
17
|
+
case kind
|
18
|
+
when :invite
|
19
|
+
resource_class.invite_key_fields
|
20
|
+
when :accept_invitation
|
21
|
+
[:password, :password_confirmation, :invitation_token]
|
22
|
+
else attributes_for_without_invitable(kind)
|
23
|
+
end
|
9
24
|
end
|
10
25
|
end
|
11
26
|
end
|
@@ -11,6 +11,10 @@ class InvitableTest < ActiveSupport::TestCase
|
|
11
11
|
assert_nil new_user.invitation_token
|
12
12
|
end
|
13
13
|
|
14
|
+
test 'should not generate the raw invitation token after creating a record' do
|
15
|
+
assert_nil new_user.raw_invitation_token
|
16
|
+
end
|
17
|
+
|
14
18
|
test 'should regenerate invitation token each time' do
|
15
19
|
user = new_user
|
16
20
|
user.invite!
|
@@ -25,6 +29,21 @@ class InvitableTest < ActiveSupport::TestCase
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
test 'should alias the invitation_token method with encrypted_invitation_token' do
|
33
|
+
user = new_user
|
34
|
+
user.invite!
|
35
|
+
assert_equal user.invitation_token, user.encrypted_invitation_token
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'should return the correct raw_invitation_token ' do
|
39
|
+
user = new_user
|
40
|
+
raw, enc = Devise.token_generator.generate(user.class, :invitation_token)
|
41
|
+
#stub the generator so the tokens are the same
|
42
|
+
Devise.token_generator.stubs(:generate).returns([raw, enc])
|
43
|
+
user.invite!
|
44
|
+
assert_equal user.raw_invitation_token, raw
|
45
|
+
end
|
46
|
+
|
28
47
|
test 'should set invitation created and sent at each time' do
|
29
48
|
user = new_user
|
30
49
|
user.invite!
|
@@ -78,19 +97,28 @@ class InvitableTest < ActiveSupport::TestCase
|
|
78
97
|
end
|
79
98
|
end
|
80
99
|
|
81
|
-
test 'should invite with
|
100
|
+
test 'should invite with multiple columns for invite key' do
|
82
101
|
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/)
|
83
102
|
user = User.invite!(:email => "valid@email.com", :username => "name")
|
84
103
|
assert user.persisted?
|
85
104
|
assert user.errors.empty?
|
86
105
|
end
|
87
106
|
|
107
|
+
test 'should allow non-string columns for invite key' do
|
108
|
+
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :profile_id => :present?.to_proc, :active => true)
|
109
|
+
user = User.invite!(:email => "valid@email.com", :profile_id => 1, :active => true)
|
110
|
+
assert user.persisted?
|
111
|
+
assert user.errors.empty?
|
112
|
+
end
|
113
|
+
|
88
114
|
test 'should not invite with some missing columns when invite key is an array' do
|
89
|
-
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z
|
115
|
+
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/, :profile_id => :present?.to_proc, :active => true)
|
90
116
|
user = User.invite!(:email => "valid@email.com")
|
91
117
|
assert user.new_record?
|
92
118
|
assert user.errors.present?
|
93
119
|
assert user.errors[:username]
|
120
|
+
assert user.errors[:profile_id]
|
121
|
+
assert user.errors[:active]
|
94
122
|
assert user.errors[:email].empty?
|
95
123
|
end
|
96
124
|
|
@@ -503,8 +531,9 @@ class InvitableTest < ActiveSupport::TestCase
|
|
503
531
|
|
504
532
|
test "user.invite! should strip whitespace from the class's strip_whitespace_keys" do
|
505
533
|
# Devise default is email
|
506
|
-
user = User.invite!(:email => " valid@email.com ")
|
534
|
+
user = User.invite!(:email => " valid@email.com ", :active => true)
|
507
535
|
assert user.email == "valid@email.com"
|
536
|
+
assert user.active == true
|
508
537
|
end
|
509
538
|
|
510
539
|
test 'should pass validation before accept if field is required in post-invited instance' do
|
data/test/models_test.rb
CHANGED
@@ -70,5 +70,9 @@ class ModelsTest < ActiveSupport::TestCase
|
|
70
70
|
test 'invitable attributes' do
|
71
71
|
assert_nil User.new.invitation_token
|
72
72
|
assert_nil User.new.invitation_sent_at
|
73
|
+
#raw token
|
74
|
+
assert_nil User.new.raw_invitation_token
|
75
|
+
#encrypted token - alias to invitation token
|
76
|
+
assert_nil User.new.encrypted_invitation_token
|
73
77
|
end
|
74
78
|
end
|
@@ -26,8 +26,10 @@ class User < PARENT_MODEL_CLASS
|
|
26
26
|
field :invited_by_id, :type => Integer
|
27
27
|
field :invited_by_type, :type => String
|
28
28
|
|
29
|
-
|
30
29
|
field :username
|
30
|
+
field :profile_id
|
31
|
+
field :active
|
32
|
+
|
31
33
|
validates_presence_of :email
|
32
34
|
validates_presence_of :encrypted_password, :if => :password_required?
|
33
35
|
end
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_invitable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 1.3.0
|
4
|
+
version: 1.3.1
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Sergio Cambra
|
@@ -15,21 +9,15 @@ autorequire:
|
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
11
|
|
18
|
-
date: 2013-
|
12
|
+
date: 2013-11-05 00:00:00 Z
|
19
13
|
dependencies:
|
20
14
|
- !ruby/object:Gem::Dependency
|
21
15
|
name: bundler
|
22
16
|
prerelease: false
|
23
17
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
18
|
requirements:
|
26
19
|
- - ">="
|
27
20
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 19
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 1
|
32
|
-
- 0
|
33
21
|
version: 1.1.0
|
34
22
|
type: :development
|
35
23
|
version_requirements: *id001
|
@@ -37,21 +25,12 @@ dependencies:
|
|
37
25
|
name: actionmailer
|
38
26
|
prerelease: false
|
39
27
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
28
|
requirements:
|
42
29
|
- - ">="
|
43
30
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 3
|
45
|
-
segments:
|
46
|
-
- 3
|
47
|
-
- 2
|
48
|
-
- 6
|
49
31
|
version: 3.2.6
|
50
32
|
- - <
|
51
33
|
- !ruby/object:Gem::Version
|
52
|
-
hash: 9
|
53
|
-
segments:
|
54
|
-
- 5
|
55
34
|
version: "5"
|
56
35
|
type: :runtime
|
57
36
|
version_requirements: *id002
|
@@ -59,15 +38,9 @@ dependencies:
|
|
59
38
|
name: devise
|
60
39
|
prerelease: false
|
61
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
41
|
requirements:
|
64
42
|
- - ">="
|
65
43
|
- !ruby/object:Gem::Version
|
66
|
-
hash: 3
|
67
|
-
segments:
|
68
|
-
- 3
|
69
|
-
- 1
|
70
|
-
- 0
|
71
44
|
version: 3.1.0
|
72
45
|
type: :runtime
|
73
46
|
version_requirements: *id003
|
@@ -163,6 +136,8 @@ files:
|
|
163
136
|
homepage: https://github.com/scambra/devise_invitable
|
164
137
|
licenses:
|
165
138
|
- MIT
|
139
|
+
metadata: {}
|
140
|
+
|
166
141
|
post_install_message:
|
167
142
|
rdoc_options:
|
168
143
|
- --main
|
@@ -171,33 +146,21 @@ rdoc_options:
|
|
171
146
|
require_paths:
|
172
147
|
- lib
|
173
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
-
none: false
|
175
149
|
requirements:
|
176
150
|
- - ">="
|
177
151
|
- !ruby/object:Gem::Version
|
178
|
-
hash: 59
|
179
|
-
segments:
|
180
|
-
- 1
|
181
|
-
- 8
|
182
|
-
- 6
|
183
152
|
version: 1.8.6
|
184
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
154
|
requirements:
|
187
155
|
- - ">="
|
188
156
|
- !ruby/object:Gem::Version
|
189
|
-
hash: 23
|
190
|
-
segments:
|
191
|
-
- 1
|
192
|
-
- 3
|
193
|
-
- 6
|
194
157
|
version: 1.3.6
|
195
158
|
requirements: []
|
196
159
|
|
197
160
|
rubyforge_project:
|
198
|
-
rubygems_version:
|
161
|
+
rubygems_version: 2.0.7
|
199
162
|
signing_key:
|
200
|
-
specification_version:
|
163
|
+
specification_version: 4
|
201
164
|
summary: An invitation strategy for Devise
|
202
165
|
test_files:
|
203
166
|
- test/functional/controller_helpers_test.rb
|
@@ -251,3 +214,4 @@ test_files:
|
|
251
214
|
- test/rails_app/script/rails
|
252
215
|
- test/routes_test.rb
|
253
216
|
- test/test_helper.rb
|
217
|
+
has_rdoc:
|