acts_as_permission 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class PermissionsGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def self.next_migration_number(path)
9
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
10
+ end
11
+
12
+ def create_model_file
13
+ template 'permission.rb', 'app/models/permission.rb'
14
+ template 'permissions_helper.rb', 'app/helpers/permissions_helper.rb'
15
+ migration_template 'create_permissions.rb', 'db/migrate/create_permissions.rb'
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ class CreatePermissions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :permissions do |t|
4
+ t.string :route, :null => false
5
+ t.boolean :value, :null => false
6
+ t.references :permittable, :polymorphic => true, :null => false
7
+ t.references :permitted, :polymorphic => true
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :permissions
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ class Permission < ActiveRecord::Base
2
+ attr_accessible :route, :value, :permitted_id, :permitted_type
3
+ attr_readonly :route, :permitted_id, :permitted_type
4
+
5
+ with_options :polymorphic => true do |opts|
6
+ opts.belongs_to :permittable
7
+ opts.belongs_to :permitted
8
+ end
9
+
10
+ validates_format_of :route, :with => /^[^#]+#[^#]+$/
11
+ validates_inclusion_of :value, :in => [true, false]
12
+ validates_presence_of :permittable, :route
13
+
14
+ validates_uniqueness_of :route, :on => :create, :scope => [
15
+ :permittable_type, :permittable_id,
16
+ :permitted_type, :permitted_id ]
17
+
18
+ validate :permittable_route, :on => :create
19
+
20
+ protected
21
+
22
+ def permittable_route
23
+ unless permittable.class.permittable?(route)
24
+ errors.add :route, :is_not_included_in_the_list
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module PermissionsHelper
2
+ def permission_fields(f)
3
+ f.object.create_default_permissions!
4
+
5
+ render 'acts_as_permission/permission_fields', :f => f
6
+ end
7
+ end
@@ -0,0 +1,331 @@
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 :permissions do |t|
36
+ t.string :route, :null => false
37
+ t.boolean :value, :null => false
38
+ t.references :permittable, :polymorphic => true, :null => false
39
+ t.references :permitted, :polymorphic => true
40
+ t.timestamps
41
+ end
42
+ end
43
+ end
44
+
45
+ def teardown_db
46
+ ActiveRecord::Base.connection.tables.each do |table|
47
+ ActiveRecord::Base.connection.drop_table(table)
48
+ end
49
+ end
50
+
51
+ class User < ActiveRecord::Base
52
+ is_able_to_be_permitted
53
+
54
+ has_one :blog, :dependent => :destroy
55
+ has_many :articles, :dependent => :destroy
56
+ has_many :comments, :dependent => :destroy
57
+ end
58
+
59
+ class Blog < ActiveRecord::Base
60
+ acts_as_permission({
61
+ :"articles#index" => true,
62
+ :"articles#new" => [false, {
63
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
64
+ :"articles#create" => [false, {
65
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
66
+ :"categories#index" => true,
67
+ :"categories#new" => [false, {
68
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
69
+ :"categories#create" => [false, {
70
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
71
+ :"blogs#show" => true,
72
+ :"blogs#edit" => [false, {
73
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
74
+ :"blogs#update" => [false, [
75
+ {:permitted_id => 1, :permitted_type => "User", :value => true}]],
76
+ :"blogs#destroy" => [false, {
77
+ :permitted_id => 1, :permitted_type => "User", :value => true}]})
78
+
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
+ acts_as_permission({
86
+ 'articles#index' => true,
87
+ 'articles#new' => [false, {
88
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
89
+ 'articles#create' => [false, {
90
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
91
+ 'categories#show' => true,
92
+ 'categories#edit' => [false, {
93
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
94
+ 'categories#update' => [false, {
95
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
96
+ 'categories#destroy' => [false, {
97
+ :permitted_id => 1, :permitted_type => "User", :value => true}]})
98
+
99
+ belongs_to :blog
100
+ has_many :articles, :as => :publishable, :dependent => :destroy
101
+ end
102
+
103
+ class Article < ActiveRecord::Base
104
+ acts_as_permission({
105
+ 'articles#show' => [true, {}],
106
+ 'articles#edit' => [false, {
107
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
108
+ 'articles#update' => [false, {
109
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
110
+ 'articles#destroy' => [false, {
111
+ :permitted_id => 1, :permitted_type => "User", :value => true}],
112
+ 'comments#index' => true,
113
+ 'comments#new' => [true, [
114
+ {:permitted_id => 3, :permitted_type => "User", :value => false}]],
115
+ 'comments#create' => [true, [
116
+ {:permitted_id => 3, :permitted_type => "User", :value => false}]]})
117
+
118
+ belongs_to :publishable, :polymorphic => true
119
+ belongs_to :user
120
+ has_many :comments, :dependent => :destroy
121
+ end
122
+
123
+ class Comment < ActiveRecord::Base
124
+ acts_as_permission([
125
+ ["comments#show", true],
126
+ ["comments#edit", [false, [
127
+ {:permitted_id => 1, :permitted_type => "User", :value => true},
128
+ {:permitted_id => 2, :permitted_type => "User", :value => true}]]],
129
+ ["comments#update", [false, [
130
+ {:permitted_id => 1, :permitted_type => "User", :value => true},
131
+ {:permitted_id => 2, :permitted_type => "User", :value => true}]]],
132
+ ["comments#destroy", [false, {
133
+ :permitted_id => 1, :permitted_type => "User", :value => true}]]])
134
+
135
+ belongs_to :article
136
+ belongs_to :user
137
+ end
138
+
139
+ class Permission < ActiveRecord::Base
140
+ attr_accessible :route, :value, :permitted_id, :permitted_type
141
+ attr_readonly :route, :permitted_id, :permitted_type
142
+
143
+ belongs_to :permittable, :polymorphic => true
144
+ belongs_to :permitted, :polymorphic => true
145
+
146
+ validates_format_of :route, :with => /^[^#]+#[^#]+$/
147
+ validates_inclusion_of :value, :in => [true, false]
148
+ validates_presence_of :permittable, :route
149
+
150
+ validates_uniqueness_of :route, :on => :create, :scope => [
151
+ :permittable_type, :permittable_id,
152
+ :permitted_type, :permitted_id ]
153
+ end
154
+
155
+ class PermissionTest < MiniTest::Unit::TestCase
156
+ def setup
157
+ setup_db
158
+
159
+ @admin = User.create! :login => 'admin'
160
+ @bob = User.create! :login => 'bob'
161
+ @spammer = User.create! :login => 'spammer'
162
+
163
+ @blog = @admin.create_blog :title => 'my_blog'
164
+ @category = @blog.categories.create! :title => 'main'
165
+ @article = @category.articles.create! :title => 'hello, world',
166
+ :user => @admin
167
+ @comment0 = @article.comments.create! :content => 'foobar',
168
+ :user => @bob
169
+ @comment1 = @article.comments.create! :content => 'spam spam spam',
170
+ :user => @spammer
171
+ end
172
+
173
+ def teardown
174
+ teardown_db
175
+ end
176
+
177
+ def test_permissibilities
178
+ refute Blog.permittable?("silk_routes#index")
179
+ refute Blog.permittable?("blogs#index")
180
+ assert Blog.permittable?('blogs#show')
181
+ assert Blog.permittable?(:"articles#index")
182
+ assert Category.permittable?("categories#show")
183
+ assert Article.permittable?("articles#show")
184
+ end
185
+
186
+ def test_permissions
187
+ assert @blog.permissions.empty?
188
+ refute @blog.permission?("blogs#edit")
189
+ refute @blog.permission?("blogs#destroy")
190
+ refute @blog.permissions.empty?
191
+ assert @blog.permission?("blogs#show")
192
+ assert @blog.has_permission?("show")
193
+ assert_nil @blog.permission?("blogs#show", @spammer)
194
+ assert @blog.permission?(:"categories#create", @admin)
195
+ refute @blog.permission?("articles#new")
196
+ assert_nil @blog.permission?("silk_routes#index")
197
+ assert_equal 5, @blog.permissions.count
198
+ assert_empty @blog.permissions.delete_all
199
+ refute_empty @blog.create_default_permissions!
200
+ assert_equal @blog.permissions.length, @blog.permissions.count
201
+ assert_empty @blog.permissions.delete_all
202
+ assert_empty @blog.permissions
203
+ refute_nil @blog.create_permission!("categories#create", false, @admin)
204
+ assert_equal 1, @blog.permissions.count
205
+ refute @blog.permission?(:"categories#create", @admin)
206
+ assert_equal 1, @blog.permissions.count
207
+ assert_empty @blog.permissions.delete_all
208
+ assert @blog.permission("categories#create", @admin).
209
+ update_attribute(:value, false)
210
+ assert_equal 1, @blog.permissions.count
211
+ refute @blog.permission?(:"categories#create", @admin)
212
+ assert_equal 1, @blog.permissions.count
213
+ assert_empty @blog.permissions.delete_all
214
+ refute_nil @blog.create_permission!("categories#create", true, @admin)
215
+ assert @blog.permission?(:"categories#create", @admin)
216
+ assert_empty @blog.permissions.delete_all
217
+ refute_nil @blog.create_permission!("categories#create", true, @admin)
218
+ assert @blog.permission?(:"categories#create", @admin)
219
+ assert_empty @blog.permissions.delete_all
220
+ refute_nil @blog.create_permission!("categories#create", true, @bob)
221
+ refute Blog.first.permissions.empty?
222
+ assert_equal @blog.permissions.length, @blog.permissions.count
223
+ assert @blog.permission?(:"categories#create", @bob)
224
+ assert_nil @blog.create_permission!("categories#create", true, @bob)
225
+ assert @blog.permission?(:"categories#create", @bob)
226
+
227
+ assert @category.permissions.empty?
228
+ assert_nil @category.permission?(:yay)
229
+ assert @category.permissions.empty?
230
+ assert @category.permission?("articles#index")
231
+ refute @category.permissions.empty?
232
+ assert_nil @category.permission?("blogs#show")
233
+ assert @category.permission?("categories#show")
234
+ assert @category.permission?("categories#show")
235
+ assert_nil @category.permission?(:"categories#create", @admin)
236
+ assert_nil @category.permission?("categories#new", @bob)
237
+ assert_nil @category.permission?("categories#create")
238
+ refute @category.permission?("articles#create")
239
+ assert_equal 3, @category.permissions.count
240
+ refute_nil @category.create_permission!("articles#new", true, @bob)
241
+ assert_equal 4, @category.permissions.count
242
+ assert @category.permission?("articles#new", @bob)
243
+ assert_equal 4, @category.permissions.count
244
+ refute_nil @category.create_permission!("articles#create", true, @bob)
245
+ assert_equal 5, @category.permissions.count
246
+ assert @category.permission?("articles#create", @bob)
247
+ assert_nil @category.permission?("articles#show", @bob)
248
+ assert_equal 5, @category.permissions.count
249
+ assert_empty @category.permissions.delete_all
250
+ assert_nil @category.permission?("articles#create", @bob)
251
+ refute_nil @category.create_permission!("articles#create", true, @bob)
252
+ assert @category.permission?("articles#create", @bob)
253
+ refute_nil @category.create_permission!("articles#index", false)
254
+ assert_equal 2, @category.permissions.count
255
+ refute_empty @category.create_default_permissions!
256
+ assert @category.permission?("articles#create", @bob)
257
+ refute @category.permission?("articles#index")
258
+ assert @category.permission("articles#index").update_attribute(:value, true)
259
+ assert @category.permission?("articles#index")
260
+
261
+ assert @admin.permitted?(@category, "categories#edit")
262
+
263
+ assert @article.permission?(:"articles#destroy", @admin)
264
+ assert_equal 1, @article.permissions.count
265
+ assert @article.permission?("articles#destroy", @admin)
266
+ assert @admin.permitted?(@article, "articles#destroy")
267
+ assert_equal 1, @article.permissions.count
268
+ assert_nil @article.permission?("articles#show", @admin)
269
+ assert @article.permission?('articles#show')
270
+ assert_equal 2, @article.permissions.count
271
+ assert @article.permission?('comments#new')
272
+ assert_nil @article.permission?('comments#new', @admin)
273
+ assert_nil @article.permission?('comments#new', @bob)
274
+ refute @article.permission?('comments#new', @spammer)
275
+ refute @article.permission?('comments#create', @spammer)
276
+ assert_equal 5, @article.permissions.count
277
+ assert_empty @article.permissions.delete_all
278
+ assert_equal 0, @article.permissions.count
279
+ assert @article.permission?('comments#new')
280
+ assert_equal @article.permissions.count, @article.permissions.length
281
+ assert_equal 1, @article.permissions.count
282
+ refute_empty @article.create_default_permissions!
283
+ assert_equal @article.permissions.count, @article.permissions.length
284
+ refute @article.permission?(:"articles#destroy", @spammer)
285
+
286
+ refute_empty @article.permissions_attributes = [{
287
+ :route => "articles#destroy", :value => true,
288
+ :permitted_id => @spammer.id, :permitted_type => @spammer.class.name }]
289
+ assert @article.save
290
+
291
+ # Should work, knowed bug:
292
+ # https://rails.lighthouseapp.com/projects/8994/tickets/2160
293
+ #assert @article.update_attributes({:permissions_attributes => [{
294
+ # :route => "articles#destroy", :value => true,
295
+ # :permitted_id => @spammer.id, :permitted_type => @spammer.class.name }]})
296
+
297
+ assert @article.permission?(:"articles#destroy", @spammer)
298
+
299
+ assert_nil @spammer.permitted?(@article, "categories#show")
300
+ assert_nil @spammer.permitted?(@article, "categories#secret")
301
+
302
+ refute @spammer.permitted?(@article, "comments#new")
303
+ assert_nil @bob.permitted?(@article, "comments#new")
304
+
305
+ assert_nil @comment0.permission?(:"comments#show", @admin)
306
+ assert_equal 0, @comment0.permissions.count
307
+ assert @comment0.permission?(:"comments#show")
308
+ assert_equal 1, @comment0.permissions.count
309
+ assert_nil @comment0.permission?(:"comments#destroy_all")
310
+ assert_equal 1, @comment0.permissions.count
311
+ refute @comment0.permission?(:"comments#destroy")
312
+ assert_equal 2, @comment0.permissions.count
313
+ assert @comment0.permission?(:"comments#destroy", @admin)
314
+ assert_equal 3, @comment0.permissions.count
315
+ assert_empty @comment1.permissions
316
+ refute_nil @comment1.permissions.create!({
317
+ :route => 'comments#show', :value => false })
318
+ assert_equal 1, @comment1.permissions.count
319
+ refute @comment1.permission?(:"comments#show")
320
+ assert_equal 1, @comment1.permissions.count
321
+ assert_empty @comment1.permissions.delete_all
322
+ assert @comment1.permission?(:"comments#show")
323
+ assert_equal 1, @comment1.permissions.count
324
+ refute_nil @comment1.permission("comments#show").
325
+ update_attribute(:value, false)
326
+ refute @comment1.permission?(:"comments#show")
327
+ assert_nil @comment1.permission("comments#show", @bob)
328
+ assert_nil @comment1.permission?(:"comments#show", @bob)
329
+ assert_equal 1, @comment1.permissions.count
330
+ end
331
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'sqlite3'
3
+ require 'active_record'
4
+ require 'acts_as_permission'
metadata CHANGED
@@ -1,101 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: acts_as_permission
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
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
- -----BEGIN CERTIFICATE-----
18
- MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApjeXJp
19
- bC53YWNrMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
20
- b20wHhcNMTAwNDExMjI1OTI4WhcNMTEwNDExMjI1OTI4WjBBMRMwEQYDVQQDDApj
21
- eXJpbC53YWNrMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
22
- FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGJFqPSXGYdS6t
23
- t+kXyFuLg7uIbQHToLhdbfpu5j7dl65EWAspRI37ZE/FIFosmwQ0DAGiJ35gVX7K
24
- 5/rj745EUW9vijemlNHZjTY40AQAP2avlcMd6DnA7pl/x8dxC9G2dW/IS0nmjH0E
25
- +X7X0BZ8WIY7PBvLsq5ptpGaoaxpmqRjJDANolnODwyBjFWtUqpvOGeUWL24orZ3
26
- xwcW6d1vl8hraZ3UUJtIVXFg85lHclyrP33DYxj5sstgRwovaCPrvUQ6ZZ+hX/iJ
27
- MYaEFZsw74WVD4RLHl1bEz2RQGDgSwfFnOnrQ1gi2SaeqUN7uFThAEbbyiJK+rNL
28
- xapWOFs9AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
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: &2153626060 !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: *2153626060
42
25
  description: Simple Rails plugin to assign a list of permissions on a resource.
43
- email: cyril.wack@gmail.com
26
+ email:
27
+ - cyril@gosu.fr
44
28
  executables: []
45
-
46
29
  extensions: []
47
-
48
- extra_rdoc_files:
49
- - README.rdoc
50
- - lib/acts_as_permission.rb
51
- - lib/permissions_helper.rb
52
- files:
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .rvmrc
34
+ - Gemfile
53
35
  - MIT-LICENSE
54
36
  - README.rdoc
55
37
  - Rakefile
56
38
  - VERSION.yml
57
- - generators/acts_as_permission/USAGE
58
- - generators/acts_as_permission/acts_as_permission_generator.rb
39
+ - acts_as_permission.gemspec
40
+ - app/views/acts_as_permission/_permission_fields.html.erb
41
+ - config/locales/en.yml
42
+ - config/locales/fr.yml
43
+ - config/locales/ja.yml
59
44
  - init.rb
60
45
  - lib/acts_as_permission.rb
61
- - lib/permissions_helper.rb
62
- - Manifest
63
- - acts_as_permission.gemspec
64
- has_rdoc: true
46
+ - lib/generators/permissions/USAGE
47
+ - lib/generators/permissions/permissions_generator.rb
48
+ - lib/generators/permissions/templates/create_permissions.rb
49
+ - lib/generators/permissions/templates/permission.rb
50
+ - lib/generators/permissions/templates/permissions_helper.rb
51
+ - test/permission_test.rb
52
+ - test/test_helper.rb
65
53
  homepage: http://github.com/cyril/acts_as_permission
66
54
  licenses: []
67
-
68
55
  post_install_message:
69
- rdoc_options:
70
- - --line-numbers
71
- - --inline-source
72
- - --title
73
- - Acts_as_permission
74
- - --main
75
- - README.rdoc
76
- require_paths:
56
+ rdoc_options: []
57
+ require_paths:
77
58
  - lib
78
- required_ruby_version: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- segments:
90
- - 1
91
- - 2
92
- version: "1.2"
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
93
71
  requirements: []
94
-
95
72
  rubyforge_project: acts_as_permission
96
- rubygems_version: 1.3.6
73
+ rubygems_version: 1.7.2
97
74
  signing_key:
98
75
  specification_version: 3
99
- summary: Simple Rails plugin to assign a list of permissions on a resource.
100
- test_files: []
101
-
76
+ summary: Simple permission solution for Rails.
77
+ test_files:
78
+ - test/permission_test.rb
79
+ - test/test_helper.rb
data/Manifest DELETED
@@ -1,10 +0,0 @@
1
- MIT-LICENSE
2
- README.rdoc
3
- Rakefile
4
- VERSION.yml
5
- generators/acts_as_permission/USAGE
6
- generators/acts_as_permission/acts_as_permission_generator.rb
7
- init.rb
8
- lib/acts_as_permission.rb
9
- lib/permissions_helper.rb
10
- Manifest
@@ -1,20 +0,0 @@
1
- Description:
2
- Alter the structure model in order to attache an access control list (ACL)
3
- to its resources.
4
-
5
- Usage:
6
- Pass the name of the model, and an optional list of controller actions.
7
-
8
- If no controller actions is specified, those following will be generated:
9
- index, show, new, create, edit, update and destroy.
10
-
11
- Examples:
12
- script/generate acts_as_permission Article
13
-
14
- Will alter the Article model table by adding a field for each seven
15
- default actions (index, show, create, new, edit, update, and destroy).
16
-
17
- script/generate acts_as_permission Category index new create
18
-
19
- Will alter categories table with index, new and create action
20
- permission fields.
@@ -1,40 +0,0 @@
1
- class ActsAsPermissionGenerator < Rails::Generator::NamedBase
2
- def initialize(runtime_args, runtime_options = {})
3
- super
4
- @args = actions if @args.empty?
5
- end
6
-
7
- def manifest
8
- record do |m|
9
- m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => permissions_local_assigns, :migration_file_name => "add_permissions_fields_to_#{plural_name}"}
10
- end
11
- end
12
-
13
- def class_name
14
- name.camelize
15
- end
16
-
17
- def plural_name
18
- custom_name = class_name.underscore.downcase
19
- custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
20
- custom_name
21
- end
22
-
23
- private
24
-
25
- def actions
26
- %w[index show new create edit update destroy]
27
- end
28
-
29
- def permissions_local_assigns
30
- returning(assigns = {}) do
31
- assigns[:migration_action] = "add"
32
- assigns[:class_name] = "add_permissions_fields_to_#{plural_name}"
33
- assigns[:table_name] = plural_name
34
- assigns[:attributes] = []
35
- @args.each do |action|
36
- assigns[:attributes] << Rails::Generator::GeneratedAttribute.new("#{action}_permission", "boolean")
37
- end
38
- end
39
- end
40
- end
@@ -1,17 +0,0 @@
1
- module PermissionsHelper
2
- def permission_fields(object_name, actions = [])
3
- actions = %w[index show new create edit update destroy] if actions.empty?
4
- actions.delete('create') if actions.include?('new')
5
- actions.delete('update') if actions.include?('edit')
6
- content_tag(:fieldset, :id => "#{object_name}_permissions") do
7
- content_tag(:legend, "Permissions") +
8
- actions.collect do |action|
9
- content_tag(:p) do
10
- label(object_name, "#{action}_permission", action.to_s.humanize) +
11
- tag('br') + "\n" +
12
- select(object_name, "#{action}_permission", [ ["allow", true], ["deny", false] ], {:include_blank => 'ignore'})
13
- end
14
- end.join("\n")
15
- end
16
- end
17
- end
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file