cbac 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
data/cbac.gemspec
CHANGED
@@ -131,16 +131,20 @@ module Cbac
|
|
131
131
|
if context_role_name = line.match(/^.*ContextRole\(\s*([A-Za-z0-9_]+)\s*\)/)
|
132
132
|
# NOTE: the 0 for an ID is very important! In CBAC a context role permission MUST have 0 as generic_role_id
|
133
133
|
# if not, the context role is not found by CBAC and thus will not work
|
134
|
-
|
134
|
+
|
135
135
|
# this may be a context role that's already in the database
|
136
136
|
context_role = use_db ? PristineRole.first(:conditions => {:role_type => PristineRole.ROLE_TYPES[:context], :name => context_role_name.captures[0]}) : nil
|
137
|
-
|
137
|
+
|
138
138
|
# this may still be a context role we've seen before...
|
139
139
|
context_role = @context_roles.select do |cr| cr.role_type == PristineRole.ROLE_TYPES[:context] and cr.name == context_role_name.captures[0] end.first if context_role.nil?
|
140
|
-
|
141
|
-
if context_role.nil?
|
140
|
+
|
141
|
+
if context_role.nil?
|
142
142
|
# this is a never-before-seen context role
|
143
|
-
context_role = PristineRole.new
|
143
|
+
context_role = PristineRole.new do |role|
|
144
|
+
role.role_id = 0
|
145
|
+
role.role_type = PristineRole.ROLE_TYPES[:context]
|
146
|
+
role.name = context_role_name.captures[0]
|
147
|
+
end
|
144
148
|
context_role.save if use_db
|
145
149
|
@context_roles.push context_role
|
146
150
|
end
|
@@ -165,7 +169,11 @@ module Cbac
|
|
165
169
|
role = use_db ? PristineRole.first(:conditions => {:role_type => PristineRole.ROLE_TYPES[:generic], :name => generic_role.captures[0]}) : nil
|
166
170
|
|
167
171
|
if role.nil?
|
168
|
-
role =
|
172
|
+
role = PristineRole.new do |role|
|
173
|
+
role.role_id = @generic_roles.length + 2
|
174
|
+
role.role_type = PristineRole.ROLE_TYPES[:generic]
|
175
|
+
role.name = generic_role.captures[0]
|
176
|
+
end
|
169
177
|
role.save if use_db
|
170
178
|
end
|
171
179
|
|
@@ -9,7 +9,6 @@ module Cbac
|
|
9
9
|
{:context => "context", :generic => "generic", :admin => "administrator"}
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
12
|
#convert this cbac role to a yml statement which can be used to create a yml fixtures file
|
14
13
|
#executing this statement will result in one cbac_generic_role in the DB
|
15
14
|
def to_yml_fixture(fixture_id = nil)
|
@@ -36,7 +35,11 @@ module Cbac
|
|
36
35
|
def self.admin_role(use_db = true)
|
37
36
|
admin_role = use_db ? PristineRole.first(:conditions => {:role_type => PristineRole.ROLE_TYPES[:admin]}) : nil
|
38
37
|
|
39
|
-
admin_role
|
38
|
+
admin_role || PristineRole.new do |role|
|
39
|
+
role.role_id = 1
|
40
|
+
role.role_type = PristineRole.ROLE_TYPES[:admin]
|
41
|
+
role.name = "administrator"
|
42
|
+
end
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|