public
Homepage: http://mutuallyhuman.com
Clone URL: git://github.com/mvanholstyn/mhs_authentication_system.git
Click here to lend your support to: mhs_authentication_system and make a donation at www.pledgie.com !
Renamed group to role
mvanholstyn (author)
Sun Jun 01 21:25:31 -0700 2008
commit  eefe12793606f7acb0b0a03304f6590b2cc0bb01
tree    52bca1a1154af5d065a78878d4fef1ff66c116be
parent  dc1464a5d6d9a3d5c2f93d273196842bfd0c5dd2
0
...
6
7
8
9
 
10
11
 
12
13
14
...
20
21
22
23
24
 
25
26
27
...
6
7
8
 
9
10
 
11
12
13
14
...
20
21
22
 
 
23
24
25
26
0
@@ -6,9 +6,9 @@ Controller
0
  ? Update how restrict_to works so that it can be ignored in subclasses
0
 
0
 Model
0
- ? Allow custom validation msg for group and priv validations
0
+ ? Allow custom validation msg for role and priv validations
0
  ? allow configuration of password_hash, and salt column names
0
- ! Revisit mixin for group/priv/group_priv/forgot_pass/forgot_pass_mailer
0
+ ! Revisit mixin for role/priv/role_priv/forgot_pass/forgot_pass_mailer
0
 
0
 Ideas
0
  * Signup hooks and options
0
@@ -20,8 +20,7 @@ Ideas
0
  * Preferences system
0
  ? view helpers (link_to, form_for, etc...)
0
  ? Syntax for asking for permission a & b (not just or)
0
- ? Users can belong to many groups
0
- ? Rename Group to Role
0
+ ? Users can belong to many roles
0
  ? can_xxx? helpers for privileges
0
 
0
 Object level privileges
...
9
10
11
12
13
14
15
 
 
 
 
16
...
9
10
11
 
 
 
 
12
13
14
15
16
0
@@ -9,8 +9,8 @@ Example:
0
         Controller: app/controller/users_controller.rb
0
         View: app/view/users/login.erb
0
         Migration: db/migrate/XXX_add_mhs_authentication_system.rb
0
- Fixtures: test/fixtures/privileges.yml
0
- test/fixtures/groups.yml
0
- test/fixtures/groups_privileges.yml
0
- test/fixtures/users.yml
0
+ Fixtures: spec/fixtures/privileges.yml
0
+ spec/fixtures/roles.yml
0
+ spec/fixtures/privileges_roles.yml
0
+ spec/fixtures/users.yml
0
 
...
19
20
21
22
23
 
 
24
25
26
...
19
20
21
 
 
22
23
24
25
26
0
@@ -19,8 +19,8 @@ class MhsAuthenticationSystemGenerator < Rails::Generator::Base
0
       m.template 'app/views/users/profile.html.erb', File.join( *%W{ app views users profile.html.erb } )
0
       m.template 'app/views/users/reminder.html.erb', File.join( *%W{ app views users reminder.html.erb } )
0
       m.template 'app/views/users/signup.html.erb', File.join( *%W{ app views users signup.html.erb } )
0
- m.template 'spec/fixtures/groups.yml', File.join( *%w{ spec fixtures groups.yml } )
0
- m.template 'spec/fixtures/groups_privileges.yml', File.join( *%w{ spec fixtures groups_privileges.yml } )
0
+ m.template 'spec/fixtures/roles.yml', File.join( *%w{ spec fixtures roles.yml } )
0
+ m.template 'spec/fixtures/privileges_roles.yml', File.join( *%w{ spec fixtures privileges_roles.yml } )
0
       m.template 'spec/fixtures/privileges.yml', File.join( *%w{ spec fixtures privileges.yml } )
0
       m.template 'spec/fixtures/users.yml', File.join( *%w{ spec fixtures users.yml } )
