Exception: Bali::AuthorizationError

Inherits:
Error
  • Object
show all
Defined in:
lib/bali/foundations/exceptions/authorization_error.rb

Overview

Error that will be raised when subtarget cannot do something he wanted to do, or when subtarget do something he should not be allowed to do.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auth_levelObject

Returns the value of attribute auth_level.



5
6
7
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 5

def auth_level
  @auth_level
end

#operationObject

Returns the value of attribute operation.



4
5
6
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 4

def operation
  @operation
end

#roleObject

Returns the value of attribute role.



6
7
8
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 6

def role
  @role
end

#subtargetObject

it may be nil, depends on whether rule checking is using symbol/user



9
10
11
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 9

def subtarget
  @subtarget
end

#targetObject

whether a class or an object



12
13
14
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 12

def target
  @target
end

Instance Method Details

#target_proper_classObject



14
15
16
17
18
19
20
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 14

def target_proper_class
  if target.is_a?(Class)
    target
  else
    target.class
  end
end

#to_sObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bali/foundations/exceptions/authorization_error.rb', line 22

def to_s
  role = humanise_value(self.role)
  operation = humanise_value(self.operation)
  auth_level = humanise_value(self.auth_level)

  if auth_level == :can
    "Role #{role} is not allowed to perform operation `#{operation}` on #{target_proper_class}"
  else
    "Role #{role} is allowed to perform operation `#{operation}` on #{target_proper_class}"
  end
end