role_based_authorization 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.15
|
@@ -42,13 +42,27 @@ module RoleBasedAuthorization
|
|
42
42
|
url_options
|
43
43
|
end
|
44
44
|
|
45
|
+
|
46
|
+
# cleans options so that they are good to be passed to exists_matching_rule
|
47
|
+
def cleanup_options(opts)
|
48
|
+
opts.reverse_merge!( :user => current_user, :controller => controller_name, :ids => {} )
|
49
|
+
user, controller, action, ids = opts.values_at( :user, :controller, :action, :ids )
|
50
|
+
ids.reverse_merge!( opts.reject { |key,value| key.to_s !~ /(_id\Z)|(\Aid\Z)/ } )
|
51
|
+
|
52
|
+
{ :user => user,
|
53
|
+
:controllers => [controller,'application'],
|
54
|
+
:actions => [:all,action],
|
55
|
+
:ids => ids }
|
56
|
+
end
|
57
|
+
|
45
58
|
|
46
59
|
# Returns true if one of the rules defined for this controller matches
|
47
60
|
# the given options
|
48
61
|
def exists_matching_rule? options
|
49
62
|
rules = self.class.role_auth_rules
|
50
63
|
|
51
|
-
|
64
|
+
# !! is an idiom for transforming any value in true/false (e.g., !!nil is exactly false)
|
65
|
+
!!options[:controllers].find do |controller|
|
52
66
|
AUTHORIZATION_LOGGER.debug("current controller: %s" % [controller])
|
53
67
|
|
54
68
|
rules_for_controller = rules[controller]
|
@@ -71,22 +85,13 @@ module RoleBasedAuthorization
|
|
71
85
|
# exiting immediately if not logged in
|
72
86
|
return false if respond_to?(:logged_in?) && !logged_in?
|
73
87
|
|
74
|
-
|
75
|
-
user, controller, action, ids = opts.values_at( :user, :controller, :action, :ids )
|
76
|
-
ids.reverse_merge!( opts.reject { |key,value| key.to_s !~ /(_id\Z)|(\Aid\Z)/ } )
|
77
|
-
|
78
|
-
new_options = { :user => user,
|
79
|
-
:controllers => [controller,'application'],
|
80
|
-
:actions => [:all,action],
|
81
|
-
:ids => ids }
|
82
|
-
|
83
|
-
return exists_matching_rule?( new_options ) != nil
|
88
|
+
exists_matching_rule?( cleanup_options(opts) )
|
84
89
|
end
|
85
90
|
|
86
91
|
# wraps some logging around do_authorize_action?.
|
87
92
|
def authorize_action? opts = {}
|
88
93
|
AUTHORIZATION_LOGGER.info("access request. options: %s" % [opts.inspect])
|
89
|
-
result = do_authorize_action?
|
94
|
+
result = do_authorize_action?(opts)
|
90
95
|
AUTHORIZATION_LOGGER.info("returning #{result}")
|
91
96
|
|
92
97
|
return result
|