Class: Zuul::ActionController::DSL::Roles
Instance Attribute Summary
Attributes inherited from Base
#actions, #context, #default, #default_block_allow_rules, #default_block_deny_rules, #force_context, #mode, #permissions, #results, #roles, #scope, #subject_method
Instance Method Summary
collapse
Methods inherited from Actionable
#all, #allow?, #deny?
Methods inherited from Base
#all_actions, #all_permissions, #all_roles, #allow_permissions, #allow_roles, #anyone, #authorized?, #collect_results, #contextual_permission, #contextual_role, #deny_permissions, #deny_roles, #execute, #logged_in, #logged_out, #options, #parse_context, #set_options, #subject
Instance Method Details
#allow(*actions) ⇒ Object
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
# File 'lib/zuul/action_controller/dsl.rb', line 275
def allow(*actions)
log_timer_start = Time.now.to_f
actions = actions[0] if actions.length == 1 && actions[0].is_a?(Array)
actions.concat(@actions)
return if @roles.empty? || actions.empty?
if actions.map(&:to_sym).include?(@controller.params[:action].to_sym)
@roles.each do |role|
if (role == logged_out && subject.nil?) ||
(role == logged_in && !subject.nil?)
@results << true
return
end
next if subject.nil?
if allow?(role)
logger.debug " \e[1;33mACL (#{((Time.now.to_f - log_timer_start) * 1000.0).round(1)}ms)\e[0m \e[1mMATCH\e[0m for \e[32mallow\e[0m role \e[1m#{role.is_a?(subject.auth_scope(@scope).role_class) ? "#{role.slug}[#{role.context.to_s}]" : role}\e[0m"
@results << true
return
end
logger.debug " \e[1;33mACL (#{((Time.now.to_f - log_timer_start) * 1000.0).round(1)}ms)\e[0m \e[1mNO MATCH\e[0m for \e[32mallow\e[0m role \e[1m#{role.is_a?(subject.auth_scope(@scope).role_class) ? "#{role.slug}[#{role.context.to_s}]" : role}\e[0m"
end
end
end
|
#deny(*actions) ⇒ Object
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/zuul/action_controller/dsl.rb', line 300
def deny(*actions)
log_timer_start = Time.now.to_f
actions = actions[0] if actions.length == 1 && actions[0].is_a?(Array)
actions.concat(@actions)
return if @roles.empty? || actions.empty?
if actions.map(&:to_sym).include?(@controller.params[:action].to_sym)
@roles.each do |role|
if (role == logged_out && subject.nil?) ||
(role == logged_in && !subject.nil?)
@results << false
return
end
next if subject.nil?
if deny?(role)
logger.debug " \e[1;33mACL (#{((Time.now.to_f - log_timer_start) * 1000.0).round(1)}ms)\e[0m \e[1mMATCH\e[0m for \e[31mdeny\e[0m role \e[1m#{role.is_a?(subject.auth_scope(@scope).role_class) ? "#{role.slug}[#{role.context.to_s}]" : role}\e[0m"
@results << false
return
end
logger.debug " \e[1;33mACL (#{((Time.now.to_f - log_timer_start) * 1000.0).round(1)}ms)\e[0m \e[1mNO MATCH\e[0m for \e[31mdeny\e[0m role \e[1m#{role.is_a?(subject.auth_scope(@scope).role_class) ? "#{role.slug}[#{role.context.to_s}]" : role}\e[0m"
end
end
end
|
#match?(role) ⇒ Boolean
271
272
273
|
# File 'lib/zuul/action_controller/dsl.rb', line 271
def match?(role)
(@or_higher && subject.auth_scope(@scope, @context, @force_context) { |context, force_context| has_role_or_higher?(role, context.to_context, force_context) }) || (!@or_higher && subject.auth_scope(@scope, @context, @force_context) { |context, force_context| has_role?(role, context.to_context, force_context) })
end
|
#or_higher(&block) ⇒ Object
325
326
327
328
329
330
331
|
# File 'lib/zuul/action_controller/dsl.rb', line 325
def or_higher(&block)
opts = options.merge(:or_higher => true)
dsl = self.class.new(@controller, opts)
dsl.instance_eval(&block) if block_given?
@results.concat dsl.results
end
|