0
       m.migration_template 'db/migrate/migration.rb', File.join( *%w{ db migrate } ), :migration_file_name => "add_mhs_authentication_system"
...
1
2
3
 
4
5
6
...
8
9
10
11
12
 
 
13
14
15
16
 
 
17
18
19
20
21
22
 
23
24
25
26
27
 
28
29
30
...
36
37
38
39
 
40
41
 
42
43
44
...
1
2
 
3
4
5
6
...
8
9
10
 
 
11
12
13
14
 
 
15
16
17
18
19
20
21
 
22
23
24
25
26
 
27
28
29
30
...
36
37
38
 
39
40
 
41
42
43
44
0
@@ -1,6 +1,6 @@
0
 class AddMhsAuthenticationSystem < ActiveRecord::Migration
0
   def self.up
0
- create_table :groups do |t|
0
+ create_table :roles do |t|
0
       t.string :name
0
     end
0
 
0
@@ -8,23 +8,23 @@ class AddMhsAuthenticationSystem < ActiveRecord::Migration
0
       t.string :name
0
     end
0
 
0
- create_table :groups_privileges, :id => false do |t|
0
- t.integer :group_id
0
+ create_table :privileges_roles, :id => false do |t|
0
+ t.integer :role_id
0
       t.integer :privilege_id
0
     end
0
- add_index :groups_privileges, :group_id
0
- add_index :groups_privileges, :privilege_id
0
+ add_index :privileges_roles, :role_id
0
+ add_index :privileges_roles, :privilege_id
0
 
0
     create_table :users do |t|
0
       t.string :password_hash
0
       t.string :salt
0
       t.string :email_address
0
- t.integer :group_id
0
+ t.integer :role_id
0
       t.boolean :active
0
       t.string :remember_me_token
0
       t.datetime :remember_me_token_expires_at
0
     end
0
- add_index :users, :group_id
0
+ add_index :users, :role_id
0
     
0
     create_table :user_reminders do |t|
0
       t.integer :user_id
0
@@ -36,9 +36,9 @@ class AddMhsAuthenticationSystem < ActiveRecord::Migration
0
 
0
   def self.down
0
     drop_table :users
0
- drop_table :groups_privileges
0
+ drop_table :privileges_roles
0
     drop_table :privileges
0
- drop_table :groups
0
+ drop_table :roles
0
     drop_table :user_reminders
0
   end
0
 end
...
3
4
5
6
 
7
8
...
3
4
5
 
6
7
8
0
@@ -3,5 +3,5 @@ admin:
0
   email_address: admin@example.com
0
   salt: 29c4e39ef3ef59e9f71c612e6456675c0f21727f
0
   password_hash: <%%= User.hash_password 'password', '29c4e39ef3ef59e9f71c612e6456675c0f21727f' %>
0
- group_id: 1
0
+ role_id: 1
0
   active: true
0
\ No newline at end of file
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@ dir = File.join( File.dirname( __FILE__), 'lib')
0
 require File.join(dir, 'model')
0
 require File.join(dir, 'controller')
0
 require File.join(dir, 'login_controller')
0
-require File.join(dir, 'group_model')
0
+require File.join(dir, 'role_model')
0
 require File.join(dir, 'privilege_model')
0
 require File.join(dir, 'user_reminder_model')
0
 require File.join(dir, 'user_reminder_mailer_model')
...
109
110
111
112
 
113
114
 
115
116
117
...
109
110
111
 
112
113
 
114
115
116
117
0
@@ -109,9 +109,9 @@ module Mhs
0
         
0
         def find_and_set_current_user
0
           if session[:current_user_id]
0
- set_current_user self.class.login_model.find(session[:current_user_id], :include => {:group => :privileges })
0
+ set_current_user self.class.login_model.find(session[:current_user_id], :include => {:role => :privileges })
0
           elsif cookies[:remember_me_token]
