Module: Authorization::OperatorMixin

Defined in:
lib/role-authz/authorization/operator_mixin.rb

Instance Method Summary collapse

Instance Method Details

#authorized?(args = {}) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/role-authz/authorization/operator_mixin.rb', line 2

def authorized?(args = {})
  @roles ||= Authorization.roles_for(self, args[:target])
  
  if args.key?(:role)
    return @roles.include?(args[:role])
  elsif args.key?(:target) && args.key?(:action)
    target = args[:target]._authorization_proxy unless args[:target]._authorization_proxy.nil?
    
    @roles.each do |role|
      actions = target._authorization.actions_for(role)
      return true if actions.include?(args[:action]) || actions.include?(:all)
    end
  end
  false
end

#roles_for(target) ⇒ Object



18
19
20
# File 'lib/role-authz/authorization/operator_mixin.rb', line 18

def roles_for(target)
  Authorization.roles_for(self, target)
end