acts_as_privilege 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +11 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +34 -19
- data/Rakefile +10 -10
- data/VERSION.yml +2 -2
- data/acts_as_privilege.gemspec +13 -27
- data/app/helpers/privileges_helper.rb +5 -0
- data/app/views/acts_as_privilege/_fieldset.html.erb +7 -0
- data/config/locales/en.yml +5 -0
- data/config/locales/fr.yml +5 -0
- data/config/locales/ja.yml +5 -0
- data/lib/acts_as_privilege.rb +16 -22
- data/lib/generators/privileges/USAGE +16 -0
- data/lib/generators/privileges/privileges_generator.rb +18 -0
- data/lib/generators/privileges/templates/create_privileges.rb +23 -0
- data/lib/generators/privileges/templates/privilege.rb +10 -0
- data/lib/generators/privileges/templates/privileges_helper.rb +5 -0
- data/test/privilege_test.rb +161 -0
- data/test/test_helper.rb +4 -0
- metadata +58 -84
- data/Manifest +0 -13
- data/generators/acts_as_privilege/USAGE +0 -17
- data/generators/acts_as_privilege/acts_as_privilege_generator.rb +0 -34
- data/generators/acts_as_privilege/templates/migration.rb +0 -28
- data/lib/ability.rb +0 -12
- data/lib/entity.rb +0 -11
- data/lib/privileges_helper.rb +0 -15
- data.tar.gz.sig +0 -2
- metadata.gz.sig +0 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm ruby-1.9.2@acts_as_privilege
|
data/Gemfile
ADDED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,48 +1,63 @@
|
|
1
1
|
= Acts as privilege
|
2
2
|
|
3
|
-
|
3
|
+
Acts as privilege is a plugin for Ruby on Rails that provides the capabilities
|
4
|
+
to restrict controller actions to privileged resources.
|
4
5
|
|
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.
|
6
8
|
|
7
|
-
|
9
|
+
== Philosophy
|
8
10
|
|
9
|
-
|
11
|
+
General library that does only one thing, without any feature.
|
10
12
|
|
11
|
-
|
13
|
+
== Installation
|
12
14
|
|
13
|
-
|
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
|
14
26
|
rake db:migrate
|
15
27
|
|
16
|
-
|
28
|
+
At this point, <tt>Privilege</tt> model can be populated with:
|
17
29
|
|
18
|
-
rest_actions = %w
|
30
|
+
rest_actions = %w(index show new create edit update destroy)
|
19
31
|
controllers = {
|
20
|
-
:groups
|
21
|
-
:users
|
32
|
+
:groups => rest_actions,
|
33
|
+
:users => rest_actions,
|
22
34
|
:articles => rest_actions,
|
23
35
|
:comments => rest_actions }
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
29
42
|
end
|
30
43
|
end
|
31
44
|
|
32
45
|
== Example
|
33
46
|
|
34
|
-
|
47
|
+
rails generate privileges group
|
35
48
|
rake db:migrate
|
36
49
|
|
50
|
+
# app/models/group.rb
|
37
51
|
class Group < ActiveRecord::Base
|
38
52
|
acts_as_privilege
|
53
|
+
|
39
54
|
has_many :users
|
40
55
|
end
|
41
56
|
|
42
57
|
# Check the current user capability to destroy articles:
|
43
|
-
current_user.group.
|
58
|
+
current_user.group.privilege?('articles#destroy') # => false
|
44
59
|
|
45
|
-
# Form helper that
|
46
|
-
<%= privileges_field
|
60
|
+
# Form helper that generates field to manage group privileges:
|
61
|
+
<%= privileges_field f %>
|
47
62
|
|
48
|
-
Copyright (c) 2009 Cyril Wack, released under the MIT license
|
63
|
+
Copyright (c) 2009-2011 Cyril Wack, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'echoe'
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
p.development_dependencies = []
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << 'lib'
|
8
|
+
t.libs << 'test'
|
9
|
+
t.test_files = FileList["test/**/*_{helper,test}.rb"]
|
12
10
|
end
|
11
|
+
|
12
|
+
task :default => :test
|
data/VERSION.yml
CHANGED
data/acts_as_privilege.gemspec
CHANGED
@@ -1,32 +1,18 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
1
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
6
|
-
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
2
|
+
s.name = "acts_as_privilege"
|
3
|
+
s.version = Psych.load_file("VERSION.yml").values.join('.')
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Cyril Wack"]
|
6
|
+
s.email = ["cyril@gosu.fr"]
|
7
|
+
s.homepage = "http://github.com/cyril/acts_as_privilege"
|
8
|
+
s.summary = %q{Simple privilege solution for Rails.}
|
11
9
|
s.description = %q{Simple Rails plugin to restrict system access to authorized users.}
|
12
|
-
s.email = %q{cyril.wack@gmail.com}
|
13
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/ability.rb", "lib/acts_as_privilege.rb", "lib/entity.rb", "lib/privileges_helper.rb"]
|
14
|
-
s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "VERSION.yml", "generators/acts_as_privilege/USAGE", "generators/acts_as_privilege/acts_as_privilege_generator.rb", "generators/acts_as_privilege/templates/migration.rb", "init.rb", "lib/ability.rb", "lib/acts_as_privilege.rb", "lib/entity.rb", "lib/privileges_helper.rb", "Manifest", "acts_as_privilege.gemspec"]
|
15
|
-
s.homepage = %q{http://github.com/cyril/acts_as_privilege}
|
16
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Acts_as_privilege", "--main", "README.rdoc"]
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
s.rubyforge_project = %q{acts_as_privilege}
|
19
|
-
s.rubygems_version = %q{1.3.6}
|
20
|
-
s.signing_key = %q{/Users/cyril/gem-private_key.pem}
|
21
|
-
s.summary = %q{Simple Rails plugin to restrict system access to authorized users.}
|
22
10
|
|
23
|
-
|
24
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
-
s.specification_version = 3
|
11
|
+
s.rubyforge_project = "acts_as_privilege"
|
26
12
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
s.add_runtime_dependency "railties", ">= 3.0.0"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_paths = ["lib"]
|
32
18
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= content_tag(:fieldset, :id => "#{f.object.class.name}_privileges") do %>
|
2
|
+
<%= content_tag(:legend, t('.legend')) %>
|
3
|
+
|
4
|
+
<%= label f.object.class.name, :privilege_ids, t('.privilege_ids') %><br />
|
5
|
+
<%= collection_select(f.object.class.name.tableize.singularize,
|
6
|
+
:privilege_ids, Privilege.all, :id, :route, {}, :multiple => true) %>
|
7
|
+
<% end %>
|
data/lib/acts_as_privilege.rb
CHANGED
@@ -1,31 +1,25 @@
|
|
1
|
-
require 'active_record/base'
|
2
|
-
|
3
1
|
module ActsAsPrivilege
|
4
|
-
def
|
5
|
-
|
2
|
+
def privilege?(route)
|
3
|
+
privileges.exists?(:route => route.to_s)
|
6
4
|
end
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def has_privilege?(controller, action)
|
7
|
+
ActiveSupport::Deprecation.warn 'has_privilege?(controller, action) ' +
|
8
|
+
'is deprecated and may be removed from future releases, ' +
|
9
|
+
'use privilege?(route) instead.'
|
11
10
|
|
12
|
-
|
13
|
-
include ActsAsPrivilege::InstanceMethods
|
14
|
-
EOV
|
15
|
-
end
|
11
|
+
privilege? [controller, action].join('#')
|
16
12
|
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
self.abilities.each do |ability|
|
21
|
-
if ability.name == action
|
22
|
-
return true if ability.entity.name == controller
|
23
|
-
end
|
24
|
-
end
|
25
|
-
false
|
26
|
-
end
|
14
|
+
def mass_assignment_authorizer
|
15
|
+
super + [:privilege_ids]
|
27
16
|
end
|
28
17
|
end
|
29
18
|
|
30
|
-
ActiveRecord::Base
|
31
|
-
|
19
|
+
class ActiveRecord::Base
|
20
|
+
def self.acts_as_privilege
|
21
|
+
has_and_belongs_to_many :privileges
|
22
|
+
|
23
|
+
include ActsAsPrivilege
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
Creates a Privilege model, and then links it with any other models that your
|
3
|
+
application might need.
|
4
|
+
|
5
|
+
Usage:
|
6
|
+
Pass the name of models that you want to apply privileges.
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
`rails generate privileges role`
|
10
|
+
|
11
|
+
Will expand roles with privileges. Then you can manage user roles and
|
12
|
+
attributed privileges for each one.
|
13
|
+
|
14
|
+
`rails generate privileges group user`
|
15
|
+
|
16
|
+
Same, with Group and User models.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class PrivilegesGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
argument :model_names, :type => :array
|
8
|
+
|
9
|
+
def self.next_migration_number(path)
|
10
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_model_file
|
14
|
+
template 'privilege.rb', 'app/models/privilege.rb'
|
15
|
+
template 'privileges_helper.rb', 'app/helpers/privileges_helper.rb'
|
16
|
+
migration_template 'create_privileges.rb', 'db/migrate/create_privileges.rb'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreatePrivileges < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :privileges do |t|
|
4
|
+
t.string :route, :limit => 255, :null => false
|
5
|
+
end
|
6
|
+
|
7
|
+
add_index :privileges, :route, {:unique => true}
|
8
|
+
|
9
|
+
<% model_names.each do |model_name| %>
|
10
|
+
create_table <%= ['privileges', model_name.tableize].sort.join('_').to_sym.inspect %>, :id => false, :force => true do |t|
|
11
|
+
t.integer :privilege_id, :null => false
|
12
|
+
t.integer <%= model_name.classify.foreign_key.to_sym.inspect %>, :null => false
|
13
|
+
end
|
14
|
+
<% end %>
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
<% model_names.each do |model_name| %>
|
19
|
+
drop_table <%= ['privileges', model_name.tableize].sort.join('_').to_sym.inspect %>
|
20
|
+
<% end %>
|
21
|
+
drop_table :privileges
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Privilege < ActiveRecord::Base
|
2
|
+
attr_accessible :route
|
3
|
+
attr_readonly :route
|
4
|
+
|
5
|
+
has_and_belongs_to_many <%=
|
6
|
+
model_names.map {|m| m.tableize.to_sym.inspect }.join(', ') %>
|
7
|
+
|
8
|
+
validates_format_of :route, :with => /^[^#]+#[^#]+$/
|
9
|
+
validates_uniqueness_of :route, :on => :create
|
10
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(
|
4
|
+
:adapter => 'sqlite3', :database => ':memory:')
|
5
|
+
|
6
|
+
def setup_db
|
7
|
+
ActiveRecord::Schema.define(:version => 1) do
|
8
|
+
create_table :users do |t|
|
9
|
+
t.string :login
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :blogs do |t|
|
13
|
+
t.references :user, :null => false
|
14
|
+
t.string :title
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :categories do |t|
|
18
|
+
t.references :blog, :null => false
|
19
|
+
t.string :title
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :articles do |t|
|
23
|
+
t.references :publishable, :polymorphic => true, :null => false
|
24
|
+
t.references :user
|
25
|
+
t.string :title
|
26
|
+
t.text :content
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :comments do |t|
|
30
|
+
t.references :article, :null => false
|
31
|
+
t.references :user
|
32
|
+
t.text :content
|
33
|
+
end
|
34
|
+
|
35
|
+
create_table :privileges do |t|
|
36
|
+
t.string :route, :limit => 255, :null => false
|
37
|
+
end
|
38
|
+
|
39
|
+
add_index :privileges, :route, {:unique => true}
|
40
|
+
|
41
|
+
create_table :privileges_users, :id => false, :force => true do |t|
|
42
|
+
t.integer :privilege_id, :null => false
|
43
|
+
t.integer :user_id, :null => false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def seed_privileges
|
49
|
+
rest_actions = %w(index show new create edit update destroy)
|
50
|
+
controllers = {
|
51
|
+
:users => rest_actions,
|
52
|
+
:blogs => rest_actions,
|
53
|
+
:categories => rest_actions,
|
54
|
+
:articles => rest_actions,
|
55
|
+
:comments => rest_actions }
|
56
|
+
|
57
|
+
controllers.each_pair do |controller, actions|
|
58
|
+
actions.each do |action|
|
59
|
+
Privilege.create! :route => [controller, action].join('#')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def teardown_db
|
65
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
66
|
+
ActiveRecord::Base.connection.drop_table(table)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class User < ActiveRecord::Base
|
71
|
+
acts_as_privilege
|
72
|
+
|
73
|
+
has_one :blog, :dependent => :destroy
|
74
|
+
has_many :articles, :dependent => :destroy
|
75
|
+
has_many :comments, :dependent => :destroy
|
76
|
+
end
|
77
|
+
|
78
|
+
class Blog < ActiveRecord::Base
|
79
|
+
belongs_to :user
|
80
|
+
has_many :articles, :as => :publishable, :dependent => :destroy
|
81
|
+
has_many :categories, :dependent => :destroy
|
82
|
+
end
|
83
|
+
|
84
|
+
class Category < ActiveRecord::Base
|
85
|
+
belongs_to :blog
|
86
|
+
has_many :articles, :as => :publishable, :dependent => :destroy
|
87
|
+
end
|
88
|
+
|
89
|
+
class Article < ActiveRecord::Base
|
90
|
+
belongs_to :publishable, :polymorphic => true
|
91
|
+
belongs_to :user
|
92
|
+
has_many :comments, :dependent => :destroy
|
93
|
+
end
|
94
|
+
|
95
|
+
class Comment < ActiveRecord::Base
|
96
|
+
belongs_to :article
|
97
|
+
belongs_to :user
|
98
|
+
end
|
99
|
+
|
100
|
+
class Privilege < ActiveRecord::Base
|
101
|
+
attr_accessible :route
|
102
|
+
attr_readonly :route
|
103
|
+
|
104
|
+
has_and_belongs_to_many :users
|
105
|
+
|
106
|
+
validates_format_of :route, :with => /^[^#]+#[^#]+$/
|
107
|
+
validates_uniqueness_of :route, :on => :create
|
108
|
+
end
|
109
|
+
|
110
|
+
class PrivilegeTest < MiniTest::Unit::TestCase
|
111
|
+
def setup
|
112
|
+
setup_db
|
113
|
+
|
114
|
+
@admin = User.create! :login => 'admin'
|
115
|
+
@bob = User.create! :login => 'bob'
|
116
|
+
@spammer = User.create! :login => 'spammer'
|
117
|
+
|
118
|
+
@blog = @admin.create_blog :title => 'my_blog'
|
119
|
+
@category = @blog.categories.create! :title => 'main'
|
120
|
+
@article = @category.articles.create! :title => 'hello, world',
|
121
|
+
:user => @admin
|
122
|
+
@comment0 = @article.comments.create! :content => 'foobar',
|
123
|
+
:user => @bob
|
124
|
+
@comment1 = @article.comments.create! :content => 'spam spam spam',
|
125
|
+
:user => @spammer
|
126
|
+
|
127
|
+
seed_privileges
|
128
|
+
|
129
|
+
@admin.update_attribute :privilege_ids, Privilege.all.map(&:id)
|
130
|
+
|
131
|
+
default_privileges = %w(index show).inject([]) do |privileges, action|
|
132
|
+
privileges << Privilege.where(['route LIKE ?', "%##{action}"]).map(&:id)
|
133
|
+
end
|
134
|
+
|
135
|
+
default_privileges.flatten!
|
136
|
+
|
137
|
+
[@bob, @spammer].each do |user|
|
138
|
+
user.update_attribute :privilege_ids, default_privileges
|
139
|
+
end
|
140
|
+
|
141
|
+
%w(new create).each do |action|
|
142
|
+
@bob.privileges << Privilege.first(:conditions => {
|
143
|
+
:route => "comments##{action}" })
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def teardown
|
148
|
+
teardown_db
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_privileges
|
152
|
+
refute @admin.privilege?('silk_routes#index')
|
153
|
+
refute @admin.privilege?('silk_routes#show')
|
154
|
+
assert @admin.has_privilege?('blogs', 'destroy')
|
155
|
+
assert @admin.privilege?('articles#create')
|
156
|
+
refute @bob.privilege?('articles#create')
|
157
|
+
assert @bob.privilege?(:"comments#create")
|
158
|
+
refute @spammer.privilege?('comments#create')
|
159
|
+
assert @spammer.privilege?('comments#show')
|
160
|
+
end
|
161
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,106 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_privilege
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
version: 1.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Cyril Wack
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
|
-
cert_chain:
|
16
|
-
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
BBSsO/YPzLP2/ZtBKQfWveZNRK3uKDANBgkqhkiG9w0BAQUFAAOCAQEAGaGpPlEc
|
30
|
-
Z8A7Jtfws1tpdLOlQrQQXfIgBrPvfjO18MxT2BVgnusYcMuJgrY1skbH6RDxhdia
|
31
|
-
EetICD0kvyGnbK+dHdhRwvmmiqc7ZOaiFb3RNLcW6jduxafH4zgKUeg23KpfJYy3
|
32
|
-
MOqVgHckM1hMZTWz7nmrXJBAjj/48jFOPrwtTed8kd6KpIjUz4e2oTwT+JIVnryF
|
33
|
-
sYFesvR4DywbXL88T29gq5biCHsAgbK89DW5DNx1Yg1HNLxCdJurJFrcQQS3XQco
|
34
|
-
h2svBTlG7Yg1wLZAGkVx4RSkrFujrxpgLsz5bfmdnbiEgKcF9njIOdVO4P4vwyoS
|
35
|
-
G4VzQZjAGxprTw==
|
36
|
-
-----END CERTIFICATE-----
|
37
|
-
|
38
|
-
date: 2010-04-12 00:00:00 +02:00
|
39
|
-
default_executable:
|
40
|
-
dependencies: []
|
41
|
-
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-04-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &2153144220 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153144220
|
42
25
|
description: Simple Rails plugin to restrict system access to authorized users.
|
43
|
-
email:
|
26
|
+
email:
|
27
|
+
- cyril@gosu.fr
|
44
28
|
executables: []
|
45
|
-
|
46
29
|
extensions: []
|
47
|
-
|
48
|
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
- lib/entity.rb
|
53
|
-
- lib/privileges_helper.rb
|
54
|
-
files:
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- .rvmrc
|
34
|
+
- Gemfile
|
55
35
|
- MIT-LICENSE
|
56
36
|
- README.rdoc
|
57
37
|
- Rakefile
|
58
38
|
- VERSION.yml
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
39
|
+
- acts_as_privilege.gemspec
|
40
|
+
- app/helpers/privileges_helper.rb
|
41
|
+
- app/views/acts_as_privilege/_fieldset.html.erb
|
42
|
+
- config/locales/en.yml
|
43
|
+
- config/locales/fr.yml
|
44
|
+
- config/locales/ja.yml
|
62
45
|
- init.rb
|
63
|
-
- lib/ability.rb
|
64
46
|
- lib/acts_as_privilege.rb
|
65
|
-
- lib/
|
66
|
-
- lib/
|
67
|
-
-
|
68
|
-
-
|
69
|
-
|
47
|
+
- lib/generators/privileges/USAGE
|
48
|
+
- lib/generators/privileges/privileges_generator.rb
|
49
|
+
- lib/generators/privileges/templates/create_privileges.rb
|
50
|
+
- lib/generators/privileges/templates/privilege.rb
|
51
|
+
- lib/generators/privileges/templates/privileges_helper.rb
|
52
|
+
- test/privilege_test.rb
|
53
|
+
- test/test_helper.rb
|
70
54
|
homepage: http://github.com/cyril/acts_as_privilege
|
71
55
|
licenses: []
|
72
|
-
|
73
56
|
post_install_message:
|
74
|
-
rdoc_options:
|
75
|
-
|
76
|
-
- --inline-source
|
77
|
-
- --title
|
78
|
-
- Acts_as_privilege
|
79
|
-
- --main
|
80
|
-
- README.rdoc
|
81
|
-
require_paths:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
82
59
|
- lib
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
- 1
|
96
|
-
- 2
|
97
|
-
version: "1.2"
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
98
72
|
requirements: []
|
99
|
-
|
100
73
|
rubyforge_project: acts_as_privilege
|
101
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.7.2
|
102
75
|
signing_key:
|
103
76
|
specification_version: 3
|
104
|
-
summary: Simple
|
105
|
-
test_files:
|
106
|
-
|
77
|
+
summary: Simple privilege solution for Rails.
|
78
|
+
test_files:
|
79
|
+
- test/privilege_test.rb
|
80
|
+
- test/test_helper.rb
|
data/Manifest
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
MIT-LICENSE
|
2
|
-
README.rdoc
|
3
|
-
Rakefile
|
4
|
-
VERSION.yml
|
5
|
-
generators/acts_as_privilege/USAGE
|
6
|
-
generators/acts_as_privilege/acts_as_privilege_generator.rb
|
7
|
-
generators/acts_as_privilege/templates/migration.rb
|
8
|
-
init.rb
|
9
|
-
lib/ability.rb
|
10
|
-
lib/acts_as_privilege.rb
|
11
|
-
lib/entity.rb
|
12
|
-
lib/privileges_helper.rb
|
13
|
-
Manifest
|
@@ -1,17 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
Creates Entity (representing controllers) and Ability (representing
|
3
|
-
controller actions) models, and then links them with any roles that your
|
4
|
-
application users might need.
|
5
|
-
|
6
|
-
Usage:
|
7
|
-
Pass the name of the model that you want to apply privileges.
|
8
|
-
|
9
|
-
Examples:
|
10
|
-
script/generate acts_as_privilege Role
|
11
|
-
|
12
|
-
Will expand roles with privileges. Then you can manage user roles
|
13
|
-
and attributed privileges for each one.
|
14
|
-
|
15
|
-
script/generate acts_as_privilege Group
|
16
|
-
|
17
|
-
Same, with the Group model.
|
@@ -1,34 +0,0 @@
|
|
1
|
-
class ActsAsPrivilegeGenerator < Rails::Generator::NamedBase
|
2
|
-
def manifest
|
3
|
-
record do |m|
|
4
|
-
m.migration_template 'migration.rb', "db/migrate", {:assigns => privileges_local_assigns, :migration_file_name => "create_privileges_for_#{plural_name}"}
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def class_name
|
9
|
-
name.camelize
|
10
|
-
end
|
11
|
-
|
12
|
-
def plural_name
|
13
|
-
custom_name = class_name.underscore.downcase
|
14
|
-
custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
|
15
|
-
custom_name
|
16
|
-
end
|
17
|
-
|
18
|
-
def plural_class_name
|
19
|
-
plural_name.camelize
|
20
|
-
end
|
21
|
-
|
22
|
-
def singular_name
|
23
|
-
class_name.underscore.downcase
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def privileges_local_assigns
|
29
|
-
returning(assigns = {}) do
|
30
|
-
assigns[:class_name] = "create_privileges_for_#{plural_name}"
|
31
|
-
assigns[:table_name] = plural_name
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
class CreatePrivilegesFor<%= plural_class_name %> < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :abilities do |t|
|
4
|
-
t.integer :entity_id, :null => false
|
5
|
-
|
6
|
-
t.string :name, :limit => 255, :null => false
|
7
|
-
end
|
8
|
-
|
9
|
-
add_index(:abilities, [:entity_id, :name])
|
10
|
-
|
11
|
-
create_table :entities do |t|
|
12
|
-
t.string :name, :limit => 255, :null => false
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index(:entities, :name, { :unique => true })
|
16
|
-
|
17
|
-
create_table :<%= ['abilities', plural_name].sort.join('_') %>, :id => false, :force => true do |t|
|
18
|
-
t.integer :ability_id, :null => false
|
19
|
-
t.integer :<%= "#{singular_name}_id" %>, :null => false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.down
|
24
|
-
drop_table :<%= ['abilities', plural_name].sort.join('_') %>
|
25
|
-
drop_table :entities
|
26
|
-
drop_table :abilities
|
27
|
-
end
|
28
|
-
end
|
data/lib/ability.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
class Ability < ActiveRecord::Base
|
2
|
-
# security
|
3
|
-
attr_readonly :name, :entity_id
|
4
|
-
|
5
|
-
# relations
|
6
|
-
belongs_to :entity
|
7
|
-
has_and_belongs_to_many :groups
|
8
|
-
|
9
|
-
# validates
|
10
|
-
validates_format_of :name, :with => /^[a-z0-9_]+$/, :allow_nil => false
|
11
|
-
validates_uniqueness_of :name, :case_sensitive => false, :scope => :entity_id
|
12
|
-
end
|
data/lib/entity.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
class Entity < ActiveRecord::Base
|
2
|
-
# security
|
3
|
-
attr_readonly :name
|
4
|
-
|
5
|
-
# relations
|
6
|
-
has_many :abilities, :dependent => :destroy
|
7
|
-
|
8
|
-
# validates
|
9
|
-
validates_format_of :name, :with => /^[a-z0-9_]+$/, :allow_nil => false
|
10
|
-
validates_uniqueness_of :name, :case_sensitive => false
|
11
|
-
end
|
data/lib/privileges_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module PrivilegesHelper
|
2
|
-
def privileges_field(resource, object_name = params[:controller].singularize)
|
3
|
-
content_tag(:fieldset, :id => "#{object_name}_privileges") do
|
4
|
-
content_tag(:legend, "Privileges") +
|
5
|
-
content_tag(:p) do
|
6
|
-
label(object_name, :ability_ids) +
|
7
|
-
tag('br') + "\n" +
|
8
|
-
select(object_name, "ability_ids",
|
9
|
-
option_groups_from_collection_for_select(Entity.all, :abilities,
|
10
|
-
:name, :id, :name, resource.abilities.collect { |ability| ability.id }),
|
11
|
-
{}, {:multiple => 'multiple'})
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data.tar.gz.sig
DELETED
metadata.gz.sig
DELETED
Binary file
|