cancan-permits 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +91 -16
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/cancan-permits.gemspec +133 -127
- data/lib/cancan-permits/permits/roles.rb +5 -4
- data/lib/generators/cancan/license/license_generator.rb +76 -0
- data/lib/generators/cancan/license/templates/license.rb +10 -0
- data/lib/generators/cancan/licenses/licenses_generator.rb +2 -5
- data/lib/generators/cancan/licenses/templates/{license.rb → base_license.rb} +0 -0
- data/lib/generators/cancan/permit/permit_generator.rb +76 -0
- data/lib/generators/cancan/permit/templates/role_permit.rb +12 -0
- data/spec/generators/cancan/license_generator_spec.rb +33 -0
- data/spec/generators/cancan/permit_generator_spec.rb +35 -0
- metadata +18 -11
- data/.gitignore +0 -23
data/README.markdown
CHANGED
@@ -6,6 +6,8 @@ Role specific Permits for use with [CanCan](http://github.com/ryanb/cancan) perm
|
|
6
6
|
|
7
7
|
See Changelog.txt (Major updates as per Nov 24. 2010)
|
8
8
|
|
9
|
+
Nov 28: Added Generators to create individual Permit and License!
|
10
|
+
|
9
11
|
## Install
|
10
12
|
|
11
13
|
<code>gem install cancan-permits</code>
|
@@ -18,7 +20,39 @@ Gemfile
|
|
18
20
|
Update gem bundle in terminal:
|
19
21
|
<code>$ bundle install</code>
|
20
22
|
|
21
|
-
See Generator section below.
|
23
|
+
See Generator section below.
|
24
|
+
|
25
|
+
See [CanCan permits demo app](https://github.com/kristianmandrup/cancan-permits-demo) for more info on how to set up a Rails 3 app with CanCan permits!
|
26
|
+
|
27
|
+
## Rails 3 configuration
|
28
|
+
|
29
|
+
Create a rails initializer with the following code:
|
30
|
+
<code>
|
31
|
+
module Cream
|
32
|
+
# specify all roles available in your app!
|
33
|
+
def self.available_roles
|
34
|
+
[:guest, :admin]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
</code>
|
38
|
+
|
39
|
+
Modify the User model in 'models/user.rb' (optional)
|
40
|
+
<code>
|
41
|
+
class User
|
42
|
+
def self.roles
|
43
|
+
Cream.available_roles
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_role? role
|
47
|
+
(self.role || 'guest').to_sym == role.to_sym
|
48
|
+
end
|
49
|
+
end
|
50
|
+
</code>
|
51
|
+
|
52
|
+
### User Roles
|
53
|
+
|
54
|
+
CanCan permits requires that you have some kind of Role system in place and that User#has_role? uses this Role system.
|
55
|
+
You can either add a 'role' field directly to User or fx use a [Roles Generic ](https://github.com/kristianmandrup/roles_generic) role strategy.
|
22
56
|
|
23
57
|
## Usage
|
24
58
|
|
@@ -32,23 +66,27 @@ To add Roles to your app, you might consider using a *roles* gem such as [Roles
|
|
32
66
|
### Define which Roles are available
|
33
67
|
|
34
68
|
You can override the default configuration here:
|
35
|
-
|
36
69
|
<pre>
|
37
70
|
module Permits::Roles
|
38
71
|
def self.available
|
39
|
-
|
72
|
+
if defined? ::Cream
|
73
|
+
Cream.available_roles
|
74
|
+
elsif defined? ::User
|
75
|
+
User.roles
|
76
|
+
else
|
77
|
+
[:admin, :guest]
|
78
|
+
end
|
40
79
|
end
|
41
80
|
end
|
42
|
-
</pre>
|
43
|
-
|
44
|
-
By default it returns User.roles if such exists, otherwise it returns [:guest, :admin] by default.
|
81
|
+
</pre>
|
45
82
|
|
46
83
|
### Define a Permit for each Role.
|
47
84
|
|
48
85
|
_Note:_ You might consider using the Permits generator in order to generate your permits for you (see below)
|
49
86
|
|
50
|
-
|
51
|
-
|
87
|
+
Permit example:
|
88
|
+
<pre><code>
|
89
|
+
class AdminPermit - Permit::Base
|
52
90
|
def initialize(ability, options = {})
|
53
91
|
super
|
54
92
|
end
|
@@ -60,7 +98,7 @@ _Note:_ You might consider using the Permits generator in order to generate your
|
|
60
98
|
can :manage, :all
|
61
99
|
end
|
62
100
|
end
|
63
|
-
</pre>
|
101
|
+
</code></pre>
|
64
102
|
|
65
103
|
## Special Permits
|
66
104
|
|
@@ -100,8 +138,8 @@ The generator will create a licenses.rb file in the permits folder where you can
|
|
100
138
|
licenses subfolder where you put your license files.
|
101
139
|
|
102
140
|
License example:
|
103
|
-
<pre>
|
104
|
-
class BloggingLicense
|
141
|
+
<pre><code>
|
142
|
+
class BloggingLicense - License::Base
|
105
143
|
def initialize name
|
106
144
|
super
|
107
145
|
end
|
@@ -112,12 +150,13 @@ License example:
|
|
112
150
|
owns(user, Post)
|
113
151
|
end
|
114
152
|
end
|
115
|
-
</pre>
|
153
|
+
</code></pre>
|
116
154
|
|
117
|
-
|
155
|
+
Note: for some reason I had problems with markdown parsing the inheritance symbol "<" :(
|
118
156
|
|
119
|
-
|
120
|
-
|
157
|
+
Usage example:
|
158
|
+
<pre><code>
|
159
|
+
class GuestPermit - Permit::Base
|
121
160
|
def initialize(ability, options = {})
|
122
161
|
super
|
123
162
|
end
|
@@ -130,7 +169,7 @@ Usage example:
|
|
130
169
|
end
|
131
170
|
end
|
132
171
|
end
|
133
|
-
</pre>
|
172
|
+
</code></pre>
|
134
173
|
|
135
174
|
By convention the permits system will try to find a license named UserAdminLicense and BloggingLicense in this example and call enforce! on each license.
|
136
175
|
|
@@ -189,7 +228,9 @@ Please provide suggestions and feedback on how to improve this :)
|
|
189
228
|
The gem comes with the following generators
|
190
229
|
|
191
230
|
* cancan:permits
|
231
|
+
* cancan:permit
|
192
232
|
* cancan:licenses
|
233
|
+
* cancan:license
|
193
234
|
|
194
235
|
## Permits Generator
|
195
236
|
|
@@ -239,6 +280,40 @@ To get an understanding of what the generator generates for a Rails 3 applicatio
|
|
239
280
|
In the file <code>licenses_generator_spec.rb</code> make the following change <code>config.remove_temp_dir = false</code>
|
240
281
|
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.
|
241
282
|
|
283
|
+
## License Generator
|
284
|
+
|
285
|
+
<code>rails g cancan:license [NAME]</code>
|
286
|
+
|
287
|
+
Options
|
288
|
+
* --creates : The models that have 'creates' permission for the holder of this license
|
289
|
+
* --owns : The models that have 'owns' permission for the holder of this license
|
290
|
+
* --manages : The models that have 'manages' permission for the holder of this license
|
291
|
+
* --read : The models that have 'read' permission for the holder of this license
|
292
|
+
|
293
|
+
Run examples:
|
294
|
+
|
295
|
+
Generate licenses:
|
296
|
+
|
297
|
+
<code>$ rails g cancan:license blog_editing --owns article post --read blog --licenses blogging</code>
|
298
|
+
|
299
|
+
## Permit Generator
|
300
|
+
|
301
|
+
Generate a named permit
|
302
|
+
|
303
|
+
<code>rails g cancan:permit [ROLE]</code>
|
304
|
+
|
305
|
+
Options
|
306
|
+
* --creates : The models that have 'creates' permission for the holder of this license
|
307
|
+
* --owns : The models that have 'owns' permission for the holder of this license
|
308
|
+
* --manages : The models that have 'manages' permission for the holder of this license
|
309
|
+
* --read : The models that have 'read' permission for the holder of this license
|
310
|
+
|
311
|
+
Run examples:
|
312
|
+
|
313
|
+
Generate licenses:
|
314
|
+
|
315
|
+
<code>$ rails g cancan:permit editor --owns article post --read blog --licenses blog_editing</code>
|
316
|
+
|
242
317
|
# TODO ?
|
243
318
|
|
244
319
|
The Permits generator should attempt to attempt to uncover which roles are currently defined as available to the system (Generic Roles API, User#roles etc.) and generate permits for those roles. Any roles specified in the --roles option should be merged with the roles available in the app.
|
data/Rakefile
CHANGED
@@ -8,8 +8,8 @@ begin
|
|
8
8
|
gem.homepage = "http://github.com/kristianmandrup/cancan-permits"
|
9
9
|
gem.authors = ["Kristian Mandrup"]
|
10
10
|
gem.add_development_dependency "rspec", ">= 2.0.1"
|
11
|
-
gem.add_development_dependency 'code-spec', "~> 0.2.
|
12
|
-
gem.add_development_dependency 'rails-app-spec', "~> 0.3.
|
11
|
+
gem.add_development_dependency 'code-spec', "~> 0.2.9"
|
12
|
+
gem.add_development_dependency 'rails-app-spec', "~> 0.3.1"
|
13
13
|
|
14
14
|
gem.add_dependency 'cancan', "~> 1.4.1"
|
15
15
|
gem.add_dependency 'require_all', "~> 1.2.0"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/cancan-permits.gemspec
CHANGED
@@ -1,147 +1,153 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
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.4"
|
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{2010-11-
|
12
|
+
s.date = %q{2010-11-28}
|
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 = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.markdown"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
21
|
+
".rspec",
|
22
|
+
"Changelog.txt",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"cancan-permits.gemspec",
|
28
|
+
"development.sqlite3",
|
29
|
+
"lib/cancan-permits.rb",
|
30
|
+
"lib/cancan-permits/license/base_license.rb",
|
31
|
+
"lib/cancan-permits/main.rb",
|
32
|
+
"lib/cancan-permits/namespaces.rb",
|
33
|
+
"lib/cancan-permits/permit/base_permit.rb",
|
34
|
+
"lib/cancan-permits/permit/util.rb",
|
35
|
+
"lib/cancan-permits/permits/ability.rb",
|
36
|
+
"lib/cancan-permits/permits/configuration.rb",
|
37
|
+
"lib/cancan-permits/permits/roles.rb",
|
38
|
+
"lib/cancan-permits/rspec.rb",
|
39
|
+
"lib/cancan-permits/rspec/config.rb",
|
40
|
+
"lib/cancan-permits/rspec/matchers/have_license.rb",
|
41
|
+
"lib/cancan-permits/rspec/matchers/have_license_class.rb",
|
42
|
+
"lib/cancan-permits/rspec/matchers/have_license_file.rb",
|
43
|
+
"lib/generators/cancan/license/license_generator.rb",
|
44
|
+
"lib/generators/cancan/license/templates/license.rb",
|
45
|
+
"lib/generators/cancan/licenses/licenses_generator.rb",
|
46
|
+
"lib/generators/cancan/licenses/templates/base_license.rb",
|
47
|
+
"lib/generators/cancan/licenses/templates/blogging_license.rb",
|
48
|
+
"lib/generators/cancan/licenses/templates/user_admin_license.rb",
|
49
|
+
"lib/generators/cancan/permit/permit_generator.rb",
|
50
|
+
"lib/generators/cancan/permit/templates/role_permit.rb",
|
51
|
+
"lib/generators/cancan/permits/permits_generator.rb",
|
52
|
+
"lib/generators/cancan/permits/templates/permit.rb",
|
53
|
+
"spec/active_record/db/database.yml",
|
54
|
+
"spec/active_record/migrations/001_create_user.rb",
|
55
|
+
"spec/active_record/migrations/002_create_comment.rb",
|
56
|
+
"spec/active_record/migrations/003_create_post.rb",
|
57
|
+
"spec/active_record/migrations/004_create_article.rb",
|
58
|
+
"spec/active_record/models/all_models.rb",
|
59
|
+
"spec/active_record/owner_permits_spec.rb",
|
60
|
+
"spec/active_record/permits_spec.rb",
|
61
|
+
"spec/active_record/spec_helper.rb",
|
62
|
+
"spec/data_mapper/models/all_models.rb",
|
63
|
+
"spec/data_mapper/owner_permits_spec.rb",
|
64
|
+
"spec/data_mapper/permits_spec.rb",
|
65
|
+
"spec/data_mapper/spec_helper.rb",
|
66
|
+
"spec/fixtures/permits/admin_permit.rb",
|
67
|
+
"spec/fixtures/permits/any_permit.rb",
|
68
|
+
"spec/fixtures/permits/editor_permit.rb",
|
69
|
+
"spec/fixtures/permits/guest_permit.rb",
|
70
|
+
"spec/fixtures/permits/super_admin_permit.rb",
|
71
|
+
"spec/fixtures/permits/system_permit.rb",
|
72
|
+
"spec/generators/cancan/license_generator_spec.rb",
|
73
|
+
"spec/generators/cancan/licenses_generator_spec.rb",
|
74
|
+
"spec/generators/cancan/permit_generator_spec.rb",
|
75
|
+
"spec/generators/cancan/permits_generator_spec.rb",
|
76
|
+
"spec/generic/api/basic/config.rb",
|
77
|
+
"spec/generic/api/basic/xgroup.rb",
|
78
|
+
"spec/generic/api/basic/xgroup_orm.rb",
|
79
|
+
"spec/generic/api/owner/config.rb",
|
80
|
+
"spec/generic/api/owner/xgroup.rb",
|
81
|
+
"spec/generic/api/owner/xgroup_orm.rb",
|
82
|
+
"spec/generic/models/all_models.rb",
|
83
|
+
"spec/generic/owner_permits_spec.rb",
|
84
|
+
"spec/generic/permits_spec.rb",
|
85
|
+
"spec/generic/spec_helper.rb",
|
86
|
+
"spec/mongo_mapper/models/all_models.rb",
|
87
|
+
"spec/mongo_mapper/owner_permits_spec.rb",
|
88
|
+
"spec/mongo_mapper/permits_spec.rb",
|
89
|
+
"spec/mongo_mapper/spec_helper.rb",
|
90
|
+
"spec/mongoid/models/all_models.rb",
|
91
|
+
"spec/mongoid/owner_permits_spec.rb",
|
92
|
+
"spec/mongoid/permits_spec.rb",
|
93
|
+
"spec/mongoid/spec_helper.rb",
|
94
|
+
"spec/simply_stored/CouchDB.txt",
|
95
|
+
"spec/simply_stored/models/all_models.rb",
|
96
|
+
"spec/simply_stored/owner_permits_spec.rb",
|
97
|
+
"spec/simply_stored/permits_spec.rb",
|
98
|
+
"spec/simply_stored/spec_helper.rb",
|
99
|
+
"spec/spec_helper.rb"
|
95
100
|
]
|
96
101
|
s.homepage = %q{http://github.com/kristianmandrup/cancan-permits}
|
97
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
98
102
|
s.require_paths = ["lib"]
|
99
103
|
s.rubygems_version = %q{1.3.7}
|
100
104
|
s.summary = %q{Permits for use with CanCan}
|
101
105
|
s.test_files = [
|
102
106
|
"spec/active_record/migrations/001_create_user.rb",
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
107
|
+
"spec/active_record/migrations/002_create_comment.rb",
|
108
|
+
"spec/active_record/migrations/003_create_post.rb",
|
109
|
+
"spec/active_record/migrations/004_create_article.rb",
|
110
|
+
"spec/active_record/models/all_models.rb",
|
111
|
+
"spec/active_record/owner_permits_spec.rb",
|
112
|
+
"spec/active_record/permits_spec.rb",
|
113
|
+
"spec/active_record/spec_helper.rb",
|
114
|
+
"spec/data_mapper/models/all_models.rb",
|
115
|
+
"spec/data_mapper/owner_permits_spec.rb",
|
116
|
+
"spec/data_mapper/permits_spec.rb",
|
117
|
+
"spec/data_mapper/spec_helper.rb",
|
118
|
+
"spec/fixtures/permits/admin_permit.rb",
|
119
|
+
"spec/fixtures/permits/any_permit.rb",
|
120
|
+
"spec/fixtures/permits/editor_permit.rb",
|
121
|
+
"spec/fixtures/permits/guest_permit.rb",
|
122
|
+
"spec/fixtures/permits/super_admin_permit.rb",
|
123
|
+
"spec/fixtures/permits/system_permit.rb",
|
124
|
+
"spec/generators/cancan/license_generator_spec.rb",
|
125
|
+
"spec/generators/cancan/licenses_generator_spec.rb",
|
126
|
+
"spec/generators/cancan/permit_generator_spec.rb",
|
127
|
+
"spec/generators/cancan/permits_generator_spec.rb",
|
128
|
+
"spec/generic/api/basic/config.rb",
|
129
|
+
"spec/generic/api/basic/xgroup.rb",
|
130
|
+
"spec/generic/api/basic/xgroup_orm.rb",
|
131
|
+
"spec/generic/api/owner/config.rb",
|
132
|
+
"spec/generic/api/owner/xgroup.rb",
|
133
|
+
"spec/generic/api/owner/xgroup_orm.rb",
|
134
|
+
"spec/generic/models/all_models.rb",
|
135
|
+
"spec/generic/owner_permits_spec.rb",
|
136
|
+
"spec/generic/permits_spec.rb",
|
137
|
+
"spec/generic/spec_helper.rb",
|
138
|
+
"spec/mongo_mapper/models/all_models.rb",
|
139
|
+
"spec/mongo_mapper/owner_permits_spec.rb",
|
140
|
+
"spec/mongo_mapper/permits_spec.rb",
|
141
|
+
"spec/mongo_mapper/spec_helper.rb",
|
142
|
+
"spec/mongoid/models/all_models.rb",
|
143
|
+
"spec/mongoid/owner_permits_spec.rb",
|
144
|
+
"spec/mongoid/permits_spec.rb",
|
145
|
+
"spec/mongoid/spec_helper.rb",
|
146
|
+
"spec/simply_stored/models/all_models.rb",
|
147
|
+
"spec/simply_stored/owner_permits_spec.rb",
|
148
|
+
"spec/simply_stored/permits_spec.rb",
|
149
|
+
"spec/simply_stored/spec_helper.rb",
|
150
|
+
"spec/spec_helper.rb"
|
145
151
|
]
|
146
152
|
|
147
153
|
if s.respond_to? :specification_version then
|
@@ -150,8 +156,8 @@ Gem::Specification.new do |s|
|
|
150
156
|
|
151
157
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
152
158
|
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
153
|
-
s.add_development_dependency(%q<code-spec>, ["~> 0.2.
|
154
|
-
s.add_development_dependency(%q<rails-app-spec>, ["~> 0.3.
|
159
|
+
s.add_development_dependency(%q<code-spec>, ["~> 0.2.9"])
|
160
|
+
s.add_development_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
155
161
|
s.add_runtime_dependency(%q<cancan>, ["~> 1.4.1"])
|
156
162
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
157
163
|
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
@@ -160,8 +166,8 @@ Gem::Specification.new do |s|
|
|
160
166
|
s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.6"])
|
161
167
|
else
|
162
168
|
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
163
|
-
s.add_dependency(%q<code-spec>, ["~> 0.2.
|
164
|
-
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.
|
169
|
+
s.add_dependency(%q<code-spec>, ["~> 0.2.9"])
|
170
|
+
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
165
171
|
s.add_dependency(%q<cancan>, ["~> 1.4.1"])
|
166
172
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
167
173
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
@@ -171,8 +177,8 @@ Gem::Specification.new do |s|
|
|
171
177
|
end
|
172
178
|
else
|
173
179
|
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
174
|
-
s.add_dependency(%q<code-spec>, ["~> 0.2.
|
175
|
-
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.
|
180
|
+
s.add_dependency(%q<code-spec>, ["~> 0.2.9"])
|
181
|
+
s.add_dependency(%q<rails-app-spec>, ["~> 0.3.1"])
|
176
182
|
s.add_dependency(%q<cancan>, ["~> 1.4.1"])
|
177
183
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
178
184
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Permits::Roles
|
2
2
|
def self.available
|
3
|
-
if
|
4
|
-
|
5
|
-
|
3
|
+
if defined? ::Cream
|
4
|
+
Cream.available_roles
|
5
|
+
elsif defined? ::User
|
6
|
+
User.roles
|
6
7
|
else
|
7
|
-
[:
|
8
|
+
[:admin, :guest]
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'sugar-high/array'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'rails3_artifactor'
|
5
|
+
require 'logging_assist'
|
6
|
+
|
7
|
+
module Cancan
|
8
|
+
module Generators
|
9
|
+
class LicenseGenerator < Rails::Generators::Base
|
10
|
+
desc "Creates a License for a Permit in 'app/licenses' with reusable permissions"
|
11
|
+
|
12
|
+
argument :name, :type => :string, :default => '', :desc => "Name of license"
|
13
|
+
|
14
|
+
class_option :creates, :type => :array, :default => [], :desc => "Models allowed to create"
|
15
|
+
class_option :manages, :type => :array, :default => [], :desc => "Models allowed to manage"
|
16
|
+
class_option :reads, :type => :array, :default => [], :desc => "Models allowed to read"
|
17
|
+
class_option :owns, :type => :array, :default => [], :desc => "Models allowed to own"
|
18
|
+
|
19
|
+
class_option :licenses, :type => :array, :default => [], :desc => "Sub licenses"
|
20
|
+
|
21
|
+
source_root File.dirname(__FILE__) + '/templates'
|
22
|
+
|
23
|
+
def main_flow
|
24
|
+
return if name.empty?
|
25
|
+
create_license
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
include Rails3::Assist::BasicLogger
|
31
|
+
|
32
|
+
def creates
|
33
|
+
options[:creates]
|
34
|
+
end
|
35
|
+
|
36
|
+
def manages
|
37
|
+
options[:manages]
|
38
|
+
end
|
39
|
+
|
40
|
+
def licenses
|
41
|
+
options[:licenses]
|
42
|
+
end
|
43
|
+
|
44
|
+
def reads
|
45
|
+
options[:reads]
|
46
|
+
end
|
47
|
+
|
48
|
+
def owns
|
49
|
+
options[:owns]
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_license
|
53
|
+
template "license.rb", "app/licenses/#{name}_license.rb"
|
54
|
+
end
|
55
|
+
|
56
|
+
def enforce_logic
|
57
|
+
[:creates, :manages, :owns, :reads].map do |a|
|
58
|
+
options[a].map do |c|
|
59
|
+
"can(:#{a.to_s.singularize}, #{act_model(c)})"
|
60
|
+
end.join("\n ")
|
61
|
+
end.join("\n ")
|
62
|
+
end
|
63
|
+
|
64
|
+
def act_model name
|
65
|
+
return ':all' if name == 'all'
|
66
|
+
name.camelize
|
67
|
+
end
|
68
|
+
|
69
|
+
def license_logic
|
70
|
+
return '' if licenses.empty?
|
71
|
+
ls = licenses.map{|c| ":#{c}"}.join(", ")
|
72
|
+
"licenses #{ls}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -7,7 +7,7 @@ require 'logging_assist'
|
|
7
7
|
module Cancan
|
8
8
|
module Generators
|
9
9
|
class LicensesGenerator < Rails::Generators::Base
|
10
|
-
desc "Creates Licenses for use with CanCan
|
10
|
+
desc "Creates Licenses for use with CanCan Permits"
|
11
11
|
|
12
12
|
argument :licenses, :type => :array, :default => [], :desc => "Licenses"
|
13
13
|
class_option :default_licenses, :type => :boolean, :default => true, :desc => "Create default exemplar licenses"
|
@@ -27,9 +27,6 @@ module Cancan
|
|
27
27
|
protected
|
28
28
|
|
29
29
|
include Rails3::Assist::BasicLogger
|
30
|
-
extend Rails3::Assist::UseMacro
|
31
|
-
|
32
|
-
use_helpers :app, :file, :special
|
33
30
|
|
34
31
|
attr_accessor :license_name
|
35
32
|
|
@@ -47,7 +44,7 @@ module Cancan
|
|
47
44
|
|
48
45
|
def template_license name
|
49
46
|
self.license_name = name
|
50
|
-
template "
|
47
|
+
template "base_license.rb", "app/licenses/#{name}_license.rb"
|
51
48
|
end
|
52
49
|
|
53
50
|
def default_license name
|
File without changes
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'sugar-high/array'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'rails3_artifactor'
|
5
|
+
require 'logging_assist'
|
6
|
+
|
7
|
+
module Cancan
|
8
|
+
module Generators
|
9
|
+
class PermitGenerator < Rails::Generators::Base
|
10
|
+
desc "Creates a Permit for a role in 'app/permits' with specific permissions and/or licenses"
|
11
|
+
|
12
|
+
argument :role, :type => :string, :default => '', :desc => "Role to create permit for"
|
13
|
+
|
14
|
+
class_option :licenses, :type => :array, :default => [], :desc => "Licenses to use in Permit"
|
15
|
+
|
16
|
+
class_option :creates, :type => :array, :default => [], :desc => "Models allowed to create"
|
17
|
+
class_option :manages, :type => :array, :default => [], :desc => "Models allowed to manage"
|
18
|
+
class_option :reads, :type => :array, :default => [], :desc => "Models allowed to read"
|
19
|
+
class_option :owns, :type => :array, :default => [], :desc => "Models allowed to own"
|
20
|
+
|
21
|
+
source_root File.dirname(__FILE__) + '/templates'
|
22
|
+
|
23
|
+
def main_flow
|
24
|
+
return if role.empty?
|
25
|
+
template_permit
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
include Rails3::Assist::BasicLogger
|
31
|
+
|
32
|
+
def creates
|
33
|
+
options[:creates]
|
34
|
+
end
|
35
|
+
|
36
|
+
def manages
|
37
|
+
options[:manages]
|
38
|
+
end
|
39
|
+
|
40
|
+
def licenses
|
41
|
+
options[:licenses]
|
42
|
+
end
|
43
|
+
|
44
|
+
def reads
|
45
|
+
options[:reads]
|
46
|
+
end
|
47
|
+
|
48
|
+
def owns
|
49
|
+
options[:owns]
|
50
|
+
end
|
51
|
+
|
52
|
+
def template_permit
|
53
|
+
template "role_permit.rb", "app/permits/#{role}_permit.rb"
|
54
|
+
end
|
55
|
+
|
56
|
+
def act_model name
|
57
|
+
return ':all' if name == 'all'
|
58
|
+
name.camelize
|
59
|
+
end
|
60
|
+
|
61
|
+
def permit_logic
|
62
|
+
[:creates, :manages, :owns, :reads].map do |a|
|
63
|
+
options[a].map do |c|
|
64
|
+
"can(:#{a.to_s.singularize}, #{act_model(c)})"
|
65
|
+
end.join("\n ")
|
66
|
+
end.join("\n ")
|
67
|
+
end
|
68
|
+
|
69
|
+
def license_logic
|
70
|
+
return '' if licenses.empty?
|
71
|
+
ls = licenses.map{|c| ":#{c}"}.join(", ")
|
72
|
+
"licenses #{ls}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generator-spec'
|
3
|
+
|
4
|
+
require_generator :cancan => :license
|
5
|
+
|
6
|
+
RSpec::Generator.configure do |config|
|
7
|
+
config.debug = true
|
8
|
+
config.remove_temp_dir = true #false
|
9
|
+
config.default_rails_root(__FILE__)
|
10
|
+
config.lib = File.dirname(__FILE__) + '/../lib'
|
11
|
+
config.logger = :stdout # :file
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe 'License generator' do
|
16
|
+
use_helpers :special, :file
|
17
|
+
|
18
|
+
setup_generator :license do
|
19
|
+
tests Cancan::Generators::LicenseGenerator
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "License: Profile Administration" do
|
23
|
+
before :each do
|
24
|
+
@generator = with_generator do |g|
|
25
|
+
g.run_generator "profile_administration --owns article --reads all --licenses blogging".args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have created license files" do
|
30
|
+
@generator.should have_license_file :profile_administration
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generator-spec'
|
3
|
+
|
4
|
+
require_generator :cancan => :permit
|
5
|
+
|
6
|
+
RSpec::Generator.configure do |config|
|
7
|
+
config.debug = true
|
8
|
+
config.remove_temp_dir = true #false
|
9
|
+
config.default_rails_root(__FILE__)
|
10
|
+
config.lib = File.dirname(__FILE__) + '/../lib'
|
11
|
+
config.logger = :stdout # :file
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe 'Permit generator' do
|
16
|
+
use_helpers :special, :file
|
17
|
+
|
18
|
+
setup_generator :permit do
|
19
|
+
tests Cancan::Generators::PermitGenerator
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'Run Permit generator' do
|
23
|
+
before :each do
|
24
|
+
@generator = with_generator do |g|
|
25
|
+
g.run_generator "admin --owns article --reads all --licenses blogging user_admin".args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'result of running Permit generator' do
|
30
|
+
it "should create Admin permit" do
|
31
|
+
@generator.should generate_permit :admin
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
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
|
+
- 4
|
9
|
+
version: 0.3.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-28 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,8 +43,8 @@ dependencies:
|
|
43
43
|
segments:
|
44
44
|
- 0
|
45
45
|
- 2
|
46
|
-
-
|
47
|
-
version: 0.2.
|
46
|
+
- 9
|
47
|
+
version: 0.2.9
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
@@ -58,8 +58,8 @@ dependencies:
|
|
58
58
|
segments:
|
59
59
|
- 0
|
60
60
|
- 3
|
61
|
-
-
|
62
|
-
version: 0.3.
|
61
|
+
- 1
|
62
|
+
version: 0.3.1
|
63
63
|
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
@@ -163,7 +163,6 @@ extra_rdoc_files:
|
|
163
163
|
- README.markdown
|
164
164
|
files:
|
165
165
|
- .document
|
166
|
-
- .gitignore
|
167
166
|
- .rspec
|
168
167
|
- Changelog.txt
|
169
168
|
- LICENSE
|
@@ -186,10 +185,14 @@ files:
|
|
186
185
|
- lib/cancan-permits/rspec/matchers/have_license.rb
|
187
186
|
- lib/cancan-permits/rspec/matchers/have_license_class.rb
|
188
187
|
- lib/cancan-permits/rspec/matchers/have_license_file.rb
|
188
|
+
- lib/generators/cancan/license/license_generator.rb
|
189
|
+
- lib/generators/cancan/license/templates/license.rb
|
189
190
|
- lib/generators/cancan/licenses/licenses_generator.rb
|
191
|
+
- lib/generators/cancan/licenses/templates/base_license.rb
|
190
192
|
- lib/generators/cancan/licenses/templates/blogging_license.rb
|
191
|
-
- lib/generators/cancan/licenses/templates/license.rb
|
192
193
|
- lib/generators/cancan/licenses/templates/user_admin_license.rb
|
194
|
+
- lib/generators/cancan/permit/permit_generator.rb
|
195
|
+
- lib/generators/cancan/permit/templates/role_permit.rb
|
193
196
|
- lib/generators/cancan/permits/permits_generator.rb
|
194
197
|
- lib/generators/cancan/permits/templates/permit.rb
|
195
198
|
- spec/active_record/db/database.yml
|
@@ -211,7 +214,9 @@ files:
|
|
211
214
|
- spec/fixtures/permits/guest_permit.rb
|
212
215
|
- spec/fixtures/permits/super_admin_permit.rb
|
213
216
|
- spec/fixtures/permits/system_permit.rb
|
217
|
+
- spec/generators/cancan/license_generator_spec.rb
|
214
218
|
- spec/generators/cancan/licenses_generator_spec.rb
|
219
|
+
- spec/generators/cancan/permit_generator_spec.rb
|
215
220
|
- spec/generators/cancan/permits_generator_spec.rb
|
216
221
|
- spec/generic/api/basic/config.rb
|
217
222
|
- spec/generic/api/basic/xgroup.rb
|
@@ -242,8 +247,8 @@ homepage: http://github.com/kristianmandrup/cancan-permits
|
|
242
247
|
licenses: []
|
243
248
|
|
244
249
|
post_install_message:
|
245
|
-
rdoc_options:
|
246
|
-
|
250
|
+
rdoc_options: []
|
251
|
+
|
247
252
|
require_paths:
|
248
253
|
- lib
|
249
254
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -288,7 +293,9 @@ test_files:
|
|
288
293
|
- spec/fixtures/permits/guest_permit.rb
|
289
294
|
- spec/fixtures/permits/super_admin_permit.rb
|
290
295
|
- spec/fixtures/permits/system_permit.rb
|
296
|
+
- spec/generators/cancan/license_generator_spec.rb
|
291
297
|
- spec/generators/cancan/licenses_generator_spec.rb
|
298
|
+
- spec/generators/cancan/permit_generator_spec.rb
|
292
299
|
- spec/generators/cancan/permits_generator_spec.rb
|
293
300
|
- spec/generic/api/basic/config.rb
|
294
301
|
- spec/generic/api/basic/xgroup.rb
|