cancan-permits 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.txt +3 -0
- data/Gemfile +19 -0
- data/README.markdown +36 -254
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/cancan-permits.gemspec +39 -5
- data/lib/cancan-permits/permit/base_permit.rb +12 -3
- metadata +202 -36
data/Changelog.txt
CHANGED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
group :default do
|
4
|
+
gem 'cancan', ">= 1.4.1"
|
5
|
+
gem 'require_all', "~> 1.2.0"
|
6
|
+
gem 'sugar-high', "~> 0.3.0"
|
7
|
+
gem 'rails3_artifactor', "~> 0.3.1"
|
8
|
+
gem 'activemodel', ">= 3.0.1"
|
9
|
+
gem 'activesupport', ">= 3.0.1"
|
10
|
+
gem 'activeresource', ">= 3.0.1"
|
11
|
+
gem 'logging_assist', ">= 0.1.6"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development, :test do
|
15
|
+
gem "rspec", ">= 2.0.1"
|
16
|
+
gem 'code-spec', "~> 0.2.9"
|
17
|
+
gem 'rails-app-spec', "~> 0.3.1"
|
18
|
+
end
|
19
|
+
|
data/README.markdown
CHANGED
@@ -45,141 +45,30 @@ Modify the User model in 'models/user.rb' (optional)
|
|
45
45
|
end
|
46
46
|
</pre>
|
47
47
|
|
48
|
-
##
|
48
|
+
## Permits configuration
|
49
49
|
|
50
|
-
|
51
|
-
These permissions will then be applied at the appropriate point when calculation permissions of the user.
|
50
|
+
Permits can be configured [using permits configuration files](https://github.com/kristianmandrup/cancan-permits/wiki/Using-permits-configuration-files)
|
52
51
|
|
53
|
-
|
54
|
-
* Permits
|
55
|
-
* Licenses
|
52
|
+
### Users, roles and permissions
|
56
53
|
|
57
|
-
|
54
|
+
_CanCan permits_ requires that you have some kind of 'role system' in place and that _User#has_role?_ returns whether the user has a given role (pass role argument as symbol or string). You can either add a 'role' directly to the _User_ class or fx use a [Roles Generic](https://github.com/kristianmandrup/roles_generic) role strategy.
|
58
55
|
|
59
|
-
|
60
|
-
edit the permits config files for: user permissions, permits and licenses.
|
56
|
+
## Application configuration for CanCan Permits
|
61
57
|
|
62
|
-
|
58
|
+
* Define roles that Users can have
|
59
|
+
* Define which roles are available
|
60
|
+
* Define a Permit for each role.
|
61
|
+
* For each Permit, define what Users with a role matching the permit can do
|
63
62
|
|
64
|
-
|
63
|
+
To add roles to your app, you might consider using a *roles* gem such as [Roles Generic](http://github.com/kristianmandrup/roles_generic) or any of the ORM specific variants.
|
65
64
|
|
66
|
-
|
65
|
+
CanCan permits is integrated with [CanCan REST links](https://github.com/kristianmandrup/cancan-rest-links), letting you easily control which users have access to which models in your app.
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
YAML file: _config/user_permissions.yml_
|
67
|
+
Note that [Cream](https://github.com/kristianmandrup/cream) has a _full_config_ generator that automatically configures all this for you in a standard configuration which integrates all the various parts (and even supports multiple ORMs) !!!
|
71
68
|
|
72
|
-
|
69
|
+
### Define which roles are available
|
73
70
|
|
74
|
-
|
75
|
-
<pre>abc@mail.ru:
|
76
|
-
can:
|
77
|
-
update: [Comment, Fruit, Car, Friendship]
|
78
|
-
manage:
|
79
|
-
- Article
|
80
|
-
owns:
|
81
|
-
- User
|
82
|
-
mike.shedlock@acc.com:
|
83
|
-
can:
|
84
|
-
read:
|
85
|
-
- all
|
86
|
-
cannot:
|
87
|
-
update:
|
88
|
-
- Post
|
89
|
-
</pre>
|
90
|
-
|
91
|
-
Loading YAML user_permits file in a Permit:
|
92
|
-
<pre>class AdminPermit < Permit::Base
|
93
|
-
def initialize(ability, options = {})
|
94
|
-
super
|
95
|
-
end
|
96
|
-
|
97
|
-
def permit?(user, options = {})
|
98
|
-
super
|
99
|
-
return if !role_match? user
|
100
|
-
can :manage, :all
|
101
|
-
|
102
|
-
load_rules user
|
103
|
-
end
|
104
|
-
end
|
105
|
-
</pre>
|
106
|
-
|
107
|
-
The call to #load_rules will call both _#load_user_roles_ and _#load_role_rules_. Hence by default it applies both the _user_permits_ and _permits_ config files.
|
108
|
-
If you want, you can call these methods individually in case only want to apply one set of rules.
|
109
|
-
|
110
|
-
### Permit rules
|
111
|
-
|
112
|
-
YAML file: _config/permits.yml_
|
113
|
-
|
114
|
-
Each key at the top level is expected to match a permit/role name.
|
115
|
-
|
116
|
-
Example yml config file:
|
117
|
-
<pre>admin:
|
118
|
-
can:
|
119
|
-
manage:
|
120
|
-
- Article
|
121
|
-
- Post
|
122
|
-
guest:
|
123
|
-
can:
|
124
|
-
manage:
|
125
|
-
- all
|
126
|
-
cannot:
|
127
|
-
manage:
|
128
|
-
- User
|
129
|
-
</pre>
|
130
|
-
|
131
|
-
As you can see
|
132
|
-
|
133
|
-
### License permissions
|
134
|
-
|
135
|
-
YAML file: _config/licenses.yml_
|
136
|
-
|
137
|
-
Each key at the top level is expected to match a license name.
|
138
|
-
|
139
|
-
Example yml config file:
|
140
|
-
|
141
|
-
<pre>blogging:
|
142
|
-
can:
|
143
|
-
manage:
|
144
|
-
- Article
|
145
|
-
- Post
|
146
|
-
admin:
|
147
|
-
can:
|
148
|
-
manage:
|
149
|
-
- all
|
150
|
-
cannot:
|
151
|
-
manage:
|
152
|
-
- User
|
153
|
-
</pre>
|
154
|
-
|
155
|
-
Usage in a license:
|
156
|
-
<pre>class UserAdminLicense < License::Base
|
157
|
-
def initialize name
|
158
|
-
super
|
159
|
-
end
|
160
|
-
|
161
|
-
def enforce!
|
162
|
-
can(:manage, User)
|
163
|
-
|
164
|
-
load_rules
|
165
|
-
end
|
166
|
-
</pre>
|
167
|
-
|
168
|
-
### User Roles
|
169
|
-
|
170
|
-
_CanCan permits_ requires that you have some kind of Role system in place and that User#has_role? uses this Role system.
|
171
|
-
You can either add a 'role' field directly to User or fx use a [Roles Generic ](https://github.com/kristianmandrup/roles_generic) role strategy.
|
172
|
-
|
173
|
-
## Usage
|
174
|
-
|
175
|
-
* Define Roles that Users can have
|
176
|
-
* Define which Roles are available
|
177
|
-
* Define a Permit for each Role.
|
178
|
-
* For each Permit, define what that Role can do
|
179
|
-
|
180
|
-
To add Roles to your app, you might consider using a *roles* gem such as [Roles Generic](http://github.com/kristianmandrup/roles_generic) or any of the ORM specific variants.
|
181
|
-
|
182
|
-
### Define which Roles are available
|
71
|
+
_CanCan permits_ uses the following strategy to discover which roles are available in the app.
|
183
72
|
|
184
73
|
Default configuration:
|
185
74
|
<pre>module Permits::Roles
|
@@ -211,41 +100,27 @@ Permit example:
|
|
211
100
|
end
|
212
101
|
|
213
102
|
def permit?(user, options = {})
|
214
|
-
|
215
|
-
|
216
|
-
can
|
103
|
+
return if !role_match? user
|
104
|
+
|
105
|
+
can(:read, Blog)
|
106
|
+
can(:manage, Article)
|
107
|
+
owns(user, Post)
|
217
108
|
end
|
218
109
|
end
|
219
110
|
</pre>
|
220
111
|
|
221
|
-
|
222
|
-
|
223
|
-
The Permits generator always generates the special permits *Any* and *System*.
|
224
|
-
|
225
|
-
### Any permit
|
112
|
+
Alternatively you can use <code>return if !super user, :in_role</code> to exit if the user doesn't have a role that matches the Permit.
|
113
|
+
This will in effect execute the same test.
|
226
114
|
|
227
|
-
|
228
|
-
F.ex, maybe in your app, any user should be able to read comments, articles and posts:
|
115
|
+
_Ownership permission:_
|
229
116
|
|
230
|
-
|
231
|
-
|
117
|
+
The _owns_ call is a special built-in way to define ownership permission. The #_owns_ call can also pe used inside Permits.
|
118
|
+
If a user owns an object instance that user will automatically have :manage permissions to that object instance.
|
232
119
|
|
233
|
-
###
|
120
|
+
### Special permits
|
234
121
|
|
235
|
-
The
|
236
|
-
|
237
|
-
|
238
|
-
Example:
|
239
|
-
The system permit can be used to allow management of all resources when the request is from localhost (which usually means "in development mode").
|
240
|
-
By default this logic is setup and ready to go.
|
241
|
-
|
242
|
-
You can configure this simply by setting the following boolean class variable:
|
243
|
-
|
244
|
-
<code>Permits::Configuration.localhost_manager = true</code>
|
245
|
-
|
246
|
-
## Default roles
|
247
|
-
|
248
|
-
By default the permits for the roles System and Guest are also generated.
|
122
|
+
The Permits system uses some [special permits](https://github.com/kristianmandrup/cancan-permits/wiki/Special-permits) that can be configured for
|
123
|
+
avanced permission scenarios as described in the wiki.
|
249
124
|
|
250
125
|
### Licenses
|
251
126
|
|
@@ -268,7 +143,7 @@ License example:
|
|
268
143
|
end
|
269
144
|
</pre>
|
270
145
|
|
271
|
-
|
146
|
+
Licenses usage example:
|
272
147
|
<pre>class GuestPermit < Permit::Base
|
273
148
|
def initialize(ability, options = {})
|
274
149
|
super
|
@@ -286,9 +161,9 @@ end
|
|
286
161
|
|
287
162
|
The permits system will try to find a license named UserAdminLicense and BloggingLicense in this example and then call _#enforce!_ on each license.
|
288
163
|
|
289
|
-
##
|
164
|
+
## Using Permits with an ORM
|
290
165
|
|
291
|
-
The easiest option is to directly set the orm as a class variable. An appropriate ownership strategy will be selected accordingly for the ORM.
|
166
|
+
The easiest option is to directly set the orm as a class variable. An appropriate 'ownership strategy' will be selected accordingly for the ORM.
|
292
167
|
|
293
168
|
<pre>
|
294
169
|
Permits::Ability.orm = :data_mapper
|
@@ -297,9 +172,9 @@ The easiest option is to directly set the orm as a class variable. An appropriat
|
|
297
172
|
The ORMs currently supported (and tested) are :active_record, :data_mapper, :mongoid, :mongo_mapper
|
298
173
|
|
299
174
|
For more fine grained control, you can set a :strategy option directly on the Ability instance. This way the ownership strategy is set explicitly.
|
300
|
-
The current valid values are :
|
175
|
+
The current valid values are _:default_ and _:string_.
|
301
176
|
|
302
|
-
The strategy option :string can be used for most ORMs. Setting
|
177
|
+
The strategy option :string can be used for most ORMs. Setting _orm__ to _:active_record_ or _:generic_ makes use of the _:default_ strategy.
|
303
178
|
All the other ORMs use the :string ownership strategy,
|
304
179
|
|
305
180
|
Note: You can dive into the code and implement your own strategy if needed.
|
@@ -328,7 +203,7 @@ Advanced #permit? functionality:
|
|
328
203
|
end
|
329
204
|
</pre>
|
330
205
|
|
331
|
-
###
|
206
|
+
### Configuring global management permission for localhost
|
332
207
|
|
333
208
|
The Permits system allows a global setting in order to allow localhost to manage all objects. This can be useful in development or administration mode.
|
334
209
|
|
@@ -337,8 +212,6 @@ To configure permits to allow localhost to manage objects:
|
|
337
212
|
Permits::Configuration.localhost_manager = true
|
338
213
|
</code>
|
339
214
|
|
340
|
-
Please provide suggestions and feedback on how to improve this :)
|
341
|
-
|
342
215
|
Assuming the following:
|
343
216
|
- a request object is present
|
344
217
|
- the host of the request is 'localhost'
|
@@ -348,6 +221,8 @@ Then the user is allowed to manage all objects and no other Permits will be eval
|
|
348
221
|
|
349
222
|
Note: In the code above, the built in <code>#localhost_manager?</code> method is used.
|
350
223
|
|
224
|
+
_Please provide suggestions and feedback on how to improve this :)_
|
225
|
+
|
351
226
|
## Generators
|
352
227
|
|
353
228
|
The gem comes with the following generators
|
@@ -357,100 +232,7 @@ The gem comes with the following generators
|
|
357
232
|
* cancan:licenses - generate multiple licenses
|
358
233
|
* cancan:license - generate a single license
|
359
234
|
|
360
|
-
|
361
|
-
|
362
|
-
Generates one or more permits in _app/permits_
|
363
|
-
|
364
|
-
Options
|
365
|
-
* --orm : The ORM to use (active_record, data_mapper, mongoid, mongo_mapper) - creates a Rails initializer
|
366
|
-
* --initializer : A Rails 3 initializer file for Permits is generated by default. Use --no-initializer option to disable this
|
367
|
-
* --roles : The roles for which to generate permits ; default Guest (read all) and Admin (manage all)
|
368
|
-
* --default-permits : By default :guest and :admin permits are generated. Use --no-default-permits option to disable this
|
369
|
-
|
370
|
-
<code>$ rails g cancan:permits --orm active_record --roles guest author admin</code>
|
371
|
-
|
372
|
-
### What does the generator generate?
|
373
|
-
|
374
|
-
To get an understanding of what the generator generates for a Rails 3 application, try to run the spec _permit_generator_spec.rb_ with _RSpec 2_ as follows:
|
375
|
-
|
376
|
-
In the file _permits_generator_spec.rb_ make the following change <code>config.remove_temp_dir = false</code>
|
377
|
-
This will prevent the rails /tmp dir from being deleted after the test run, so you can inspect what is generated in the Rails app.
|
378
|
-
|
379
|
-
Now run the generator spec to see the result:
|
380
|
-
<code>$ rspec spec/generators/cancan/permits_generator_spec.rb</code>
|
381
|
-
|
382
|
-
## Licenses Generator
|
383
|
-
|
384
|
-
Generates one or more licenses in _app/licenses_
|
385
|
-
|
386
|
-
Options
|
387
|
-
* --licenses : The licenses to generate; default UserAdmin and Blogging licenses are generated
|
388
|
-
* --default-licenses : By default exemplar licenses are generated. Use --no-default-licenses option to disable this
|
389
|
-
|
390
|
-
Run examples:
|
391
|
-
|
392
|
-
Generate default licenses:
|
393
|
-
|
394
|
-
<code>$ rails g cancan:licenses</code>
|
395
|
-
|
396
|
-
Genereate specific licenses (no defaults):
|
397
|
-
|
398
|
-
<code>$ rails g cancan:licenses profile_administration article_editing --no-default-licenses</code>
|
399
|
-
|
400
|
-
Create both specific and default licenses:
|
401
|
-
|
402
|
-
<code>$ rails g cancan:licenses profile_administration article_editing</code>
|
403
|
-
|
404
|
-
### What does the generator generate?
|
405
|
-
|
406
|
-
To get an understanding of what the generator generates for a Rails 3 application, try to run the spec _licenses_generator_spec.rb_ with rspec 2 as follows:
|
407
|
-
|
408
|
-
In the file _licenses_generator_spec.rb_ make the following change <code>config.remove_temp_dir = false</code>
|
409
|
-
This will prevent the rails /tmp dir from being deleted after the test run, so you can inspect what is generated in the Rails app.
|
410
|
-
|
411
|
-
Now run the generator spec to see the result:
|
412
|
-
<code>$ rspec spec/generators/cancan/licenses_generator_spec.rb</code>
|
413
|
-
|
414
|
-
|
415
|
-
## License Generator
|
416
|
-
|
417
|
-
Generates a single license in _app/licenses_
|
418
|
-
|
419
|
-
<code>rails g cancan:license [NAME]</code>
|
420
|
-
|
421
|
-
Options
|
422
|
-
* --creates : The models that have 'creates' permission for the holder of this license
|
423
|
-
* --owns : The models that have 'owns' permission for the holder of this license
|
424
|
-
* --manages : The models that have 'manages' permission for the holder of this license
|
425
|
-
* --read : The models that have 'read' permission for the holder of this license
|
426
|
-
|
427
|
-
Run examples:
|
428
|
-
|
429
|
-
Generate licenses:
|
430
|
-
|
431
|
-
<code>$ rails g cancan:license blog_editing --owns article post --read blog --licenses blogging</code>
|
432
|
-
|
433
|
-
## Permit Generator
|
434
|
-
|
435
|
-
Generates a single license in _app/permits_
|
436
|
-
|
437
|
-
<code>rails g cancan:permit [ROLE]</code>
|
438
|
-
|
439
|
-
Options
|
440
|
-
* --creates : The models that have 'creates' permission for the holder of this license
|
441
|
-
* --owns : The models that have 'owns' permission for the holder of this license
|
442
|
-
* --manages : The models that have 'manages' permission for the holder of this license
|
443
|
-
* --read : The models that have 'read' permission for the holder of this license
|
444
|
-
|
445
|
-
Run examples:
|
446
|
-
|
447
|
-
Generate licenses:
|
448
|
-
|
449
|
-
<code>$ rails g cancan:permit editor --owns article post --read blog --licenses blog_editing</code>
|
450
|
-
|
451
|
-
# TODO
|
452
|
-
|
453
|
-
The Permits generator should attempt to attempt to uncover which roles are currently defined as available to the system, trying Cream#available_roles and then User#roles. It could then generate permits for those roles. Any roles specified in the --roles option should be merged with the roles available in the app.
|
235
|
+
The generators are described in detail [here](https://github.com/kristianmandrup/cancan-permits/wiki/Permits-and-License-generators)
|
454
236
|
|
455
237
|
## Note on Patches/Pull Requests
|
456
238
|
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.add_development_dependency 'code-spec', "~> 0.2.9"
|
12
12
|
gem.add_development_dependency 'rails-app-spec', "~> 0.3.1"
|
13
13
|
|
14
|
-
gem.add_dependency 'cancan', "
|
14
|
+
gem.add_dependency 'cancan', ">= 1.4.1"
|
15
15
|
gem.add_dependency 'require_all', "~> 1.2.0"
|
16
16
|
gem.add_dependency 'sugar-high', "~> 0.3.0"
|
17
17
|
gem.add_dependency 'rails3_artifactor', "~> 0.3.1"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
data/cancan-permits.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cancan-permits}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-09}
|
13
13
|
s.description = %q{Role specific Permits for use with CanCan permission system}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
22
|
"Changelog.txt",
|
23
|
+
"Gemfile",
|
23
24
|
"LICENSE",
|
24
25
|
"README.markdown",
|
25
26
|
"Rakefile",
|
@@ -169,10 +170,21 @@ Gem::Specification.new do |s|
|
|
169
170
|
s.specification_version = 3
|
170
171
|
|
171
172
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
173
|
+
s.add_runtime_dependency(%q<cancan>, [">= 1.4.1"])
|
174
|
+
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
175
|
+
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
176
|
+
s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
|
177
|
+
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.1"])
|
178
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
|
179
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 3.0.1"])
|
180
|
+
s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.6"])
|
172
181
|
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
173
182
|
s.add_development_dependency(%q<code-spec>, ["~> 0.2.9"])
|
174
183
|
s.add_development_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
175
|
-
s.
|
184
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
185
|
+
s.add_development_dependency(%q<code-spec>, ["~> 0.2.9"])
|
186
|
+
s.add_development_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
187
|
+
s.add_runtime_dependency(%q<cancan>, [">= 1.4.1"])
|
176
188
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
177
189
|
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
178
190
|
s.add_runtime_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
|
@@ -181,10 +193,21 @@ Gem::Specification.new do |s|
|
|
181
193
|
s.add_runtime_dependency(%q<activeresource>, [">= 3.0.1"])
|
182
194
|
s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.6"])
|
183
195
|
else
|
196
|
+
s.add_dependency(%q<cancan>, [">= 1.4.1"])
|
197
|
+
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
198
|
+
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
199
|
+
s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
|
200
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.1"])
|
201
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.1"])
|
202
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.1"])
|
203
|
+
s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
|
204
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
205
|
+
s.add_dependency(%q<code-spec>, ["~> 0.2.9"])
|
206
|
+
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
184
207
|
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
185
208
|
s.add_dependency(%q<code-spec>, ["~> 0.2.9"])
|
186
209
|
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
187
|
-
s.add_dependency(%q<cancan>, ["
|
210
|
+
s.add_dependency(%q<cancan>, [">= 1.4.1"])
|
188
211
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
189
212
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
190
213
|
s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
|
@@ -194,10 +217,21 @@ Gem::Specification.new do |s|
|
|
194
217
|
s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
|
195
218
|
end
|
196
219
|
else
|
220
|
+
s.add_dependency(%q<cancan>, [">= 1.4.1"])
|
221
|
+
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
222
|
+
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
223
|
+
s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
|
224
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.1"])
|
225
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.1"])
|
226
|
+
s.add_dependency(%q<activeresource>, [">= 3.0.1"])
|
227
|
+
s.add_dependency(%q<logging_assist>, [">= 0.1.6"])
|
228
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
229
|
+
s.add_dependency(%q<code-spec>, ["~> 0.2.9"])
|
230
|
+
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
197
231
|
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
198
232
|
s.add_dependency(%q<code-spec>, ["~> 0.2.9"])
|
199
233
|
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
200
|
-
s.add_dependency(%q<cancan>, ["
|
234
|
+
s.add_dependency(%q<cancan>, [">= 1.4.1"])
|
201
235
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
202
236
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
203
237
|
s.add_dependency(%q<rails3_artifactor>, ["~> 0.3.1"])
|
@@ -66,16 +66,19 @@ module Permit
|
|
66
66
|
@role_permissions = ::PermissionsLoader.load_permits options[:permits_file]
|
67
67
|
end
|
68
68
|
|
69
|
-
def permit?(user, options = {})
|
69
|
+
def permit?(user, options = {})
|
70
|
+
if options == :in_role
|
71
|
+
return true if !role_match? user
|
72
|
+
end
|
70
73
|
false
|
71
74
|
end
|
72
75
|
|
73
76
|
def can(action, subject, conditions = nil, &block)
|
74
|
-
can_definitions <<
|
77
|
+
can_definitions << rule_class.new(true, action, subject, conditions, block)
|
75
78
|
end
|
76
79
|
|
77
80
|
def cannot(action, subject, conditions = nil, &block)
|
78
|
-
can_definitions <<
|
81
|
+
can_definitions << rule_class.new(false, action, subject, conditions, block)
|
79
82
|
end
|
80
83
|
|
81
84
|
def owns(user, clazz, ownership_relation = :user_id, user_id_attribute = :id, strategy_used = nil)
|
@@ -102,6 +105,12 @@ module Permit
|
|
102
105
|
end
|
103
106
|
|
104
107
|
protected
|
108
|
+
|
109
|
+
# CanCan 1.5 compatibility
|
110
|
+
def rule_class
|
111
|
+
return CanCan::Rule if defined? CanCan::Rule
|
112
|
+
CanCan::CanDefinition
|
113
|
+
end
|
105
114
|
|
106
115
|
include Permit::Util
|
107
116
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 8
|
9
|
+
version: 0.3.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,13 +14,132 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-09 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
-
prerelease: false
|
21
|
+
name: cancan
|
23
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 4
|
30
|
+
- 1
|
31
|
+
version: 1.4.1
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: require_all
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
version: 1.2.0
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: sugar-high
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
- 3
|
60
|
+
- 0
|
61
|
+
version: 0.3.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rails3_artifactor
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
- 3
|
75
|
+
- 1
|
76
|
+
version: 0.3.1
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: activemodel
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 3
|
89
|
+
- 0
|
90
|
+
- 1
|
91
|
+
version: 3.0.1
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: activesupport
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 3
|
104
|
+
- 0
|
105
|
+
- 1
|
106
|
+
version: 3.0.1
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: activeresource
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 3
|
119
|
+
- 0
|
120
|
+
- 1
|
121
|
+
version: 3.0.1
|
122
|
+
type: :runtime
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: logging_assist
|
127
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
- 1
|
135
|
+
- 6
|
136
|
+
version: 0.1.6
|
137
|
+
type: :runtime
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: *id008
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rspec
|
142
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
24
143
|
none: false
|
25
144
|
requirements:
|
26
145
|
- - ">="
|
@@ -31,11 +150,11 @@ dependencies:
|
|
31
150
|
- 1
|
32
151
|
version: 2.0.1
|
33
152
|
type: :development
|
34
|
-
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: *id009
|
35
155
|
- !ruby/object:Gem::Dependency
|
36
156
|
name: code-spec
|
37
|
-
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
157
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
39
158
|
none: false
|
40
159
|
requirements:
|
41
160
|
- - ~>
|
@@ -46,11 +165,11 @@ dependencies:
|
|
46
165
|
- 9
|
47
166
|
version: 0.2.9
|
48
167
|
type: :development
|
49
|
-
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: *id010
|
50
170
|
- !ruby/object:Gem::Dependency
|
51
171
|
name: rails-app-spec
|
52
|
-
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
172
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
54
173
|
none: false
|
55
174
|
requirements:
|
56
175
|
- - ~>
|
@@ -61,14 +180,59 @@ dependencies:
|
|
61
180
|
- 1
|
62
181
|
version: 0.3.1
|
63
182
|
type: :development
|
64
|
-
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: *id011
|
65
185
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
186
|
+
name: rspec
|
187
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
188
|
+
none: false
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
segments:
|
193
|
+
- 2
|
194
|
+
- 0
|
195
|
+
- 1
|
196
|
+
version: 2.0.1
|
197
|
+
type: :development
|
67
198
|
prerelease: false
|
68
|
-
|
199
|
+
version_requirements: *id012
|
200
|
+
- !ruby/object:Gem::Dependency
|
201
|
+
name: code-spec
|
202
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ~>
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
segments:
|
208
|
+
- 0
|
209
|
+
- 2
|
210
|
+
- 9
|
211
|
+
version: 0.2.9
|
212
|
+
type: :development
|
213
|
+
prerelease: false
|
214
|
+
version_requirements: *id013
|
215
|
+
- !ruby/object:Gem::Dependency
|
216
|
+
name: rails-app-spec
|
217
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
69
218
|
none: false
|
70
219
|
requirements:
|
71
220
|
- - ~>
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
segments:
|
223
|
+
- 0
|
224
|
+
- 3
|
225
|
+
- 1
|
226
|
+
version: 0.3.1
|
227
|
+
type: :development
|
228
|
+
prerelease: false
|
229
|
+
version_requirements: *id014
|
230
|
+
- !ruby/object:Gem::Dependency
|
231
|
+
name: cancan
|
232
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
233
|
+
none: false
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
72
236
|
- !ruby/object:Gem::Version
|
73
237
|
segments:
|
74
238
|
- 1
|
@@ -76,11 +240,11 @@ dependencies:
|
|
76
240
|
- 1
|
77
241
|
version: 1.4.1
|
78
242
|
type: :runtime
|
79
|
-
|
243
|
+
prerelease: false
|
244
|
+
version_requirements: *id015
|
80
245
|
- !ruby/object:Gem::Dependency
|
81
246
|
name: require_all
|
82
|
-
|
83
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
247
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
84
248
|
none: false
|
85
249
|
requirements:
|
86
250
|
- - ~>
|
@@ -91,11 +255,11 @@ dependencies:
|
|
91
255
|
- 0
|
92
256
|
version: 1.2.0
|
93
257
|
type: :runtime
|
94
|
-
|
258
|
+
prerelease: false
|
259
|
+
version_requirements: *id016
|
95
260
|
- !ruby/object:Gem::Dependency
|
96
261
|
name: sugar-high
|
97
|
-
|
98
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
262
|
+
requirement: &id017 !ruby/object:Gem::Requirement
|
99
263
|
none: false
|
100
264
|
requirements:
|
101
265
|
- - ~>
|
@@ -106,11 +270,11 @@ dependencies:
|
|
106
270
|
- 0
|
107
271
|
version: 0.3.0
|
108
272
|
type: :runtime
|
109
|
-
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: *id017
|
110
275
|
- !ruby/object:Gem::Dependency
|
111
276
|
name: rails3_artifactor
|
112
|
-
|
113
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
277
|
+
requirement: &id018 !ruby/object:Gem::Requirement
|
114
278
|
none: false
|
115
279
|
requirements:
|
116
280
|
- - ~>
|
@@ -121,11 +285,11 @@ dependencies:
|
|
121
285
|
- 1
|
122
286
|
version: 0.3.1
|
123
287
|
type: :runtime
|
124
|
-
|
288
|
+
prerelease: false
|
289
|
+
version_requirements: *id018
|
125
290
|
- !ruby/object:Gem::Dependency
|
126
291
|
name: activemodel
|
127
|
-
|
128
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
292
|
+
requirement: &id019 !ruby/object:Gem::Requirement
|
129
293
|
none: false
|
130
294
|
requirements:
|
131
295
|
- - ">="
|
@@ -136,11 +300,11 @@ dependencies:
|
|
136
300
|
- 1
|
137
301
|
version: 3.0.1
|
138
302
|
type: :runtime
|
139
|
-
|
303
|
+
prerelease: false
|
304
|
+
version_requirements: *id019
|
140
305
|
- !ruby/object:Gem::Dependency
|
141
306
|
name: activesupport
|
142
|
-
|
143
|
-
requirement: &id009 !ruby/object:Gem::Requirement
|
307
|
+
requirement: &id020 !ruby/object:Gem::Requirement
|
144
308
|
none: false
|
145
309
|
requirements:
|
146
310
|
- - ">="
|
@@ -151,11 +315,11 @@ dependencies:
|
|
151
315
|
- 1
|
152
316
|
version: 3.0.1
|
153
317
|
type: :runtime
|
154
|
-
|
318
|
+
prerelease: false
|
319
|
+
version_requirements: *id020
|
155
320
|
- !ruby/object:Gem::Dependency
|
156
321
|
name: activeresource
|
157
|
-
|
158
|
-
requirement: &id010 !ruby/object:Gem::Requirement
|
322
|
+
requirement: &id021 !ruby/object:Gem::Requirement
|
159
323
|
none: false
|
160
324
|
requirements:
|
161
325
|
- - ">="
|
@@ -166,11 +330,11 @@ dependencies:
|
|
166
330
|
- 1
|
167
331
|
version: 3.0.1
|
168
332
|
type: :runtime
|
169
|
-
|
333
|
+
prerelease: false
|
334
|
+
version_requirements: *id021
|
170
335
|
- !ruby/object:Gem::Dependency
|
171
336
|
name: logging_assist
|
172
|
-
|
173
|
-
requirement: &id011 !ruby/object:Gem::Requirement
|
337
|
+
requirement: &id022 !ruby/object:Gem::Requirement
|
174
338
|
none: false
|
175
339
|
requirements:
|
176
340
|
- - ">="
|
@@ -181,7 +345,8 @@ dependencies:
|
|
181
345
|
- 6
|
182
346
|
version: 0.1.6
|
183
347
|
type: :runtime
|
184
|
-
|
348
|
+
prerelease: false
|
349
|
+
version_requirements: *id022
|
185
350
|
description: Role specific Permits for use with CanCan permission system
|
186
351
|
email: kmandrup@gmail.com
|
187
352
|
executables: []
|
@@ -195,6 +360,7 @@ files:
|
|
195
360
|
- .document
|
196
361
|
- .rspec
|
197
362
|
- Changelog.txt
|
363
|
+
- Gemfile
|
198
364
|
- LICENSE
|
199
365
|
- README.markdown
|
200
366
|
- Rakefile
|