devise_invitable 0.4.rc3 → 0.4.rc4

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.

@@ -8,10 +8,23 @@ require 'devise_invitable/controllers/helpers'
8
8
  require 'devise_invitable/rails'
9
9
 
10
10
  module Devise
11
- # The period the generated invitation token is valid.
11
+ # Public: Validity period of the invitation token (default: 0). If
12
+ # invite_for is 0 or nil, the invitation will never expire.
13
+ # Set invite_for in the Devise configuration file (in config/initializers/devise.rb).
14
+ #
15
+ # config.invite_for = 2.weeks # => The invitation token will be valid 2 weeks
12
16
  mattr_accessor :invite_for
13
17
  @@invite_for = 0
14
18
 
19
+ # Public: Flag that force a record to be valid before being actually invited
20
+ # (default: false).
21
+ #
22
+ # Examples (in config/initializers/devise.rb)
23
+ #
24
+ # config.validate_on_invite = true
25
+ mattr_accessor :validate_on_invite
26
+ @@validate_on_invite = false
27
+
15
28
  # Public: number of invitations the user is allowed to send
16
29
  #
17
30
  # Examples (in config/initializers/devise.rb)
@@ -20,7 +33,11 @@ module Devise
20
33
  mattr_accessor :invitation_limit
21
34
  @@invitation_limit = nil
22
35
 
23
- # The key to be used to check existing users when sending an invitation
36
+ # Public: The key to be used to check existing users when sending an invitation
37
+ #
38
+ # Examples (in config/initializers/devise.rb)
39
+ #
40
+ # config.invite_key = :email
24
41
  mattr_accessor :invite_key
25
42
  @@invite_key = :email
26
43
  end
@@ -55,11 +55,11 @@ module Devise
55
55
  # Reset invitation token and send invitation again
56
56
  def invite!
57
57
  if new_record? || invited?
58
+ @skip_password = true
58
59
  self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
59
60
  generate_invitation_token if self.invitation_token.nil?
60
61
  self.invitation_sent_at = Time.now.utc
61
- save(:validate => false)
62
- ::Devise.mailer.invitation_instructions(self).deliver
62
+ save(:validate => self.class.validate_on_invite) && !!deliver_invitation
63
63
  end
64
64
  end
65
65
 
@@ -77,6 +77,16 @@ module Devise
77
77
 
78
78
  protected
79
79
 
80
+ # Overriding the method in Devise's :validatable module so password is not required on inviting
81
+ def password_required?
82
+ !@skip_password && super
83
+ end
84
+
85
+ # Deliver the invitation email
86
+ def deliver_invitation
87
+ ::Devise.mailer.invitation_instructions(self).deliver
88
+ end
89
+
80
90
  # Clear invitation token when reset password token is cleared too
81
91
  def clear_reset_password_token
82
92
  self.invitation_token = nil if invited?
@@ -153,6 +163,7 @@ module Devise
153
163
  end
154
164
 
155
165
  Devise::Models.config(self, :invite_for)
166
+ Devise::Models.config(self, :validate_on_invite)
156
167
  Devise::Models.config(self, :invitation_limit)
157
168
  Devise::Models.config(self, :invite_key)
158
169
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '0.4.rc3'
2
+ VERSION = '0.4.rc4'
3
3
  end
@@ -1,12 +1,12 @@
1
1
  class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  change_table :<%= table_name %> do |t|
4
- t.string :invitation_token, :limit => 60
5
- t.datetime :invitation_sent_at
6
- t.integer :invitation_limit
7
- t.integer :invited_by_id
8
- t.index :invitation_token # for invitable
9
- t.index :invited_by_id
4
+ t.string :invitation_token, :limit => 60
5
+ t.datetime :invitation_sent_at
6
+ t.integer :invitation_limit
7
+ t.references :invited_by, :polymorphic => true
8
+ t.index :invitation_token # for invitable
9
+ t.index :invited_by_id
10
10
  end
11
11
 
12
12
  # And allow null encrypted_password and password_salt:
@@ -17,9 +17,9 @@ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
17
17
  end
18
18
 
19
19
  def self.down
20
- remove_column :<%= table_name %>, :invited_by_id
21
- remove_column :<%= table_name %>, :invitation_limit
22
- remove_column :<%= table_name %>, :invitation_sent_at
23
- remove_column :<%= table_name %>, :invitation_token
20
+ change_table :<%= table_name %> do |t|
21
+ remove_references :invited_by, :polymorphic => true
22
+ remove :invitation_limit, :invitation_sent_at, :invitation_token
23
+ end
24
24
  end
25
25
  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
- hash: 15424195
4
+ hash: 15424205
5
5
  prerelease: 4
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - rc
10
- - 3
11
- version: 0.4.rc3
10
+ - 4
11
+ version: 0.4.rc4
12
12
  platform: ruby
13
13
  authors:
14
14
  - Sergio Cambra
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-23 00:00:00 +01:00
19
+ date: 2011-03-09 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency