cantango-core 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +7 -1
- data/Gemfile.lock +70 -12
- data/README.mdown +16 -14
- data/VERSION +1 -1
- data/cantango-core.gemspec +41 -51
- data/lib/cantango/ability/base/callbacks.rb +37 -0
- data/lib/cantango/ability/base.rb +21 -8
- data/lib/cantango/ability/cache.rb +1 -1
- data/lib/cantango/ability/executor/modes.rb +6 -6
- data/lib/cantango/ability/executor/no_cache_mode.rb +2 -6
- data/lib/cantango/ability/executor.rb +1 -1
- data/lib/cantango/ability/helper/account.rb +6 -10
- data/lib/cantango/ability/helper/engine.rb +22 -26
- data/lib/cantango/ability/helper/user.rb +10 -14
- data/lib/cantango/ability/helper.rb +1 -1
- data/lib/cantango/ability.rb +7 -2
- data/lib/cantango/adaptor/active_record.rb +6 -0
- data/lib/cantango/adaptor/data_mapper.rb +5 -0
- data/lib/cantango/adaptor/generic.rb +12 -0
- data/lib/cantango/adaptor/mongo.rb +13 -0
- data/lib/cantango/adaptor/mongo_mapper.rb +5 -0
- data/lib/cantango/adaptor/mongoid.rb +5 -0
- data/lib/cantango/adaptor/relational.rb +8 -0
- data/lib/cantango/{rules/adaptor.rb → adaptor.rb} +4 -4
- data/lib/cantango/{rules → cancan}/rule_class.rb +1 -1
- data/lib/cantango/cancan.rb +5 -0
- data/lib/cantango/core.rb +5 -13
- data/lib/cantango/engine.rb +6 -16
- data/lib/cantango/filter/base.rb +1 -1
- data/lib/cantango/helpers/debug.rb +31 -1
- data/lib/cantango/loader/yaml.rb +2 -11
- data/lib/cantango/model/guest.rb +3 -1
- data/spec/cantango/ability/base_spec.rb +13 -63
- data/spec/cantango/ability/cache/simple_key_spec.rb +29 -0
- data/spec/cantango/ability/executor/base_spec.rb +12 -52
- data/spec/cantango/ability/executor/custom_spec.rb +51 -0
- data/spec/cantango/ability/executor/modes_spec.rb +27 -49
- data/spec/cantango/ability/executor/no_cache_mode_spec.rb +29 -0
- data/spec/cantango/ability/helper/account_spec.rb +37 -0
- data/spec/cantango/ability/helper/engine_spec.rb +36 -0
- data/spec/cantango/ability/helper/user_spec.rb +38 -0
- data/spec/cantango/adaptor/active_record_spec.rb +38 -0
- data/spec/cantango/adaptor/data_mapper_spec.rb +39 -0
- data/spec/cantango/{rules/adaptor → adaptor}/mongo_mapper_spec.rb +0 -0
- data/spec/cantango/{rules/adaptor → adaptor}/mongoid_spec.rb +0 -0
- data/spec/cantango/cancan/rule_spec.rb +5 -0
- data/spec/cantango/core_spec.rb +0 -2
- data/spec/cantango/engine_spec.rb +51 -0
- data/spec/cantango/filter/base_spec.rb +25 -0
- data/spec/cantango/helpers/debug_spec.rb +29 -0
- data/spec/cantango/loader/yaml_spec.rb +5 -0
- data/spec/cantango/model/guest_spec.rb +14 -0
- data/spec/cantango/rspec/be_allowed_to_spec.rb +5 -0
- data/spec/cantango/scope/ability_spec.rb +33 -0
- data/spec/fixtures/models/account.rb +7 -0
- data/spec/fixtures/models/admin.rb +2 -0
- data/spec/fixtures/models/admin_account.rb +8 -0
- data/spec/fixtures/models/items.rb +11 -0
- data/spec/fixtures/models/user.rb +20 -0
- data/spec/fixtures/models.rb +2 -0
- data/spec/spec_helper.rb +4 -0
- metadata +60 -67
- data/lib/cantango/ability/executor/cache_mode.rb +0 -33
- data/lib/cantango/ability/helper/role.rb +0 -21
- data/lib/cantango/ability/helper/role_group.rb +0 -21
- data/lib/cantango/macros/account.rb +0 -14
- data/lib/cantango/macros/user.rb +0 -16
- data/lib/cantango/macros.rb +0 -11
- data/lib/cantango/rules/adaptor/active_record.rb +0 -10
- data/lib/cantango/rules/adaptor/data_mapper.rb +0 -11
- data/lib/cantango/rules/adaptor/generic.rb +0 -16
- data/lib/cantango/rules/adaptor/mongo.rb +0 -19
- data/lib/cantango/rules/adaptor/mongo_mapper.rb +0 -10
- data/lib/cantango/rules/adaptor/mongoid.rb +0 -9
- data/lib/cantango/rules/adaptor/relational.rb +0 -13
- data/lib/cantango/rules/dsl.rb +0 -24
- data/lib/cantango/rules/relation.rb +0 -67
- data/lib/cantango/rules/scope.rb +0 -24
- data/lib/cantango/rules.rb +0 -8
- data/spec/cantango/ability/cached_spec.rb +0 -0
- data/spec/cantango/ability/executor/base2.rb +0 -75
- data/spec/cantango/ability/executor/cache_mode_spec.rb +0 -77
- data/spec/cantango/macros/account_spec.rb +0 -0
- data/spec/cantango/macros/user_spec.rb +0 -0
- data/spec/cantango/rules/adaptor/active_record_spec.rb +0 -0
- data/spec/cantango/rules/adaptor/data_mapper_spec.rb +0 -0
- data/spec/cantango/rules/adaptor_spec.rb +0 -0
- data/spec/cantango/rules/dsl_spec.rb +0 -0
- data/spec/cantango/rules/relation_spec.rb +0 -0
- data/spec/cantango/rules/rule_class_spec.rb +0 -0
- data/spec/cantango/rules/scope_spec.rb +0 -0
- data/spec/cantango/rules_spec.rb +0 -55
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cantango-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-12-01 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &914770100 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.0.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *914770100
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cancan
|
28
|
-
requirement: &
|
28
|
+
requirement: &914769860 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '1.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *914769860
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: sugar-high
|
39
|
-
requirement: &
|
39
|
+
requirement: &914769620 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,21 +44,21 @@ dependencies:
|
|
44
44
|
version: 0.6.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *914769620
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: sweetloader
|
50
|
-
requirement: &
|
50
|
+
requirement: &914769380 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.1.
|
55
|
+
version: 0.1.5
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *914769380
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: hashie
|
61
|
-
requirement: &
|
61
|
+
requirement: &914769140 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *914769140
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec-rails
|
72
|
-
requirement: &
|
72
|
+
requirement: &914768900 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 2.6.1
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *914768900
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: forgery
|
83
|
-
requirement: &
|
83
|
+
requirement: &914768660 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0.3'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *914768660
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: factory_girl
|
94
|
-
requirement: &
|
94
|
+
requirement: &914768420 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *914768420
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: sqlite3
|
105
|
-
requirement: &
|
105
|
+
requirement: &914768150 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *914768150
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rspec
|
116
|
-
requirement: &
|
116
|
+
requirement: &914767910 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: 2.6.0
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *914767910
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: jeweler
|
127
|
-
requirement: &
|
127
|
+
requirement: &914767660 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ! '>='
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: 1.6.4
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *914767660
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: bundler
|
138
|
-
requirement: &
|
138
|
+
requirement: &914767420 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ! '>='
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: 1.1.rc
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *914767420
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: rdoc
|
149
|
-
requirement: &
|
149
|
+
requirement: &914767180 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ! '>='
|
@@ -154,10 +154,10 @@ dependencies:
|
|
154
154
|
version: '0'
|
155
155
|
type: :development
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *914767180
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: rake
|
160
|
-
requirement: &
|
160
|
+
requirement: &914766940 !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
version: 0.9.2.2
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
|
-
version_requirements: *
|
168
|
+
version_requirements: *914766940
|
169
169
|
description: ! 'Define your permission rules as role- or role group specific permits.
|
170
170
|
|
171
171
|
Integrates well with multiple Devise user acounts.
|
@@ -191,20 +191,28 @@ files:
|
|
191
191
|
- cantango-core.gemspec
|
192
192
|
- lib/cantango/ability.rb
|
193
193
|
- lib/cantango/ability/base.rb
|
194
|
+
- lib/cantango/ability/base/callbacks.rb
|
194
195
|
- lib/cantango/ability/cache.rb
|
195
196
|
- lib/cantango/ability/cache/simple_key.rb
|
196
197
|
- lib/cantango/ability/executor.rb
|
197
198
|
- lib/cantango/ability/executor/base.rb
|
198
|
-
- lib/cantango/ability/executor/cache_mode.rb
|
199
199
|
- lib/cantango/ability/executor/modes.rb
|
200
200
|
- lib/cantango/ability/executor/no_cache_mode.rb
|
201
201
|
- lib/cantango/ability/helper.rb
|
202
202
|
- lib/cantango/ability/helper/account.rb
|
203
203
|
- lib/cantango/ability/helper/engine.rb
|
204
|
-
- lib/cantango/ability/helper/role.rb
|
205
|
-
- lib/cantango/ability/helper/role_group.rb
|
206
204
|
- lib/cantango/ability/helper/user.rb
|
205
|
+
- lib/cantango/adaptor.rb
|
206
|
+
- lib/cantango/adaptor/active_record.rb
|
207
|
+
- lib/cantango/adaptor/data_mapper.rb
|
208
|
+
- lib/cantango/adaptor/generic.rb
|
209
|
+
- lib/cantango/adaptor/mongo.rb
|
210
|
+
- lib/cantango/adaptor/mongo_mapper.rb
|
211
|
+
- lib/cantango/adaptor/mongoid.rb
|
212
|
+
- lib/cantango/adaptor/relational.rb
|
213
|
+
- lib/cantango/cancan.rb
|
207
214
|
- lib/cantango/cancan/rule.rb
|
215
|
+
- lib/cantango/cancan/rule_class.rb
|
208
216
|
- lib/cantango/core.rb
|
209
217
|
- lib/cantango/engine.rb
|
210
218
|
- lib/cantango/filter.rb
|
@@ -213,28 +221,12 @@ files:
|
|
213
221
|
- lib/cantango/helpers/debug.rb
|
214
222
|
- lib/cantango/loader.rb
|
215
223
|
- lib/cantango/loader/yaml.rb
|
216
|
-
- lib/cantango/macros.rb
|
217
|
-
- lib/cantango/macros/account.rb
|
218
|
-
- lib/cantango/macros/user.rb
|
219
224
|
- lib/cantango/model.rb
|
220
225
|
- lib/cantango/model/guest.rb
|
221
226
|
- lib/cantango/rspec.rb
|
222
227
|
- lib/cantango/rspec/config.rb
|
223
228
|
- lib/cantango/rspec/matchers.rb
|
224
229
|
- lib/cantango/rspec/matchers/be_allowed_to.rb
|
225
|
-
- lib/cantango/rules.rb
|
226
|
-
- lib/cantango/rules/adaptor.rb
|
227
|
-
- lib/cantango/rules/adaptor/active_record.rb
|
228
|
-
- lib/cantango/rules/adaptor/data_mapper.rb
|
229
|
-
- lib/cantango/rules/adaptor/generic.rb
|
230
|
-
- lib/cantango/rules/adaptor/mongo.rb
|
231
|
-
- lib/cantango/rules/adaptor/mongo_mapper.rb
|
232
|
-
- lib/cantango/rules/adaptor/mongoid.rb
|
233
|
-
- lib/cantango/rules/adaptor/relational.rb
|
234
|
-
- lib/cantango/rules/dsl.rb
|
235
|
-
- lib/cantango/rules/relation.rb
|
236
|
-
- lib/cantango/rules/rule_class.rb
|
237
|
-
- lib/cantango/rules/scope.rb
|
238
230
|
- lib/cantango/scope.rb
|
239
231
|
- lib/cantango/scope/ability.rb
|
240
232
|
- lib/generators/cantango/install/install_generator.rb
|
@@ -242,33 +234,34 @@ files:
|
|
242
234
|
- lib/generators/cantango/install/templates/categories.yml
|
243
235
|
- lib/generators/cantango/install/templates/permissions.yml
|
244
236
|
- spec/cantango/ability/base_spec.rb
|
245
|
-
- spec/cantango/ability/
|
246
|
-
- spec/cantango/ability/executor/base2.rb
|
237
|
+
- spec/cantango/ability/cache/simple_key_spec.rb
|
247
238
|
- spec/cantango/ability/executor/base_spec.rb
|
248
|
-
- spec/cantango/ability/executor/
|
239
|
+
- spec/cantango/ability/executor/custom_spec.rb
|
249
240
|
- spec/cantango/ability/executor/modes_spec.rb
|
250
241
|
- spec/cantango/ability/executor/no_cache_mode_spec.rb
|
242
|
+
- spec/cantango/ability/helper/account_spec.rb
|
243
|
+
- spec/cantango/ability/helper/engine_spec.rb
|
244
|
+
- spec/cantango/ability/helper/user_spec.rb
|
245
|
+
- spec/cantango/adaptor/active_record_spec.rb
|
246
|
+
- spec/cantango/adaptor/data_mapper_spec.rb
|
247
|
+
- spec/cantango/adaptor/mongo_mapper_spec.rb
|
248
|
+
- spec/cantango/adaptor/mongoid_spec.rb
|
251
249
|
- spec/cantango/cancan/rule_spec.rb
|
252
250
|
- spec/cantango/core_spec.rb
|
253
251
|
- spec/cantango/engine_spec.rb
|
254
252
|
- spec/cantango/filter/base_spec.rb
|
255
253
|
- spec/cantango/helpers/debug_spec.rb
|
256
254
|
- spec/cantango/loader/yaml_spec.rb
|
257
|
-
- spec/cantango/
|
258
|
-
- spec/cantango/macros/user_spec.rb
|
255
|
+
- spec/cantango/model/guest_spec.rb
|
259
256
|
- spec/cantango/rspec/be_allowed_to_spec.rb
|
260
|
-
- spec/cantango/rules/adaptor/active_record_spec.rb
|
261
|
-
- spec/cantango/rules/adaptor/data_mapper_spec.rb
|
262
|
-
- spec/cantango/rules/adaptor/mongo_mapper_spec.rb
|
263
|
-
- spec/cantango/rules/adaptor/mongoid_spec.rb
|
264
|
-
- spec/cantango/rules/adaptor_spec.rb
|
265
|
-
- spec/cantango/rules/dsl_spec.rb
|
266
|
-
- spec/cantango/rules/relation_spec.rb
|
267
|
-
- spec/cantango/rules/rule_class_spec.rb
|
268
|
-
- spec/cantango/rules/scope_spec.rb
|
269
|
-
- spec/cantango/rules_spec.rb
|
270
257
|
- spec/cantango/scope/ability_spec.rb
|
271
258
|
- spec/cantango_spec.rb
|
259
|
+
- spec/fixtures/models.rb
|
260
|
+
- spec/fixtures/models/account.rb
|
261
|
+
- spec/fixtures/models/admin.rb
|
262
|
+
- spec/fixtures/models/admin_account.rb
|
263
|
+
- spec/fixtures/models/items.rb
|
264
|
+
- spec/fixtures/models/user.rb
|
272
265
|
- spec/generators/cantango/install_generator_spec.rb
|
273
266
|
- spec/spec_helper.rb
|
274
267
|
homepage: http://github.com/kristianmandrup/cantango
|
@@ -286,7 +279,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
286
279
|
version: '0'
|
287
280
|
segments:
|
288
281
|
- 0
|
289
|
-
hash:
|
282
|
+
hash: 472570963
|
290
283
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
291
284
|
none: false
|
292
285
|
requirements:
|
@@ -295,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
288
|
version: '0'
|
296
289
|
requirements: []
|
297
290
|
rubyforge_project:
|
298
|
-
rubygems_version: 1.8.
|
291
|
+
rubygems_version: 1.8.10
|
299
292
|
signing_key:
|
300
293
|
specification_version: 3
|
301
294
|
summary: CanCan extension with role oriented permission management and more
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
class Ability
|
3
|
-
module Executor
|
4
|
-
class CachedMode < Base
|
5
|
-
include CanTango::Ability::CacheHelpers
|
6
|
-
|
7
|
-
# FIX! no reason for double cache check!
|
8
|
-
def cached?
|
9
|
-
@rules = cached_rules if cached_rules? && caching_on?
|
10
|
-
end
|
11
|
-
|
12
|
-
def cache
|
13
|
-
@cache ||= cache_class.new self, :cache_key => cache_key, :key_method_names => key_method_names
|
14
|
-
end
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def cache_class
|
19
|
-
CanTango::Ability::Cache
|
20
|
-
end
|
21
|
-
|
22
|
-
def start_execute
|
23
|
-
debug "Executing cached ability"
|
24
|
-
end
|
25
|
-
|
26
|
-
def end_execute
|
27
|
-
cache_rules! if caching_on?
|
28
|
-
debug "DONE"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
class Ability
|
3
|
-
module Helper
|
4
|
-
module Role
|
5
|
-
include CanTango::Helpers::RoleMethods
|
6
|
-
|
7
|
-
# return list roles the user has
|
8
|
-
def roles
|
9
|
-
return [] if !subject.respond_to?(roles_list_meth) || roles_of(subject).blank?
|
10
|
-
roles_of(subject).flatten
|
11
|
-
end
|
12
|
-
|
13
|
-
protected
|
14
|
-
|
15
|
-
def roles_of subject
|
16
|
-
@subj_roles ||= subject.send(roles_list_meth)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
class Ability
|
3
|
-
module Helper
|
4
|
-
module RoleGroup
|
5
|
-
include CanTango::Helpers::RoleMethods
|
6
|
-
|
7
|
-
# return list of symbols for role groups the user belongs to
|
8
|
-
def role_groups
|
9
|
-
return [] if !subject.respond_to?(role_groups_list_meth) || role_groups_of(subject).blank?
|
10
|
-
role_groups_of(subject).flatten
|
11
|
-
end
|
12
|
-
|
13
|
-
protected
|
14
|
-
|
15
|
-
def role_groups_of subject
|
16
|
-
@subj_role_groups ||= subject.send(role_groups_list_meth)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module CanTango::Macros
|
2
|
-
module Account
|
3
|
-
def tango_user_account options = {}
|
4
|
-
self.send :include, CanTango::AccountApi
|
5
|
-
|
6
|
-
if defined? CanTango::Macros::Masquerader
|
7
|
-
self.send :include, CanTango::Macros::Masquerader
|
8
|
-
masquerader if options[:masquerade]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
alias_method :tango_account, :tango_user_account
|
12
|
-
alias_method :cantango_account, :tango_user_account
|
13
|
-
end
|
14
|
-
end
|
data/lib/cantango/macros/user.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module CanTango::Macros
|
2
|
-
module User
|
3
|
-
def tango_user options = {}
|
4
|
-
self.send :include, CanTango::UserApi
|
5
|
-
self.send :include, CanTango::Masquerade::UserApi
|
6
|
-
masquerader if options[:masquerade]
|
7
|
-
end
|
8
|
-
alias_method :cantango_user, :tango_user
|
9
|
-
|
10
|
-
module Masquerader
|
11
|
-
def masquerader
|
12
|
-
self.send :include, CanTango::Masquerade::UserApi
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/cantango/macros.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
module Rules
|
3
|
-
module Adaptor
|
4
|
-
module Generic
|
5
|
-
|
6
|
-
def attribute_condition attribute, user_scope
|
7
|
-
Proc.new { |model| model.send(attribute) == user_scope }
|
8
|
-
end
|
9
|
-
|
10
|
-
def include_condition attribute, user_scope
|
11
|
-
Proc.new { |model| model.send(attribute).include? user_scope }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
module Rules
|
3
|
-
module Adaptor
|
4
|
-
module Mongo
|
5
|
-
#include CanTango::Rules::Adaptor::Generic
|
6
|
-
# using #in on Hash (Mongoid query)
|
7
|
-
def include_condition attribute, user_scope
|
8
|
-
{ attribute.to_sym.in => user_scope.send(attribute) }
|
9
|
-
end
|
10
|
-
|
11
|
-
def attribute_condition attribute, user_scope
|
12
|
-
{ attribute.to_sym => user_scope.send(attribute) }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
module Rules
|
3
|
-
module Adaptor
|
4
|
-
module Relational
|
5
|
-
def attribute_condition attribute, user_scope
|
6
|
-
{ attribute.to_sym => user_scope.send(attribute) }
|
7
|
-
end
|
8
|
-
alias_method :include_condition, :attribute_condition
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
data/lib/cantango/rules/dsl.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
module Rules
|
3
|
-
module Dsl
|
4
|
-
def self.included(base)
|
5
|
-
::CanTango.config.user.relations.each do |relationship|
|
6
|
-
base.class_eval %{
|
7
|
-
def #{relationship}_of *models, &block
|
8
|
-
options = models.extract_options!
|
9
|
-
scope = options[:scope] || :user_account
|
10
|
-
relation = UserRelation.new :#{relationship}, self, scope, *models, &block
|
11
|
-
yield relation if block
|
12
|
-
relation
|
13
|
-
end
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# creates a scope that enforces either using the user or user_account for determining relationship matches on the models
|
19
|
-
def scope name, &block
|
20
|
-
yield CanTango::Rules::Scope.new name, self, &block
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'active_support/inflector'
|
2
|
-
|
3
|
-
module CanTango
|
4
|
-
module Rules
|
5
|
-
class Relation
|
6
|
-
attr_reader :attribute, :permit, :scope, :models
|
7
|
-
|
8
|
-
include CanTango::Rules::Adaptor
|
9
|
-
include CanTango::Rules::RuleClass
|
10
|
-
|
11
|
-
def initialize attribute, permit, scope, *models, &block
|
12
|
-
@attribute = attribute
|
13
|
-
@scope = scope
|
14
|
-
@permit = permit
|
15
|
-
@models = models
|
16
|
-
|
17
|
-
check_models
|
18
|
-
use_adaptor! self, user_scope
|
19
|
-
end
|
20
|
-
|
21
|
-
def can(action)
|
22
|
-
models.each do |model|
|
23
|
-
rules << rule_class.new(true, action, model, nil, condition_block(model))
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def cannot(action)
|
28
|
-
models.each do |model|
|
29
|
-
rules << rule_class.new(false, action, model, nil, condition_block(model))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
def condition_block model
|
36
|
-
return attribute_condition(attribute, user_scope) if model.new.respond_to?(attribute)
|
37
|
-
return include_condition(plural_attribute, user_scope) if model.new.respond_to?(plural_attribute)
|
38
|
-
end
|
39
|
-
|
40
|
-
def user_scope
|
41
|
-
@user_scope ||= (scope == :account) ? permit.user_account : permit.user
|
42
|
-
end
|
43
|
-
|
44
|
-
def scope_key
|
45
|
-
@scope_key ||= (scope == :account) ? :user_account : :user
|
46
|
-
end
|
47
|
-
|
48
|
-
def ability
|
49
|
-
permit.ability
|
50
|
-
end
|
51
|
-
|
52
|
-
def rules
|
53
|
-
ability.send :rules
|
54
|
-
end
|
55
|
-
|
56
|
-
def plural_attribute
|
57
|
-
:"#{attribute.to_s.pluralize}"
|
58
|
-
end
|
59
|
-
|
60
|
-
def check_models
|
61
|
-
models.each do |model|
|
62
|
-
raise "#{model} has no :#{attribute} or :#{plural_attribute} defined" if !model.new.respond_to?(attribute) && !model.new.respond_to?(plural_attribute)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/lib/cantango/rules/scope.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module CanTango
|
2
|
-
module Rules
|
3
|
-
class Scope
|
4
|
-
attr_reader :name, :permit
|
5
|
-
|
6
|
-
def initialize name, permit, &block
|
7
|
-
@name = name.to_sym
|
8
|
-
@permit = permit
|
9
|
-
end
|
10
|
-
|
11
|
-
::CanTango.config.user.relations.each do |relationship|
|
12
|
-
base.class_eval %{
|
13
|
-
def #{relationship}_of *models, &block
|
14
|
-
options = models.extract_options!
|
15
|
-
scope = options[:scope] || name
|
16
|
-
relation = UserRelation.new :#{relationship}, permit, scope, models, &block
|
17
|
-
yield relation if block
|
18
|
-
relation
|
19
|
-
end
|
20
|
-
}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/cantango/rules.rb
DELETED
File without changes
|