devise_invitable 0.4.2 → 0.5.0
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.
- data/README.rdoc +9 -2
- data/app/controllers/devise/invitations_controller.rb +10 -5
- data/lib/devise_invitable.rb +4 -0
- data/lib/devise_invitable/inviter.rb +35 -0
- data/lib/devise_invitable/model.rb +1 -20
- data/lib/devise_invitable/version.rb +1 -1
- metadata +17 -17
data/README.rdoc
CHANGED
@@ -128,10 +128,10 @@ To accept an invitation with a token use the <tt>accept_invitation!</tt> class m
|
|
128
128
|
|
129
129
|
Since the invitations controller take care of all the creation/acceptation of an invitation, in most cases you wouldn't call the <tt>invite!</tt> and <tt>accept_invitation!</tt> methods directly.
|
130
130
|
Instead, in your views, put a link to <tt>new_user_invitation_path</tt> or <tt>new_invitation_path(:user)</tt> or even <tt>/users/invitation/new</tt> to prepare and send an invitation (to a user in this example).
|
131
|
-
|
131
|
+
|
132
|
+
After an invitation is created and sent, the inviter will be redirected to after_accept_path_for(resource), which is the same path as after_sign_in_path_for by default. If you want to override the path, override invitations controller and define after_accept_path_for method. More on {Devise's README}[http://github.com/plataformatec/devise], "Controller filters and helpers" section.
|
132
133
|
|
133
134
|
The invitation email includes a link to accept the invitation that looks like this: <tt>/users/invitation/accept?invitation_token=abcd123</tt>. When clicked, the invited must set a password in order to accept its invitation. Note that if the invitation_token is not present or not valid, the invited is redirected to after_sign_out_path_for(resource_name).
|
134
|
-
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks. More on {Devise's README}[http://github.com/plataformatec/devise], "Controller filters and helpers" section.
|
135
135
|
|
136
136
|
The controller sets the invited_by_id attribute for the new user to the current user. This will let you easily keep track of who invited who.
|
137
137
|
|
@@ -150,6 +150,13 @@ You would have a User model which is configured as invitable and an Admin model
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
And include DeviseInvitable::Inviter module into Admin model:
|
154
|
+
|
155
|
+
class Admin < ActiveRecord::Base
|
156
|
+
devise :database_authenticatable, :validatable
|
157
|
+
include DeviseInvitable::Inviter
|
158
|
+
end
|
159
|
+
|
153
160
|
== I18n
|
154
161
|
|
155
162
|
DeviseInvitable uses flash messages with I18n with the flash keys <tt>:send_instructions</tt>, <tt>:invitation_token_invalid</tt> and <tt>:updated</tt>. To customize your app, you can modify the generated locale file:
|
@@ -18,9 +18,9 @@ class Devise::InvitationsController < ApplicationController
|
|
18
18
|
|
19
19
|
if resource.errors.empty?
|
20
20
|
set_flash_message :notice, :send_instructions, :email => self.resource.email
|
21
|
-
|
21
|
+
respond_with resource, :location => redirect_location(resource_name, resource)
|
22
22
|
else
|
23
|
-
render_with_scope :new
|
23
|
+
respond_with_navigational(resource) { render_with_scope :new }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -40,9 +40,10 @@ class Devise::InvitationsController < ApplicationController
|
|
40
40
|
|
41
41
|
if resource.errors.empty?
|
42
42
|
set_flash_message :notice, :updated
|
43
|
-
|
43
|
+
sign_in(resource_name, resource)
|
44
|
+
respond_with resource, :location => after_accept_path_for(resource)
|
44
45
|
else
|
45
|
-
render_with_scope :edit
|
46
|
+
respond_with_navigational(resource){ render_with_scope :edit }
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -55,7 +56,11 @@ class Devise::InvitationsController < ApplicationController
|
|
55
56
|
unless current_inviter.nil? || current_inviter.has_invitations_left?
|
56
57
|
build_resource
|
57
58
|
set_flash_message :alert, :no_invitations_remaining
|
58
|
-
render_with_scope :new
|
59
|
+
respond_with_navigational(resource) { render_with_scope :new }
|
59
60
|
end
|
60
61
|
end
|
62
|
+
|
63
|
+
def after_accept_path_for(resource)
|
64
|
+
after_sign_in_path_for(resource)
|
65
|
+
end
|
61
66
|
end
|
data/lib/devise_invitable.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module DeviseInvitable
|
2
|
+
module Inviter
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
extend ClassMethods
|
7
|
+
attr_accessor :invitation_limit unless respond_to? :invitation_limit
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return true if this user has invitations left to send
|
11
|
+
def has_invitations_left?
|
12
|
+
if self.class.invitation_limit.present?
|
13
|
+
if invitation_limit
|
14
|
+
return invitation_limit > 0
|
15
|
+
else
|
16
|
+
return self.class.invitation_limit > 0
|
17
|
+
end
|
18
|
+
else
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def decrement_invitation_limit!
|
25
|
+
if self.class.invitation_limit.present?
|
26
|
+
self.invitation_limit ||= self.class.invitation_limit
|
27
|
+
self.update_attribute(:invitation_limit, invitation_limit - 1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
Devise::Models.config(self, :invitation_limit)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -24,6 +24,7 @@ module Devise
|
|
24
24
|
attr_accessor :skip_invitation
|
25
25
|
|
26
26
|
included do
|
27
|
+
include ::DeviseInvitable::Inviter
|
27
28
|
belongs_to :invited_by, :polymorphic => true
|
28
29
|
end
|
29
30
|
|
@@ -41,19 +42,6 @@ module Devise
|
|
41
42
|
persisted? && invitation_token.present?
|
42
43
|
end
|
43
44
|
|
44
|
-
# Return true if this user has invitations left to send
|
45
|
-
def has_invitations_left?
|
46
|
-
if self.class.invitation_limit.present?
|
47
|
-
if invitation_limit
|
48
|
-
return invitation_limit > 0
|
49
|
-
else
|
50
|
-
return self.class.invitation_limit > 0
|
51
|
-
end
|
52
|
-
else
|
53
|
-
return true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
45
|
# Reset invitation token and send invitation again
|
58
46
|
def invite!
|
59
47
|
if new_record? || invited?
|
@@ -81,13 +69,6 @@ module Devise
|
|
81
69
|
end
|
82
70
|
|
83
71
|
protected
|
84
|
-
def decrement_invitation_limit!
|
85
|
-
if self.class.invitation_limit.present?
|
86
|
-
self.invitation_limit ||= self.class.invitation_limit
|
87
|
-
self.update_attribute(:invitation_limit, invitation_limit - 1)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
72
|
# Overriding the method in Devise's :validatable module so password is not required on inviting
|
92
73
|
def password_required?
|
93
74
|
!@skip_password && super
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sergio Cambra
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-05-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
hash: 7
|
46
46
|
segments:
|
@@ -48,6 +48,13 @@ dependencies:
|
|
48
48
|
- 0
|
49
49
|
- 0
|
50
50
|
version: 3.0.0
|
51
|
+
- - <=
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 3
|
56
|
+
- 2
|
57
|
+
version: "3.2"
|
51
58
|
type: :runtime
|
52
59
|
version_requirements: *id002
|
53
60
|
- !ruby/object:Gem::Dependency
|
@@ -56,22 +63,14 @@ dependencies:
|
|
56
63
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
64
|
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - ~>
|
60
67
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
68
|
+
hash: 25
|
62
69
|
segments:
|
63
70
|
- 1
|
64
|
-
-
|
65
|
-
- 0
|
66
|
-
version: 1.2.0
|
67
|
-
- - <=
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
hash: 7
|
70
|
-
segments:
|
71
|
+
- 3
|
71
72
|
- 1
|
72
|
-
|
73
|
-
- 0
|
74
|
-
version: 1.4.0
|
73
|
+
version: 1.3.1
|
75
74
|
type: :runtime
|
76
75
|
version_requirements: *id003
|
77
76
|
description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation by setting a password.
|
@@ -98,6 +97,7 @@ files:
|
|
98
97
|
- lib/devise_invitable/controllers/helpers.rb
|
99
98
|
- lib/devise_invitable/controllers/url_helpers.rb
|
100
99
|
- lib/devise_invitable/version.rb
|
100
|
+
- lib/devise_invitable/inviter.rb
|
101
101
|
- lib/generators/active_record/devise_invitable_generator.rb
|
102
102
|
- lib/generators/active_record/templates/migration.rb
|
103
103
|
- lib/generators/devise_invitable/views_generator.rb
|