0
- model = self.class.login_model.find(:first, :conditions => ["remember_me_token = ? AND remember_me_token_expires_at >= ?", cookies[:remember_me_token], Time.now], :include => {:group => :privileges })
0
+ model = self.class.login_model.find(:first, :conditions => ["remember_me_token = ? AND remember_me_token_expires_at >= ?", cookies[:remember_me_token], Time.now], :include => {:role => :privileges })
0
             if model
0
               model.remember_me!
0
               cookies[:remember_me_token] = { :value => model.remember_me_token , :expires => model.remember_me_token_expires_at }
...
9
10
11
12
 
13
14
15
...
21
22
23
24
 
25
26
27
...
38
39
40
41
 
42
43
44
45
 
46
47
 
48
49
50
...
61
62
63
64
 
65
66
67
 
 
68
69
70
...
103
104
105
106
 
107
108
109
...
159
160
161
162
 
163
164
 
165
166
167
...
9
10
11
 
12
13
14
15
...
21
22
23
 
24
25
26
27
...
38
39
40
 
41
42
43
44
 
45
46
 
47
48
49
50
...
61
62
63
 
64
65
 
 
66
67
68
69
70
...
103
104
105
 
106
107
108
109
...
159
160
161
 
162
163
 
164
165
166
167
0
@@ -9,7 +9,7 @@ module Mhs
0
       # These methods are added to ActiveRecord::Base
0
       module ClassMethods
0
         # Sets up this model as a login model. The following thigs are done:
0
- # * belongs_to :group
0
+ # * belongs_to :role
0
         # * validates_presence_of :email_address
0
         # * validates_uniqueness_of :email_address
0
         # * sets up validation to check that password and password_confirmation
0
@@ -21,7 +21,7 @@ module Mhs
0
         # * Adds methods from Mhs::AuthenticationSystem::Model::SingletonMethods
0
         #
0
         # Valid options:
0
- # - :group_validation - Error message used when the group_id is blank.
0
+ # - :role_validation - Error message used when the role_id is blank.
0
         # If this check is not desired, set this to false.
0
         # Default: "can't be blank"
0
         # - :password_validation - Error message used when the passwords do not match.
0
@@ -38,13 +38,13 @@ module Mhs
0
           include Mhs::AuthenticationSystem::Model::InstanceMethods
0
 
0
           self.mhs_authentication_system_options = {
0
- :group_validation => {},
0
+ :role_validation => {},
0
             :email_address_validation => {},
0
             :email_address_unique_validation => {},
0
             :password_validation => "must match"
0
- }.merge(options.except(:group_validation, :email_address_validation, :email_address_unique_validation))
0
+ }.merge(options.except(:role_validation, :email_address_validation, :email_address_unique_validation))
0
           
0
- options.slice(:group_validation, :email_address_validation, :email_address_unique_validation).each do |key, value|
0
+ options.slice(:role_validation, :email_address_validation, :email_address_unique_validation).each do |key, value|
0
             if value.is_a?(String)
0
               self.mhs_authentication_system_options[key].merge(:message => value)
0
             elsif value.is_a?(Hash)
0
@@ -61,10 +61,10 @@ module Mhs
0
             Digest::SHA1.hexdigest("--#{salt}--#{password}--")
0
           end
0
 
0
- belongs_to :group
0
+ belongs_to :role
0
 
0
- if options = mhs_authentication_system_options[:group_validation]
0
- validates_presence_of :group_id, options
0
+ if options = mhs_authentication_system_options[:role_validation]
0
+ validates_presence_of :role_id, options
0
           end
0
 
0
           if options = mhs_authentication_system_options[:email_address_validation]
0
@@ -103,7 +103,7 @@ module Mhs
0
         # Attempts to find a user by the passed in attributes. The param :password will
0
         # be removed and will be checked against the password of the user found (if any).
0
         def login(params)
0
- if not params.blank? and user = self.find_by_email_address(params[:email_address], :include => {:group => :privileges})
0
+ if not params.blank? and user = self.find_by_email_address(params[:email_address], :include => {:role => :privileges})
0
             self.hash_password(params[:password], user.salt) == user.password_hash ? user : nil
