devise_invitable 0.4.rc5 → 0.4.0

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.

data/README.rdoc CHANGED
@@ -104,6 +104,18 @@ To send an invitation to a user, use the <tt>invite!</tt> class method. <tt>:ema
104
104
  User.invite!(:email => "new_user@example.com", :name => "John Doe")
105
105
  # => an invitation email will be sent to new_user@example.com
106
106
 
107
+ If you want to create the invitation but not send it, you can set <tt>skip_invitation</tt> to true.
108
+
109
+ User.invite!(:email => "new_user@example.com", :name => "John Doe") do |u|
110
+ u.skip_invitation = true
111
+ end
112
+ # => the record will be created, but the invitation email will not be sent
113
+
114
+ You can add :skip_invitation to attributes hash if skip_invitation is added to attr_accessible.
115
+
116
+ User.invite!(:email => "new_user@example.com", :name => "John Doe", :skip_invitation => true)
117
+ # => the record will be created, but the invitation email will not be sent
118
+
107
119
  === Accept an invitation
108
120
 
109
121
  To accept an invitation with a token use the <tt>accept_invitation!</tt> class method. <tt>:invitation_token</tt> must be present in the parameters hash. You can also include other attributes in the hash.
@@ -17,10 +17,6 @@ class Devise::InvitationsController < ApplicationController
17
17
  self.resource = resource_class.invite!(params[resource_name], current_inviter)
18
18
 
19
19
  if resource.errors.empty?
20
- if resource_class.invitation_limit.present? && current_inviter
21
- current_inviter.invitation_limit ||= resource_class.invitation_limit
22
- current_inviter.decrement!(:invitation_limit)
23
- end
24
20
  set_flash_message :notice, :send_instructions, :email => self.resource.email
25
21
  redirect_to after_sign_in_path_for(resource_name)
26
22
  else
@@ -21,6 +21,8 @@ module Devise
21
21
  module Invitable
22
22
  extend ActiveSupport::Concern
23
23
 
24
+ attr_accessor :skip_invitation
25
+
24
26
  included do
25
27
  belongs_to :invited_by, :polymorphic => true
26
28
  end
@@ -59,7 +61,10 @@ module Devise
59
61
  self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
60
62
  generate_invitation_token if self.invitation_token.nil?
61
63
  self.invitation_sent_at = Time.now.utc
62
- save(:validate => self.class.validate_on_invite) && !!deliver_invitation
64
+ if save(:validate => self.class.validate_on_invite)
65
+ self.invited_by.decrement_invitation_limit! if self.invited_by
66
+ !!deliver_invitation unless @skip_invitation
67
+ end
63
68
  end
64
69
  end
65
70
 
@@ -76,6 +81,12 @@ module Devise
76
81
  end
77
82
 
78
83
  protected
84
+ def decrement_invitation_limit!
85
+ if self.class.invitation_limit.present?
86
+ self.invitation_limit ||= self.class.invitation_limit
87
+ self.decrement!(:invitation_limit)
88
+ end
89
+ end
79
90
 
80
91
  # Overriding the method in Devise's :validatable module so password is not required on inviting
81
92
  def password_required?
@@ -127,7 +138,7 @@ module Devise
127
138
  # user and send invitation to it. If user is found, returns the user with an
128
139
  # email already exists error.
129
140
  # Attributes must contain the user email, other attributes will be set in the record
130
- def invite!(attributes={}, invited_by=nil)
141
+ def invite!(attributes={}, invited_by=nil, &block)
131
142
  invitable = find_or_initialize_with_error_by(invite_key, attributes.delete(invite_key))
132
143
  invitable.attributes = attributes
133
144
  invitable.invited_by = invited_by
@@ -138,7 +149,10 @@ module Devise
138
149
  invitable.errors.add(invite_key, :taken) unless invitable.invited?
139
150
  end
140
151
 
141
- invitable.invite! if invitable.errors.empty?
152
+ if invitable.errors.empty?
153
+ yield invitable if block_given?
154
+ invitable.invite!
155
+ end
142
156
  invitable
143
157
  end
144
158
 
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '0.4.rc5'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424207
5
- prerelease: 4
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - rc
10
- - 5
11
- version: 0.4.rc5
9
+ - 0
10
+ version: 0.4.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - Sergio Cambra
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-03-21 00:00:00 +01:00
18
+ date: 2011-03-31 00:00:00 +02:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -59,13 +58,12 @@ dependencies:
59
58
  requirements:
60
59
  - - ~>
61
60
  - !ruby/object:Gem::Version
62
- hash: 15424225
61
+ hash: 31
63
62
  segments:
64
63
  - 1
65
64
  - 2
66
- - rc
67
- - 2
68
- version: 1.2.rc2
65
+ - 0
66
+ version: 1.2.0
69
67
  type: :runtime
70
68
  version_requirements: *id003
71
69
  description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation by setting a password.
@@ -82,7 +80,6 @@ files:
82
80
  - app/views/devise/invitations/edit.html.erb
83
81
  - app/views/devise/invitations/new.html.erb
84
82
  - app/views/devise/mailer/invitation_instructions.html.erb
85
- - app/views/devise/mailer/invitation.html.erb
86
83
  - config/locales/en.yml
87
84
  - lib/devise_invitable.rb
88
85
  - lib/devise_invitable/mailer.rb
@@ -1,8 +0,0 @@
1
- <p>Hello <%= @resource.email %>!</p>
2
-
3
- <p>Someone has invited you to <%= root_url %>, you can accept it through the link below.</p>
4
-
5
- <p><%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %></p>
6
-
7
- <p>If you don't want to accept the invitation, please ignore this email.<br />
8
- Your account won't be created until you access the link above and set your password.</p>