Adman65-AccessControl 0.2.1 → 0.2.2
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.
- data/AccessControl.gemspec +6 -6
- data/README.markdown +23 -28
- data/VERSION +1 -1
- data/generators/access_control/access_control_generator.rb +3 -2
- data/generators/access_control/templates/migrate/create_access_control_models.rb +1 -0
- data/lib/access_control/common_methods.rb +1 -6
- data/lib/access_control/role_extension.rb +2 -5
- data/lib/access_control/user_extension.rb +7 -0
- metadata +4 -4
data/AccessControl.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{AccessControl}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Adam Hawkins"]
|
@@ -47,13 +47,13 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.rubygems_version = %q{1.3.4}
|
48
48
|
s.summary = %q{Simple role based authorization for rails}
|
49
49
|
s.test_files = [
|
50
|
-
"spec/
|
51
|
-
"spec/models/permission_spec.rb",
|
52
|
-
"spec/models/role_spec.rb",
|
53
|
-
"spec/spec_helper.rb",
|
50
|
+
"spec/spec_helper.rb",
|
54
51
|
"spec/support/access_control_user.rb",
|
55
52
|
"spec/support/authorizable.rb",
|
56
|
-
"spec/support/schema.rb"
|
53
|
+
"spec/support/schema.rb",
|
54
|
+
"spec/models/permission_spec.rb",
|
55
|
+
"spec/models/role_spec.rb",
|
56
|
+
"spec/access_controlled_user_spec.rb"
|
57
57
|
]
|
58
58
|
|
59
59
|
if s.respond_to? :specification_version then
|
data/README.markdown
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
AccessControl
|
2
2
|
=============
|
3
|
-
**Warning: this is a beta plugin!**
|
4
3
|
|
5
4
|
AccessControl is a user authorization plugin. It gives you a role based permission system without having to do any work. There are users and roles, each have permission.
|
6
5
|
A user can play any role and inherit permissions through that role. A user may also have individual permissions. For example, you can create a role to update
|
@@ -14,18 +13,19 @@ Features
|
|
14
13
|
* God permission
|
15
14
|
* Easy to use
|
16
15
|
|
17
|
-
|
18
16
|
Up and Running
|
19
17
|
================
|
20
18
|
|
21
19
|
Install
|
22
20
|
-------
|
23
21
|
|
24
|
-
First, prepare your application. AccessControl does not create user logins, it soley is a permission system.
|
22
|
+
First, prepare your application. AccessControl does not create user logins, it soley is a permission system. Your user model must be named User. AccessControl
|
25
23
|
also uses two other models: Permission & Role. Once your users can login and log out, you are ready to use AccessControl.
|
26
24
|
|
27
25
|
1. Install
|
28
|
-
./script/plugin install git://github.com/Adman65/AccessControl.git
|
26
|
+
(plugin) ./script/plugin install git://github.com/Adman65/AccessControl.git
|
27
|
+
(gem) sudo gem install Adman65-AccessControl
|
28
|
+
(gem) config.gem 'Adman65-AccessControl', :lib => 'access_control'
|
29
29
|
|
30
30
|
2. Prepare the database
|
31
31
|
./script/generate access_control models
|
@@ -64,7 +64,7 @@ Voilla, Adam can now post_news. But that's no good by itself. So now check agani
|
|
64
64
|
end
|
65
65
|
|
66
66
|
Your controllers are protected from people who can't post news. Now lets expand our permissions by adding a role:
|
67
|
-
editors = Role.create :name => "Editors", :description => "Manage content around the site."
|
67
|
+
editors = Role.create :name => "Editors", :description => "Manage content around the site." # Description is optional
|
68
68
|
# assuming we have these permissions in the system
|
69
69
|
editors.grant :manage_news
|
70
70
|
editors.grant :manage_categories
|
@@ -83,29 +83,24 @@ Man, Adam sure got a lot of responsibilities, hopefully you trust him :)
|
|
83
83
|
Using the language
|
84
84
|
==============
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
Utilties
|
105
|
-
===========
|
106
|
-
Sometimes you want to see all the permissions in your application:
|
107
|
-
rake access_control:permissions
|
108
|
-
|
86
|
+
Here are the methods available on User & Role objects:
|
87
|
+
Authorizable#authorize(permission)
|
88
|
+
Authorizable#grant(permission)
|
89
|
+
Authorizable#deauthorize(permission)
|
90
|
+
Authorizable#cannot?(permission)
|
91
|
+
Authorizable#god?
|
92
|
+
Authorizable#can_permission_name?
|
93
|
+
Authorizable#can_not_permission_name?
|
94
|
+
Authorizable#permissions
|
95
|
+
Authorizable#has_permission?(permission)
|
96
|
+
Authorizable#can?(permission)
|
97
|
+
|
98
|
+
User Methods:
|
99
|
+
User#plays?(role)
|
100
|
+
User#plays(role)
|
101
|
+
User#does_not_play?(role)
|
102
|
+
User#does_not_play(role)
|
103
|
+
User.roles (and all other has_and_belongs_to_many methods)
|
109
104
|
|
110
105
|
|
111
106
|
Copyright (c) 2009 Adam Hawkins, released under the MIT license
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -29,7 +29,7 @@ class AccessControlGenerator < Rails::Generator::NamedBase
|
|
29
29
|
|
30
30
|
m.migration_template File.join("migrate","create_access_control_models.rb"), File.join("db","migrate"), :migration_file_name => "GenerateAccessControlModels".underscore
|
31
31
|
when :permission
|
32
|
-
file_name = "
|
32
|
+
file_name = "create_multiple_permissions_#{@permission_names.join('_').underscore}" if args.size > 2
|
33
33
|
file_name = "create_permission_#{@permission_name}" if args.size.eql? 2
|
34
34
|
m.migration_template "migration:migration.rb", File.join("db","migrate"), :assigns => migration_options, :migration_file_name => file_name
|
35
35
|
end
|
@@ -40,7 +40,8 @@ class AccessControlGenerator < Rails::Generator::NamedBase
|
|
40
40
|
def migration_options
|
41
41
|
assigns = {}
|
42
42
|
assigns[:migration_action] = "add"
|
43
|
-
assigns[:class_name] = "
|
43
|
+
assigns[:class_name] = "create_multiple_permissions_#{@permission_names.join('_').underscore}".camelize if @permission_names
|
44
|
+
assigns[:class_name] = "create_multiple_permissions" if @permission_name
|
44
45
|
assigns[:table_name] = "permissions"
|
45
46
|
assigns[:attributes] = @permission_names.map {|name| Rails::Generator::GeneratedAttribute.new(name, "boolean")}
|
46
47
|
assigns
|
@@ -6,7 +6,7 @@ module AccessControl
|
|
6
6
|
include AccessControl::CommonMethods
|
7
7
|
include AccessControl::Language
|
8
8
|
|
9
|
-
has_and_belongs_to_many :users, :join_table => :user_roles
|
9
|
+
has_and_belongs_to_many :users, :join_table => :user_roles
|
10
10
|
has_one :permission, :as => :authorizable, :dependent => :destroy
|
11
11
|
|
12
12
|
alias :has_permission? :has_local_permission?
|
@@ -17,10 +17,7 @@ module AccessControl
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def permissions
|
20
|
-
|
21
|
-
return nil if set.nil?
|
22
|
-
return set.first if set.size.eql? 0
|
23
|
-
set
|
20
|
+
self.permission.set_permissions
|
24
21
|
end
|
25
22
|
|
26
23
|
end
|
@@ -32,6 +32,13 @@ module AccessControl
|
|
32
32
|
def does_not_play? role
|
33
33
|
!plays? role
|
34
34
|
end
|
35
|
+
|
36
|
+
def does_not_play role
|
37
|
+
role = role.to_s if role.is_a? Symbol
|
38
|
+
actual_role = Role.find_by_name(role.downcase)
|
39
|
+
raise "#{role} does not exist" if actual_role.nil?
|
40
|
+
roles.delete actual_role
|
41
|
+
end
|
35
42
|
|
36
43
|
def has_permission? perm
|
37
44
|
return true if has_local_permission? perm
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Adman65-AccessControl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hawkins
|
@@ -76,10 +76,10 @@ signing_key:
|
|
76
76
|
specification_version: 3
|
77
77
|
summary: Simple role based authorization for rails
|
78
78
|
test_files:
|
79
|
-
- spec/access_controlled_user_spec.rb
|
80
|
-
- spec/models/permission_spec.rb
|
81
|
-
- spec/models/role_spec.rb
|
82
79
|
- spec/spec_helper.rb
|
83
80
|
- spec/support/access_control_user.rb
|
84
81
|
- spec/support/authorizable.rb
|
85
82
|
- spec/support/schema.rb
|
83
|
+
- spec/models/permission_spec.rb
|
84
|
+
- spec/models/role_spec.rb
|
85
|
+
- spec/access_controlled_user_spec.rb
|