0
           end
0
         end
0
@@ -159,9 +159,9 @@ module Mhs
0
         # - :match_all - If set to true, returns true if this user has ALL of the
0
         # passed in privileges. Default: false
0
         def has_privilege?(*requested_privileges)
0
- return false unless group
0
+ return false unless role
0
           options = requested_privileges.last.is_a?(Hash) ? requested_privileges.pop : {}
0
- matched_privileges = requested_privileges.map(&:to_s) & group.privileges.map(&:name)
0
+ matched_privileges = requested_privileges.map(&:to_s) & role.privileges.map(&:name)
0
           options[:match_all] ? matched_privileges.size == requested_privileges.size : !matched_privileges.empty?
0
         end
0
       end
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ if( Privilege rescue true )
0
 end
0
 
0
 Privilege.class_eval do
0
- has_and_belongs_to_many :groups unless Group.reflect_on_association :groups
0
+ has_and_belongs_to_many :roles unless Role.reflect_on_association :roles
0
   
0
   validates_presence_of :name
0
 end
...
26
27
28
29
30
 
 
31
32
33
...
65
66
67
68
69
 
 
70
71
72
...
26
27
28
 
 
29
30
31
32
33
...
65
66
67
 
 
68
69
70
71
72
0
@@ -26,8 +26,8 @@ end
0
 
0
 
0
 describe DefaultActiveRecordModel, "instance does not respond to methods added by Mhs::AuthenticationSystem::Model::InstanceMethods" do
0
- it "does not respond to group=" do
0
- DefaultActiveRecordModel.new.should_not respond_to(:group=)
0
+ it "does not respond to role=" do
0
+ DefaultActiveRecordModel.new.should_not respond_to(:role=)
0
   end
0
 
0
   it "does not respond to password" do
0
@@ -65,8 +65,8 @@ describe DefaultActiveRecordModel, "does not respond to methods added by databas
0
     DefaultActiveRecordModel.new.should_not respond_to(:password_hash)
0
   end
0
   
0
- it "does not respond to group_id" do
0
- DefaultActiveRecordModel.new.should_not respond_to(:group_id)
0
+ it "does not respond to role_id" do
0
+ DefaultActiveRecordModel.new.should_not respond_to(:role_id)
0
   end
0
   
0
   it "does not respond to email_address" do
...
26
27
28
29
30
 
 
31
32
33
...
65
66
67
68
69
 
 
70
71
72
...
95
96
97
98
 
99
100
101
 
102
103
104
...
108
109
110
111
 
112
113
114
...
222
223
224
225
 
226
227
228
229
 
 
230
231
232
 
233
234
235
...
26
27
28
 
 
29
30
31
32
33
...
65
66
67
 
 
68
69
70
71
72
...
95
96
97
 
98
99
100
 
101
102
103
104
...
108
109
110
 
111
112
113
114
...
222
223
224
 
225
226
227
 
 
228
229
230
231
 
232
233
234
235
0
@@ -26,8 +26,8 @@ end
0
 
0
 
0
 describe MhsAuthenticationSystemModel, "instance responds to methods added by Mhs::AuthenticationSystem::Model::InstanceMethods" do
0
- it "responds to group=" do
0
- MhsAuthenticationSystemModel.new.should respond_to(:group=)
0
+ it "responds to role=" do
0
+ MhsAuthenticationSystemModel.new.should respond_to(:role=)
0
   end
0
 
0
   it "responds to password" do
0
@@ -65,8 +65,8 @@ describe MhsAuthenticationSystemModel, "responds to methods added by database sc
0
     MhsAuthenticationSystemModel.new.should respond_to(:password_hash)
0
   end
0
   
