acts_as_privilege 2.0.0 → 2.0.1
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/README.md +83 -0
- data/VERSION.yml +1 -1
- data/acts_as_privilege.gemspec +2 -2
- metadata +38 -32
- data/README.rdoc +0 -63
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Acts as privilege
|
2
|
+
=================
|
3
|
+
|
4
|
+
Acts as privilege is a plugin for Ruby on Rails that provides the capabilities
|
5
|
+
to restrict controller actions to privileged resources.
|
6
|
+
|
7
|
+
This ACL-based security model is designed as a role-based access control, where
|
8
|
+
each role can be a group of users.
|
9
|
+
|
10
|
+
Philosophy
|
11
|
+
----------
|
12
|
+
|
13
|
+
General library that does only one thing, without any feature.
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
Include the gem in your `Gemfile`:
|
19
|
+
|
20
|
+
gem 'acts_as_privilege'
|
21
|
+
|
22
|
+
And run the `bundle` command. Or as a plugin:
|
23
|
+
|
24
|
+
rails plugin install git://github.com/cyril/acts_as_privilege.git
|
25
|
+
|
26
|
+
Then, generate files and apply the migration:
|
27
|
+
|
28
|
+
rails generate privileges model
|
29
|
+
rake db:migrate
|
30
|
+
|
31
|
+
At this point, `Privilege` model can be populated with:
|
32
|
+
|
33
|
+
``` ruby
|
34
|
+
rest_actions = %w(index show new create edit update destroy)
|
35
|
+
controllers = {
|
36
|
+
groups: rest_actions,
|
37
|
+
users: rest_actions,
|
38
|
+
articles: rest_actions,
|
39
|
+
comments: rest_actions }
|
40
|
+
|
41
|
+
Privilege.transaction do
|
42
|
+
controllers.each_pair do |controller, actions|
|
43
|
+
actions.each do |action|
|
44
|
+
Privilege.create! route: [controller, action].join('#')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Example
|
51
|
+
-------
|
52
|
+
|
53
|
+
First, let's run commands:
|
54
|
+
|
55
|
+
rails generate privileges group
|
56
|
+
rake db:migrate
|
57
|
+
|
58
|
+
Second, let's add this in `Group` model:
|
59
|
+
|
60
|
+
``` ruby
|
61
|
+
# app/models/group.rb
|
62
|
+
class Group < ActiveRecord::Base
|
63
|
+
acts_as_privilege
|
64
|
+
|
65
|
+
has_many :users
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
Now, check the current user capability to destroy articles:
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
current_user.group.privilege?('articles#destroy') # => false
|
73
|
+
```
|
74
|
+
|
75
|
+
And add a form helper that generates the field to manage group privileges:
|
76
|
+
|
77
|
+
``` ruby
|
78
|
+
form_for @group do |f|
|
79
|
+
privileges_field f
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
Copyright (c) 2009-2011 Cyril Wack, released under the MIT license
|
data/VERSION.yml
CHANGED
data/acts_as_privilege.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "acts_as_privilege"
|
3
|
-
s.version =
|
3
|
+
s.version = YAML.load_file("VERSION.yml").values.join('.')
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["Cyril Wack"]
|
6
|
-
s.email = ["cyril
|
6
|
+
s.email = ["contact@cyril.io"]
|
7
7
|
s.homepage = "http://github.com/cyril/acts_as_privilege"
|
8
8
|
s.summary = %q{Simple privilege solution for Rails.}
|
9
9
|
s.description = %q{Simple Rails plugin to restrict system access to authorized users.}
|
metadata
CHANGED
@@ -1,39 +1,43 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_privilege
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 2.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Cyril Wack
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2011-08-29 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: railties
|
16
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
19
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
21
23
|
version: 3.0.0
|
22
24
|
type: :runtime
|
23
|
-
|
24
|
-
version_requirements: *2153144220
|
25
|
+
version_requirements: *id001
|
25
26
|
description: Simple Rails plugin to restrict system access to authorized users.
|
26
|
-
email:
|
27
|
-
- cyril
|
27
|
+
email:
|
28
|
+
- contact@cyril.io
|
28
29
|
executables: []
|
30
|
+
|
29
31
|
extensions: []
|
32
|
+
|
30
33
|
extra_rdoc_files: []
|
31
|
-
|
34
|
+
|
35
|
+
files:
|
32
36
|
- .gitignore
|
33
37
|
- .rvmrc
|
34
38
|
- Gemfile
|
35
39
|
- MIT-LICENSE
|
36
|
-
- README.
|
40
|
+
- README.md
|
37
41
|
- Rakefile
|
38
42
|
- VERSION.yml
|
39
43
|
- acts_as_privilege.gemspec
|
@@ -53,28 +57,30 @@ files:
|
|
53
57
|
- test/test_helper.rb
|
54
58
|
homepage: http://github.com/cyril/acts_as_privilege
|
55
59
|
licenses: []
|
60
|
+
|
56
61
|
post_install_message:
|
57
62
|
rdoc_options: []
|
58
|
-
|
63
|
+
|
64
|
+
require_paths:
|
59
65
|
- lib
|
60
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
67
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version:
|
66
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
73
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version:
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
72
78
|
requirements: []
|
79
|
+
|
73
80
|
rubyforge_project: acts_as_privilege
|
74
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.8.9
|
75
82
|
signing_key:
|
76
83
|
specification_version: 3
|
77
84
|
summary: Simple privilege solution for Rails.
|
78
|
-
test_files:
|
79
|
-
|
80
|
-
- test/test_helper.rb
|
85
|
+
test_files: []
|
86
|
+
|
data/README.rdoc
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
= Acts as privilege
|
2
|
-
|
3
|
-
Acts as privilege is a plugin for Ruby on Rails that provides the capabilities
|
4
|
-
to restrict controller actions to privileged resources.
|
5
|
-
|
6
|
-
This ACL-based security model is designed as a role-based access control, where
|
7
|
-
each role can be a group of users.
|
8
|
-
|
9
|
-
== Philosophy
|
10
|
-
|
11
|
-
General library that does only one thing, without any feature.
|
12
|
-
|
13
|
-
== Installation
|
14
|
-
|
15
|
-
Include the gem in your <tt>Gemfile</tt>:
|
16
|
-
|
17
|
-
gem 'acts_as_privilege'
|
18
|
-
|
19
|
-
And run the +bundle+ command. Or as a plugin:
|
20
|
-
|
21
|
-
rails plugin install git://github.com/cyril/acts_as_privilege.git
|
22
|
-
|
23
|
-
Then, generate files and apply the migration:
|
24
|
-
|
25
|
-
rails generate privileges model
|
26
|
-
rake db:migrate
|
27
|
-
|
28
|
-
At this point, <tt>Privilege</tt> model can be populated with:
|
29
|
-
|
30
|
-
rest_actions = %w(index show new create edit update destroy)
|
31
|
-
controllers = {
|
32
|
-
:groups => rest_actions,
|
33
|
-
:users => rest_actions,
|
34
|
-
:articles => rest_actions,
|
35
|
-
:comments => rest_actions }
|
36
|
-
|
37
|
-
Privilege.transaction do
|
38
|
-
controllers.each_pair do |controller, actions|
|
39
|
-
actions.each do |action|
|
40
|
-
Privilege.create! :route => [controller, action].join('#')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
== Example
|
46
|
-
|
47
|
-
rails generate privileges group
|
48
|
-
rake db:migrate
|
49
|
-
|
50
|
-
# app/models/group.rb
|
51
|
-
class Group < ActiveRecord::Base
|
52
|
-
acts_as_privilege
|
53
|
-
|
54
|
-
has_many :users
|
55
|
-
end
|
56
|
-
|
57
|
-
# Check the current user capability to destroy articles:
|
58
|
-
current_user.group.privilege?('articles#destroy') # => false
|
59
|
-
|
60
|
-
# Form helper that generates field to manage group privileges:
|
61
|
-
<%= privileges_field f %>
|
62
|
-
|
63
|
-
Copyright (c) 2009-2011 Cyril Wack, released under the MIT license
|