devise_invitable 0.5.7 → 0.6.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.

@@ -149,6 +149,18 @@ To accept an invitation with a token use the <tt>accept_invitation!</tt> class m
149
149
 
150
150
  User.accept_invitation!(:invitation_token => params[:invitation_token], :password => "ad97nwj3o2", :name => "John Doe")
151
151
 
152
+ === Callbacks
153
+
154
+ A callback event is fired before and after an invitation is accepted (User#accept_invitation!). For example, in your resource model you can add:
155
+
156
+ after_invitation_accepted :email_invited_by
157
+
158
+ def email_invited_by
159
+ # ...
160
+ end
161
+
162
+ The callbacks support all options and arguments available to the standard callbacks provided by AR.
163
+
152
164
  == Integration in a Rails application
153
165
 
154
166
  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.
@@ -173,7 +185,7 @@ You would have a User model which is configured as invitable and an Admin model
173
185
  class ApplicationController < ActionController::Base
174
186
  protected
175
187
  def authenticate_inviter!
176
- authenticate_admin!(true)
188
+ authenticate_admin!(:force => true)
177
189
  end
178
190
  end
179
191
 
@@ -1,7 +1,7 @@
1
1
  module DeviseInvitable::Controllers::Helpers
2
2
  protected
3
3
  def authenticate_inviter!
4
- send(:"authenticate_#{resource_name}!", true)
4
+ send(:"authenticate_#{resource_name}!", :force => true)
5
5
  end
6
6
  end
7
7
  ActionController::Base.send :include, DeviseInvitable::Controllers::Helpers
@@ -5,10 +5,5 @@ module DeviseInvitable
5
5
  def invitation_instructions(record)
6
6
  devise_mail(record, :invitation_instructions)
7
7
  end
8
-
9
- def invitation(record)
10
- ActiveSupport::Deprecation.warn('invitation has been renamed to invitation_instructions')
11
- invitation_instructions(record)
12
- end
13
8
  end
14
9
  end
@@ -24,17 +24,22 @@ module Devise
24
24
  attr_accessor :skip_invitation
25
25
 
26
26
  included do
27
- include ::DeviseInvitable::Inviter
27
+ include ::DeviseInvitable::Inviter
28
28
  belongs_to :invited_by, :polymorphic => true
29
+
30
+ include ActiveSupport::Callbacks
31
+ define_callbacks :invitation_accepted
29
32
  end
30
33
 
31
34
  # Accept an invitation by clearing invitation token and confirming it if model
32
35
  # is confirmable
33
36
  def accept_invitation!
34
37
  if self.invited? && self.valid?
35
- self.invitation_token = nil
36
- self.invitation_accepted_at = Time.now.utc # if has_attribute? :invitation_accepted_at
37
- self.save(:validate => false)
38
+ run_callbacks :invitation_accepted do
39
+ self.invitation_token = nil
40
+ self.invitation_accepted_at = Time.now.utc if respond_to? :"invitation_accepted_at="
41
+ self.save(:validate => false)
42
+ end
38
43
  end
39
44
  end
40
45
 
@@ -169,6 +174,16 @@ module Devise
169
174
  def invitation_token
170
175
  generate_token(:invitation_token)
171
176
  end
177
+
178
+ # Callback convenience methods
179
+ def before_invitation_accepted(*args, &blk)
180
+ set_callback(:invitation_accepted, :before, *args, &blk)
181
+ end
182
+
183
+ def after_invitation_accepted(*args, &blk)
184
+ set_callback(:invitation_accepted, :after, *args, &blk)
185
+ end
186
+
172
187
 
173
188
  Devise::Models.config(self, :invite_for)
174
189
  Devise::Models.config(self, :validate_on_invite)
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '0.5.7'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 7
10
- version: 0.5.7
8
+ - 6
9
+ - 0
10
+ version: 0.6.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-11-09 00:00:00 Z
18
+ date: 2011-11-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler
@@ -62,14 +62,21 @@ dependencies:
62
62
  requirement: &id003 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
- - - ~>
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- hash: 5
67
+ hash: 11
68
68
  segments:
69
69
  - 1
70
70
  - 4
71
+ - 6
72
+ version: 1.4.6
73
+ - - <
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
71
77
  - 1
72
- version: 1.4.1
78
+ - 6
79
+ version: "1.6"
73
80
  type: :runtime
74
81
  version_requirements: *id003
75
82
  description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation by setting a password.