0
- it "responds to group_id" do
0
- MhsAuthenticationSystemModel.new.should respond_to(:group_id)
0
+ it "responds to role_id" do
0
+ MhsAuthenticationSystemModel.new.should respond_to(:role_id)
0
   end
0
   
0
   it "responds to email_address" do
0
@@ -95,10 +95,10 @@ describe MhsAuthenticationSystemModel, "acts_as_login_model" do
0
 end
0
 
0
 describe MhsAuthenticationSystemModel, "validations" do
0
- it "validates the presences of a group id" do
0
+ it "validates the presences of a role id" do
0
     model = MhsAuthenticationSystemModel.new
0
     model.should_not be_valid
0
- model.errors.on(:group_id).should == "can't be blank"
0
+ model.errors.on(:role_id).should == "can't be blank"
0
   end
0
   
0
   it "validates the presences of a email address" do
0
@@ -108,7 +108,7 @@ describe MhsAuthenticationSystemModel, "validations" do
0
   end
0
   
0
   it "validates the uniqueness of a email address" do
0
- saved_model = MhsAuthenticationSystemModel.create! :email_address => "user@example.com", :group_id => 1
0
+ saved_model = MhsAuthenticationSystemModel.create! :email_address => "user@example.com", :role_id => 1
0
     model = MhsAuthenticationSystemModel.new :email_address => "user@example.com"
0
     model.should_not be_valid
0
     model.errors.on(:email_address).should == "has already been taken"
0
@@ -222,14 +222,14 @@ end
0
 
0
 describe MhsAuthenticationSystemModel, "has_privilege?" do
0
   before(:each) do
0
- group = Group.create! :name => "admin"
0
+ role = Role.create! :name => "admin"
0
     admin_privilege = Privilege.create! :name => "admin"
0
     super_admin_privilege = Privilege.create! :name => "super_admin"
0
- group.privileges << admin_privilege << super_admin_privilege
0
- @model = MhsAuthenticationSystemModel.new :group => group
0
+ role.privileges << admin_privilege << super_admin_privilege
0
+ @model = MhsAuthenticationSystemModel.new :role => role
0
   end
0
 
0
- it "returns false if user does not have a group" do
0
+ it "returns false if user does not have a role" do
0
     MhsAuthenticationSystemModel.new.has_privilege?(:admin).should be_false
0
   end
0
 
...
35
36
37
38
 
39
40
41
42
43
44
 
45
46
47
...
49
50
51
52
53
 
 
54
55
56
57
58
59
60
 
61
62
63
...
35
36
37
 
38
39
40
41
42
43
 
44
45
46
47
...
49
50
51
 
 
52
53
54
55
56
57
58
59
 
60
61
62
63
0
@@ -35,13 +35,13 @@ ActiveRecord::Schema.suppress_messages do
0
       t.column :password_hash, :string
0
       t.column :salt, :string
0
       t.column :email_address, :string
0
- t.column :group_id, :integer
0
+ t.column :role_id, :integer
0
       t.column :active, :boolean
0
       t.column :remember_me_token, :string
0
       t.column :remember_me_token_expires_at, :datetime
0
     end
0
     
0
- create_table :groups, :force => true do |t|
0
+ create_table :roles, :force => true do |t|
0
       t.column :name, :string
0
     end
0
     
0
@@ -49,15 +49,15 @@ ActiveRecord::Schema.suppress_messages do
0
       t.column :name, :string
0
     end
0
     
0
- create_table :groups_privileges, :force => true do |t|
0
- t.column :group_id, :integer
0
+ create_table :privileges_roles, :force => true do |t|
0
+ t.column :role_id, :integer
0
       t.column :privilege_id, :integer
0
     end
0
     #
0
     # create_table :users, :force => true do |t|
0
     # t.column :username, :string
0
     # t.column :password_hash, :string
0
- # t.column :group_id, :integer
0
+ # t.column :role_id, :integer
0
     # t.column :email_address, :string
0
     # t.column :active, :boolean
0
     # end

Comments

    No one has commented yet.