authorizer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/authorizer.rb +1 -1
- data/lib/authorizer/base.rb +55 -2
- metadata +4 -4
data/lib/authorizer.rb
CHANGED
data/lib/authorizer/base.rb
CHANGED
@@ -207,6 +207,55 @@ module Authorizer
|
|
207
207
|
end
|
208
208
|
|
209
209
|
protected
|
210
|
+
|
211
|
+
############################################################################
|
212
|
+
# get_topmost_class
|
213
|
+
############################################################################
|
214
|
+
# Get the topmost class for the given class, not going higher up the tree
|
215
|
+
# than ActiveRecord::Base or Object
|
216
|
+
############################################################################
|
217
|
+
|
218
|
+
def self.get_topmost_class(klazz)
|
219
|
+
raise "Please provide me with a Class object." unless klazz.is_a?(Class)
|
220
|
+
|
221
|
+
top_klazz = klazz
|
222
|
+
next_top_klazz = nil
|
223
|
+
|
224
|
+
begin
|
225
|
+
next_top_klazz = top_klazz.superclass
|
226
|
+
rescue
|
227
|
+
end
|
228
|
+
|
229
|
+
if next_top_klazz
|
230
|
+
until next_top_klazz.eql?(ActiveRecord::Base) || next_top_klazz.eql?(Object)
|
231
|
+
top_klazz = next_top_klazz
|
232
|
+
next_top_klazz = top_klazz.superclass
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
top_klazz
|
237
|
+
end
|
238
|
+
|
239
|
+
############################################################################
|
240
|
+
# array_of_string_subclasses
|
241
|
+
############################################################################
|
242
|
+
# Call the protected 'subclasses' method and convert all class names to string.
|
243
|
+
############################################################################
|
244
|
+
|
245
|
+
def self.array_of_string_subclasses(klazz)
|
246
|
+
raise "Need a Class object." unless klazz.is_a?(Class)
|
247
|
+
|
248
|
+
ret = []
|
249
|
+
|
250
|
+
for c in klazz.subclasses
|
251
|
+
ret.push(c.to_s)
|
252
|
+
end
|
253
|
+
|
254
|
+
# Also, we must include the class itself.
|
255
|
+
ret.push(klazz.to_s)
|
256
|
+
|
257
|
+
ret
|
258
|
+
end
|
210
259
|
|
211
260
|
############################################################################
|
212
261
|
# get_current_user
|
@@ -267,10 +316,14 @@ module Authorizer
|
|
267
316
|
# oooo ooo ooo ___ --- === __- --_- ++_+_ =--- +- =+=-=- =-= <--- ice beam!
|
268
317
|
unless klazz.nil?
|
269
318
|
# now we know klazz really exists.
|
319
|
+
# This class might be some subclass. Let's find out what the topmost class is.
|
320
|
+
topmost_class = get_topmost_class(klazz)
|
321
|
+
# Get an array that contains all subclasses of the topmost class
|
322
|
+
subclasses_of_topmost_class = array_of_string_subclasses(topmost_class)
|
270
323
|
# let's find the object_role objects that match the user and klazz.
|
271
324
|
# Get the object_role objects
|
272
|
-
object_roles_conditions = { :
|
273
|
-
object_roles = ObjectRole.
|
325
|
+
object_roles_conditions = { :user_id => user.id }
|
326
|
+
object_roles = ObjectRole.find_all_by_klazz_name(subclasses_of_topmost_class, :conditions => object_roles_conditions )
|
274
327
|
# OK.
|
275
328
|
# We already have the comprehensive list of object roles we are authorized on.
|
276
329
|
unless object_roles.nil?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authorizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- CmdJohnson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: options_checker
|