devise_invitable 2.0.3 → 2.0.6
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 +12 -0
- data/README.rdoc +61 -6
- data/app/controllers/devise/invitations_controller.rb +2 -2
- data/config/locales/de.yml +31 -31
- data/config/locales/es.yml +2 -2
- data/config/locales/ja.yml +0 -1
- data/lib/devise_invitable/models/authenticatable.rb +7 -1
- data/lib/devise_invitable/models.rb +7 -3
- data/lib/devise_invitable/version.rb +1 -1
- data/test/models/invitable_test.rb +16 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3803fa69fe6bdecc811ab934878cc365f31ae0a124e54bbde34ad967752f1d3c
|
4
|
+
data.tar.gz: df5c2b785956d22e8bf69d644326605a649f1fd76b1d19af04d4bcd48a3c15f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 925df2c1ef1a893f9e4d9b376b298fa5e21a4c516d8829d7990aa5e5b4a18a7d288d209658f38a1793c51b5a4fca83cbff814a19f2e725ddd8baa4307f448092
|
7
|
+
data.tar.gz: 4380da8ff7d5ff6e680393ab8f8935dae7b10e3d50271fdfaa839d0968caad99a56282ba6765b3d18f2f70090796c607c0198dc3932f3ac21f24821a8635a4e5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 2.0.6
|
2
|
+
- Fix submit form failure with turbolinks, fixes ([#865](https://github.com/scambra/devise_invitable/issues/865))
|
3
|
+
- Fix obsolete symbols in German translation ([#864](https://github.com/scambra/devise_invitable/pull/864))
|
4
|
+
|
5
|
+
## 2.0.5
|
6
|
+
- Fix NoMethodError in random_password when validatable is not used ([#850](https://github.com/scambra/devise_invitable/pull/850))
|
7
|
+
|
8
|
+
## 2.0.4
|
9
|
+
- Fix devise deprecations ([#842](https://github.com/scambra/devise_invitable/pull/842))
|
10
|
+
- Update translations ([#844](https://github.com/scambra/devise_invitable/pull/844), [#845](https://github.com/scambra/devise_invitable/pull/845))
|
11
|
+
- Fix/enforce initial password length to follow devise ([#848](https://github.com/scambra/devise_invitable/pull/848))
|
12
|
+
|
1
13
|
## 2.0.3
|
2
14
|
- Add locales ([#834](https://github.com/scambra/devise_invitable/pull/834), [#835](https://github.com/scambra/devise_invitable/pull/835))
|
3
15
|
- Remove index on invitations_count column ([#830](https://github.com/scambra/devise_invitable/pull/830))
|
data/README.rdoc
CHANGED
@@ -35,14 +35,14 @@ Replace MODEL by the class name you want to add DeviseInvitable, like <tt>User</
|
|
35
35
|
|
36
36
|
Follow the walkthrough for Devise and after it's done, follow this walkthrough.
|
37
37
|
|
38
|
-
|
38
|
+
==== Devise Configuration
|
39
39
|
Add <tt>:invitable</tt> to the <tt>devise</tt> call in your model (we’re assuming here you already have a User model with some Devise modules):
|
40
40
|
|
41
41
|
class User < ActiveRecord::Base
|
42
42
|
devise :database_authenticatable, :confirmable, :invitable
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
==== ActiveRecord Migration
|
46
46
|
Add <tt>t.invitable</tt> to your Devise model migration:
|
47
47
|
|
48
48
|
create_table :users do
|
@@ -181,15 +181,15 @@ To change behaviour of inviting or accepting users, you can simply override two
|
|
181
181
|
class Users::InvitationsController < Devise::InvitationsController
|
182
182
|
private
|
183
183
|
|
184
|
-
#
|
185
|
-
# should return an instance of resource class
|
184
|
+
# This is called when creating invitation.
|
185
|
+
# It should return an instance of resource class.
|
186
186
|
def invite_resource
|
187
187
|
# skip sending emails on invite
|
188
188
|
super { |user| user.skip_invitation = true }
|
189
189
|
end
|
190
190
|
|
191
|
-
#
|
192
|
-
# should return an instance of resource class
|
191
|
+
# This is called when accepting invitation.
|
192
|
+
# It should return an instance of resource class.
|
193
193
|
def accept_resource
|
194
194
|
resource = resource_class.accept_invitation!(update_resource_params)
|
195
195
|
# Report accepting invitation to analytics
|
@@ -217,6 +217,61 @@ Here is an example of what your application controller might need to include in
|
|
217
217
|
devise_parameter_sanitizer.permit(:accept_invitation, keys: [:first_name, :last_name, :phone])
|
218
218
|
end
|
219
219
|
|
220
|
+
Here is an example setting a User's first name, last name, and role for a custom invitation:
|
221
|
+
|
222
|
+
#Configuring the InvitationsController to accept :first_name, :last_name, and :role
|
223
|
+
|
224
|
+
class Users::InvitationsController < Devise::InvitationsController
|
225
|
+
before_action :configure_permitted_parameters
|
226
|
+
|
227
|
+
protected
|
228
|
+
|
229
|
+
# Permit the new params here.
|
230
|
+
def configure_permitted_parameters
|
231
|
+
devise_parameter_sanitizer.permit(:invite, keys: [:first_name, :last_name, :role])
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
#Define your roles in the User model
|
236
|
+
|
237
|
+
class User < ApplicationRecord
|
238
|
+
has_many :models
|
239
|
+
|
240
|
+
enum role: {Role 1 Name: 0, Role 2 Name: 1, Role 3 Name: 2, etc...}
|
241
|
+
end
|
242
|
+
|
243
|
+
#In the Invitation view
|
244
|
+
|
245
|
+
<h2><%= t "devise.invitations.new.header" %></h2>
|
246
|
+
|
247
|
+
<%= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f| %>
|
248
|
+
<%= render "devise/shared/error_messages", resource: resource %>
|
249
|
+
<% resource.class.invite_key_fields.each do |field| -%>
|
250
|
+
<div class="field">
|
251
|
+
<%= f.label field %><br />
|
252
|
+
<%= f.text_field field %>
|
253
|
+
</div>
|
254
|
+
<% end %>
|
255
|
+
|
256
|
+
<div class="field">
|
257
|
+
<%= f.label :first_name %>
|
258
|
+
<%= f.text_field :first_name %>
|
259
|
+
</div>
|
260
|
+
|
261
|
+
<div class="field">
|
262
|
+
<%= f.label :last_name %>
|
263
|
+
<%= f.text_field :last_name %>
|
264
|
+
</div>
|
265
|
+
|
266
|
+
<div class="field">
|
267
|
+
<%= f.label :role %>
|
268
|
+
<%= f.select :role, options_for_select(User.roles.map { |key, value| [key.humanize, key] }), {prompt: "Select Role"} %>
|
269
|
+
</div>
|
270
|
+
|
271
|
+
<div class="actions">
|
272
|
+
<%= f.submit t("devise.invitations.new.submit_button") %>
|
273
|
+
</div>
|
274
|
+
<% end %>
|
220
275
|
|
221
276
|
== Usage
|
222
277
|
|
@@ -31,7 +31,7 @@ class Devise::InvitationsController < DeviseController
|
|
31
31
|
respond_with resource, location: after_invite_path_for(current_inviter, resource)
|
32
32
|
end
|
33
33
|
else
|
34
|
-
respond_with_navigational(resource) { render :new }
|
34
|
+
respond_with_navigational(resource) { render :new, status: :unprocessable_entity }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -63,7 +63,7 @@ class Devise::InvitationsController < DeviseController
|
|
63
63
|
end
|
64
64
|
else
|
65
65
|
resource.invitation_token = raw_invitation_token
|
66
|
-
respond_with_navigational(resource) { render :edit }
|
66
|
+
respond_with_navigational(resource) { render :edit, status: :unprocessable_entity }
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/config/locales/de.yml
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
de:
|
2
|
-
devise:
|
3
|
-
failure:
|
4
|
-
invited: "Du hast bereits eine Einladung erhalten. Nimm die Einladung an um dein Nutzerkonto zu erstellen."
|
5
|
-
invitations:
|
6
|
-
send_instructions: "Eine Einladung wurde an %{email} verschickt."
|
7
|
-
invitation_token_invalid: "Der Einladungs-Code ist ungültig!"
|
8
|
-
updated: "Dein Passwort wurde gesetzt. Du bist nun angemeldet."
|
9
|
-
updated_not_active: "Dein Passwort wurde gesetzt."
|
10
|
-
no_invitations_remaining: "Es gibt keine weiteren Einladungen"
|
11
|
-
invitation_removed: "Deine Einladung wurde gelöscht."
|
12
|
-
new:
|
13
|
-
header: "Einladung schicken"
|
14
|
-
submit_button: "Einladung schicken"
|
15
|
-
edit:
|
16
|
-
header: "Setze ein Passwort"
|
17
|
-
submit_button: "Passwort setzen"
|
18
|
-
mailer:
|
19
|
-
invitation_instructions:
|
20
|
-
subject: "Einladung"
|
21
|
-
hello: "Hallo %{email}"
|
22
|
-
someone_invited_you: "Jemand hat dich zu %{url} eingeladen. Du kannst die Einladung mit dem Link unten annehmen."
|
23
|
-
accept: "Einladung annehmen"
|
24
|
-
accept_until: "Diese Einladung ist gültig bis zum %{due_date}."
|
25
|
-
ignore: "Wenn du die Einladung nicht annehmen willst, ignoriere diese E-Mail einfach
|
26
|
-
time:
|
27
|
-
formats:
|
28
|
-
devise:
|
29
|
-
mailer:
|
30
|
-
invitation_instructions:
|
31
|
-
accept_until_format: "%d. %B %Y %H:%M"
|
1
|
+
de:
|
2
|
+
devise:
|
3
|
+
failure:
|
4
|
+
invited: "Du hast bereits eine Einladung erhalten. Nimm die Einladung an um dein Nutzerkonto zu erstellen."
|
5
|
+
invitations:
|
6
|
+
send_instructions: "Eine Einladung wurde an %{email} verschickt."
|
7
|
+
invitation_token_invalid: "Der Einladungs-Code ist ungültig!"
|
8
|
+
updated: "Dein Passwort wurde gesetzt. Du bist nun angemeldet."
|
9
|
+
updated_not_active: "Dein Passwort wurde gesetzt."
|
10
|
+
no_invitations_remaining: "Es gibt keine weiteren Einladungen"
|
11
|
+
invitation_removed: "Deine Einladung wurde gelöscht."
|
12
|
+
new:
|
13
|
+
header: "Einladung schicken"
|
14
|
+
submit_button: "Einladung schicken"
|
15
|
+
edit:
|
16
|
+
header: "Setze ein Passwort"
|
17
|
+
submit_button: "Passwort setzen"
|
18
|
+
mailer:
|
19
|
+
invitation_instructions:
|
20
|
+
subject: "Einladung"
|
21
|
+
hello: "Hallo %{email}"
|
22
|
+
someone_invited_you: "Jemand hat dich zu %{url} eingeladen. Du kannst die Einladung mit dem Link unten annehmen."
|
23
|
+
accept: "Einladung annehmen"
|
24
|
+
accept_until: "Diese Einladung ist gültig bis zum %{due_date}."
|
25
|
+
ignore: "Wenn du die Einladung nicht annehmen willst, ignoriere diese E-Mail einfach. Es wird kein Benutzerkonto erstellt solange du nicht die Einladung mittels des Links oben annimmst."
|
26
|
+
time:
|
27
|
+
formats:
|
28
|
+
devise:
|
29
|
+
mailer:
|
30
|
+
invitation_instructions:
|
31
|
+
accept_until_format: "%d. %B %Y %H:%M"
|
data/config/locales/es.yml
CHANGED
@@ -18,7 +18,7 @@ es:
|
|
18
18
|
mailer:
|
19
19
|
invitation_instructions:
|
20
20
|
subject: "Instruciones de la invitación"
|
21
|
-
hello: "
|
21
|
+
hello: "Hola %{email}"
|
22
22
|
someone_invited_you: "Has sido invitado a %{url}, puedes aceptarlo siguiendo el siguiente enlace"
|
23
23
|
accept: "Aceptar la invitación"
|
24
24
|
accept_until: "Esta invitación expirará en %{due_date}."
|
@@ -28,4 +28,4 @@ es:
|
|
28
28
|
devise:
|
29
29
|
mailer:
|
30
30
|
invitation_instructions:
|
31
|
-
accept_until_format: "%d de %B de %Y, %H:%M"
|
31
|
+
accept_until_format: "%d de %B de %Y, %H:%M"
|
data/config/locales/ja.yml
CHANGED
@@ -20,7 +20,6 @@ ja:
|
|
20
20
|
subject: '招待を承認するには'
|
21
21
|
hello: 'こんにちは、%{email}さん'
|
22
22
|
someone_invited_you: '%{url}に招待されました。以下のリンクから承認できます。'
|
23
|
-
accept: 'Accept invitation'
|
24
23
|
accept: '招待を承認する'
|
25
24
|
accept_until: 'この招待は%{due_date}まで有効です。'
|
26
25
|
ignore: '招待を承認しない場合は、このメールを無視してください。<br />あなたのアカウントは上記のリンク先にアクセスしパスワードを設定するまでは作成されません。'
|
@@ -1,11 +1,17 @@
|
|
1
1
|
module Devise
|
2
2
|
module Models
|
3
3
|
module Authenticatable
|
4
|
-
|
4
|
+
list = %i[
|
5
5
|
invitation_token invitation_created_at invitation_sent_at
|
6
6
|
invitation_accepted_at invitation_limit invited_by_type
|
7
7
|
invited_by_id invitations_count
|
8
8
|
]
|
9
|
+
|
10
|
+
if defined?(UNSAFE_ATTRIBUTES_FOR_SERIALIZATION)
|
11
|
+
UNSAFE_ATTRIBUTES_FOR_SERIALIZATION.concat(list)
|
12
|
+
else
|
13
|
+
BLACKLIST_FOR_SERIALIZATION.concat(list)
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
@@ -158,7 +158,8 @@ module Devise
|
|
158
158
|
self.downcase_keys if new_record_and_responds_to?(:downcase_keys)
|
159
159
|
self.strip_whitespace if new_record_and_responds_to?(:strip_whitespace)
|
160
160
|
|
161
|
-
|
161
|
+
validate = options.key?(:validate) ? options[:validate] : self.class.validate_on_invite
|
162
|
+
if save(validate: validate)
|
162
163
|
self.invited_by.decrement_invitation_limit! if !was_invited and self.invited_by.present?
|
163
164
|
deliver_invitation(options) unless skip_invitation
|
164
165
|
end
|
@@ -324,7 +325,7 @@ module Devise
|
|
324
325
|
end
|
325
326
|
|
326
327
|
yield invitable if block_given?
|
327
|
-
mail = invitable.invite!(nil, options) if invitable.errors.empty?
|
328
|
+
mail = invitable.invite!(nil, options.merge(validate: false)) if invitable.errors.empty?
|
328
329
|
[invitable, mail]
|
329
330
|
end
|
330
331
|
|
@@ -397,7 +398,10 @@ module Devise
|
|
397
398
|
# lower + upper case, a digit and a symbol.
|
398
399
|
# For more unusual rules, this method can be overridden.
|
399
400
|
def random_password
|
400
|
-
|
401
|
+
length = respond_to?(:password_length) ? password_length : Devise.password_length
|
402
|
+
|
403
|
+
prefix = 'aA1!'
|
404
|
+
prefix + Devise.friendly_token(length.last - prefix.length)
|
401
405
|
end
|
402
406
|
end
|
403
407
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'model_tests_helper'
|
3
3
|
|
4
|
+
class Validatable < User
|
5
|
+
devise :validatable, password_length: 10..20
|
6
|
+
end
|
7
|
+
|
4
8
|
class InvitableTest < ActiveSupport::TestCase
|
5
9
|
|
6
10
|
def setup
|
@@ -760,4 +764,16 @@ class InvitableTest < ActiveSupport::TestCase
|
|
760
764
|
assert user.persisted?
|
761
765
|
assert user.errors.empty?
|
762
766
|
end
|
767
|
+
|
768
|
+
test 'should set initial password following Devise.password_length' do
|
769
|
+
user = User.invite!(email: 'valid@email.com')
|
770
|
+
assert_empty user.errors
|
771
|
+
assert_equal Devise.password_length.last, user.password.length
|
772
|
+
end
|
773
|
+
|
774
|
+
test 'should set initial passsword using :validatable with custom password_length' do
|
775
|
+
user = Validatable.invite!(email: 'valid@email.com')
|
776
|
+
assert_empty user.errors
|
777
|
+
assert_equal Validatable.password_length.last, user.password.length
|
778
|
+
end
|
763
779
|
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.6
|
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: 2021-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -186,8 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
|
-
|
190
|
-
rubygems_version: 2.7.9
|
189
|
+
rubygems_version: 3.0.9
|
191
190
|
signing_key:
|
192
191
|
specification_version: 4
|
193
192
|
summary: An invitation strategy for Devise
|