devise_invitable 1.3.3 → 1.3.4
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 +4 -4
- data/README.rdoc +25 -1
- data/app/controllers/devise/invitations_controller.rb +2 -0
- data/lib/devise_invitable.rb +5 -0
- data/lib/devise_invitable/model.rb +8 -9
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -1
- data/lib/generators/devise_invitable/install_generator.rb +14 -0
- data/test/models/invitable_test.rb +3 -3
- data/test/rails_app/app/models/user.rb +4 -4
- data/test/rails_app/config/initializers/devise.rb +39 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec084ea3f59520fb7b2cfb978cd79d53ec5c1488
|
4
|
+
data.tar.gz: 257a48340805f6bfe02bc4fd1279a8694ab24c5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51c1385e5d2235ef7d3004208e489ecd241e99ade5afd8d7f5a1289e48cc7e9af6ba599b058862b82c5eb9c64ee02dc63d1be1526d692ccd86c33099bda8c8a8
|
7
|
+
data.tar.gz: 86ff8fa5e4f3990ca8c5dee25acc0e663204b671337e479fc19cfc0c5d2145d79f85f5a68c1ac53790b8a4c967050e13b0a070cf8943c6c4d639684ad68898b7
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= DeviseInvitable
|
2
2
|
{<img src="https://travis-ci.org/scambra/devise_invitable.png"/>}[http://travis-ci.org/scambra/devise_invitable]
|
3
3
|
|
4
|
-
It adds support to devise[http://github.com/plataformatec/devise] for
|
4
|
+
It adds support to devise[http://github.com/plataformatec/devise] for sending invitations by email (it requires to be authenticated) and accept the invitation setting the password.
|
5
5
|
|
6
6
|
DeviseInvitable currently supports Rails 3 and 4, if you want to use it with Rails 2.3 you must install version {0.2.3}[http://rubygems.org/gems/devise_invitable/versions/0.2.3]
|
7
7
|
|
@@ -172,6 +172,30 @@ be sure that you generate the views and put them into the controller that you ge
|
|
172
172
|
|
173
173
|
rails generate devise_invitable:views users/invitations
|
174
174
|
|
175
|
+
To change behaviour of inviting or accepting users, you can simply override two methods:
|
176
|
+
|
177
|
+
class Users::InvitationsController < Devise::InvitationsController
|
178
|
+
private
|
179
|
+
|
180
|
+
# this is called when creating invitation
|
181
|
+
# should return an instance of resource class
|
182
|
+
def invite_resource
|
183
|
+
## skip sending emails on invite
|
184
|
+
resource_class.invite!(invite_params, current_inviter) do |u|
|
185
|
+
u.skip_invitation = true
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# this is called when accepting invitation
|
190
|
+
# should return an instance of resource class
|
191
|
+
def accept_resource
|
192
|
+
resource = resource_class.accept_invitation!(update_resource_params)
|
193
|
+
## Report accepting invitation to analytics
|
194
|
+
Analytics.report('invite.accept', resource.id)
|
195
|
+
resource
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
175
199
|
== Strong Parameters
|
176
200
|
|
177
201
|
When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing DeviseInvitable to handle this concern at the controller as well. Read about it in {devise README}[http://github.com/plataformatec/devise#strong-parameters]
|
@@ -17,6 +17,7 @@ class Devise::InvitationsController < DeviseController
|
|
17
17
|
self.resource = invite_resource
|
18
18
|
|
19
19
|
if resource.errors.empty?
|
20
|
+
yield resource if block_given?
|
20
21
|
set_flash_message :notice, :send_instructions, :email => self.resource.email if self.resource.invitation_sent_at
|
21
22
|
respond_with resource, :location => after_invite_path_for(resource)
|
22
23
|
else
|
@@ -35,6 +36,7 @@ class Devise::InvitationsController < DeviseController
|
|
35
36
|
self.resource = accept_resource
|
36
37
|
|
37
38
|
if resource.errors.empty?
|
39
|
+
yield resource if block_given?
|
38
40
|
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
39
41
|
set_flash_message :notice, flash_message
|
40
42
|
sign_in(resource_name, resource)
|
data/lib/devise_invitable.rb
CHANGED
@@ -61,6 +61,11 @@ module Devise
|
|
61
61
|
# the #invited_by association is declared to be polymorphic. (default: nil)
|
62
62
|
mattr_accessor :invited_by_class_name
|
63
63
|
@@invited_by_class_name = nil
|
64
|
+
|
65
|
+
# Public: The column name used for counter_cache column. If this is nil,
|
66
|
+
# the #invited_by association is declared without counter_cache. (default: nil)
|
67
|
+
mattr_accessor :invited_by_counter_cache
|
68
|
+
@@invited_by_counter_cache = nil
|
64
69
|
end
|
65
70
|
|
66
71
|
Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => {:invitation => [nil, :new, :accept]}
|
@@ -35,7 +35,12 @@ module Devise
|
|
35
35
|
{:polymorphic => true}
|
36
36
|
end
|
37
37
|
if defined?(ActiveRecord) && 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
|
+
belongs_to_options.merge! :counter_cache => counter_cache if counter_cache
|
39
44
|
end
|
40
45
|
belongs_to :invited_by, belongs_to_options
|
41
46
|
|
@@ -61,9 +66,8 @@ module Devise
|
|
61
66
|
def self.required_fields(klass)
|
62
67
|
fields = [:invitation_token, :invitation_created_at, :invitation_sent_at, :invitation_accepted_at,
|
63
68
|
:invitation_limit, :invited_by_id, :invited_by_type]
|
64
|
-
if
|
65
|
-
|
66
|
-
end
|
69
|
+
fields << :invitations_count if defined?(ActiveRecord) && self < ActiveRecord::Base
|
70
|
+
fields -= [:invited_by_type] if Devise.invited_by_class_name
|
67
71
|
fields
|
68
72
|
end
|
69
73
|
|
@@ -282,11 +286,6 @@ module Devise
|
|
282
286
|
invitable unless only_valid && invitable.errors.present?
|
283
287
|
end
|
284
288
|
|
285
|
-
# Generate a token checking if one does not already exist in the database.
|
286
|
-
def invitation_token
|
287
|
-
generate_token(:invitation_token)
|
288
|
-
end
|
289
|
-
|
290
289
|
# Callback convenience methods
|
291
290
|
def before_invitation_accepted(*args, &blk)
|
292
291
|
set_callback(:invitation_accepted, :before, *args, &blk)
|
@@ -23,7 +23,7 @@ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
23
23
|
def down
|
24
24
|
change_table :<%= table_name %> do |t|
|
25
25
|
t.remove_references :invited_by, :polymorphic => true
|
26
|
-
t.remove :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at
|
26
|
+
t.remove :invitations_count, :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -43,6 +43,20 @@ module DeviseInvitable
|
|
43
43
|
# Default: false
|
44
44
|
# config.validate_on_invite = true
|
45
45
|
|
46
|
+
# Resend invitation if user with invited status is invited again
|
47
|
+
# Default: true
|
48
|
+
# config.resend_invitation = false
|
49
|
+
|
50
|
+
# The class name of the inviting model. If this is nil,
|
51
|
+
# the #invited_by association is declared to be polymorphic.
|
52
|
+
# Default: nil
|
53
|
+
# config.invited_by_class_name = 'User'
|
54
|
+
|
55
|
+
# The column name used for counter_cache column. If this is nil,
|
56
|
+
# the #invited_by association is declared without counter_cache.
|
57
|
+
# Default: nil
|
58
|
+
# config.invited_by_counter_cache = :invitations_count
|
59
|
+
|
46
60
|
CONTENT
|
47
61
|
end
|
48
62
|
end
|
@@ -548,13 +548,13 @@ class InvitableTest < ActiveSupport::TestCase
|
|
548
548
|
|
549
549
|
test 'should pass validation before accept if field is required in post-invited instance' do
|
550
550
|
user = User.invite!(:email => "valid@email.com")
|
551
|
-
user.
|
551
|
+
user.testing_accepted_or_not_invited = true
|
552
552
|
assert_equal true, user.valid?
|
553
553
|
end
|
554
554
|
|
555
555
|
test 'should fail validation after accept if field is required in post-invited instance' do
|
556
556
|
user = User.invite!(:email => "valid@email.com")
|
557
|
-
user.
|
557
|
+
user.testing_accepted_or_not_invited = true
|
558
558
|
user.accept_invitation!
|
559
559
|
assert_equal false, user.valid?
|
560
560
|
end
|
@@ -562,7 +562,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
562
562
|
test 'should pass validation after accept if field is required in post-invited instance' do
|
563
563
|
user = User.invite!(:email => "valid@email.com")
|
564
564
|
user.username = 'test'
|
565
|
-
user.
|
565
|
+
user.testing_accepted_or_not_invited = true
|
566
566
|
user.bio = "Test"
|
567
567
|
user.accept_invitation!
|
568
568
|
assert_equal true, user.valid?
|
@@ -39,12 +39,12 @@ class User < PARENT_MODEL_CLASS
|
|
39
39
|
attr_accessor :callback_works, :bio, :token
|
40
40
|
validates :username, :length => { :maximum => 20 }
|
41
41
|
|
42
|
-
attr_accessor :
|
43
|
-
validates :username, :presence => true, :if => :
|
42
|
+
attr_accessor :testing_accepted_or_not_invited
|
43
|
+
validates :username, :presence => true, :if => :testing_accepted_or_not_invited_validator?
|
44
44
|
validates :bio, :presence => true, :if => :invitation_accepted?
|
45
45
|
|
46
|
-
def
|
47
|
-
|
46
|
+
def testing_accepted_or_not_invited_validator?
|
47
|
+
testing_accepted_or_not_invited && accepted_or_not_invited?
|
48
48
|
end
|
49
49
|
|
50
50
|
after_invitation_accepted do |object|
|
@@ -90,6 +90,45 @@ Devise.setup do |config|
|
|
90
90
|
# Setup a pepper to generate the encrypted password.
|
91
91
|
# config.pepper = "e31589192aeea8807cb7d8686b0f8484d6cbfaaa65443d45144519ed1d4ffbc6ccb73b21a69ece276d94f2cac95d83990d824f36f301d6f585ededd1bf90d67d"
|
92
92
|
|
93
|
+
# ==> Configuration for :invitable
|
94
|
+
# The period the generated invitation token is valid, after
|
95
|
+
# this period, the invited resource won't be able to accept the invitation.
|
96
|
+
# When invite_for is 0 (the default), the invitation won't expire.
|
97
|
+
# config.invite_for = 2.weeks
|
98
|
+
|
99
|
+
# Number of invitations users can send.
|
100
|
+
# - If invitation_limit is nil, there is no limit for invitations, users can
|
101
|
+
# send unlimited invitations, invitation_limit column is not used.
|
102
|
+
# - If invitation_limit is 0, users can't send invitations by default.
|
103
|
+
# - If invitation_limit n > 0, users can send n invitations.
|
104
|
+
# You can change invitation_limit column for some users so they can send more
|
105
|
+
# or less invitations, even with global invitation_limit = 0
|
106
|
+
# Default: nil
|
107
|
+
# config.invitation_limit = 5
|
108
|
+
|
109
|
+
# The key to be used to check existing users when sending an invitation
|
110
|
+
# and the regexp used to test it when validate_on_invite is not set.
|
111
|
+
# config.invite_key = {:email => /\\A[^@]+@[^@]+\\z/}
|
112
|
+
# config.invite_key = {:email => /\\A[^@]+@[^@]+\\z/, :username => nil}
|
113
|
+
|
114
|
+
# Flag that force a record to be valid before being actually invited
|
115
|
+
# Default: false
|
116
|
+
# config.validate_on_invite = true
|
117
|
+
|
118
|
+
# Resend invitation if user with invited status is invited again
|
119
|
+
# Default: true
|
120
|
+
# config.resend_invitation = false
|
121
|
+
|
122
|
+
# The class name of the inviting model. If this is nil,
|
123
|
+
# the #invited_by association is declared to be polymorphic.
|
124
|
+
# Default: nil
|
125
|
+
# config.invited_by_class_name = 'User'
|
126
|
+
|
127
|
+
# The column name used for counter_cache column. If this is nil,
|
128
|
+
# the #invited_by association is declared without counter_cache.
|
129
|
+
# Default: nil
|
130
|
+
config.invited_by_counter_cache = :invitations_count
|
131
|
+
|
93
132
|
# ==> Configuration for :confirmable
|
94
133
|
# A period that the user is allowed to access the website even without
|
95
134
|
# confirming his account. For instance, if set to 2.days, the user will be
|
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.3.
|
4
|
+
version: 1.3.4
|
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-
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|