Module: Walruz::Manager::AuthorizationQuery

Included in:
Walruz, Actor
Defined in:
lib/walruz/manager.rb

Instance Method Summary collapse

Instance Method Details

#authorize(actor, action, subject) ⇒ Object



26
27
28
29
30
31
# File 'lib/walruz/manager.rb', line 26

def authorize(actor, action, subject)
  result = Walruz::Manager.check_action_authorization(actor,
                                                      action,
                                                      subject)
  result[0] ? result[1] : nil
end

#authorize!(actor, action, subject) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/walruz/manager.rb', line 15

def authorize!(actor, action, subject)
  result = Walruz::Manager.check_action_authorization(actor, action, subject)
  if result[0]
    result[1]
  else
    response_params = result[1]
    error_message   = response_params[:error_message] || "You are not authorized to access this content"
    raise NotAuthorized.new(actor, subject, action, error_message)
  end
end

#can?(actor, action, subject) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/walruz/manager.rb', line 11

def can?(actor, action, subject)
  Walruz::Manager.check_action_authorization(actor, action, subject)[0]
end

#satisfies(actor, policy_label, subject) ⇒ Object



40
41
42
43
44
45
# File 'lib/walruz/manager.rb', line 40

def satisfies(actor, policy_label, subject)
  result = Walruz::Manager.check_policy_authorization(actor,
                                                      policy_label,
                                                      subject)
  result[0] ? result[1] : nil
end

#satisfies!(actor, policy_label, subject) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/walruz/manager.rb', line 47

def satisfies!(actor, policy_label, subject)
  result = Walruz::Manager.check_policy_authorization(actor,
                                                      policy_label,
                                                      subject)
  if result[0]
    result[1]
  else
    response_params = result[1]
    error_message = response_params[:error_message] ||
     "You are not authorized to access this content"
    raise NotAuthorized.new(actor, subject, :access, error_message)
  end
end

#satisfies?(actor, policy_label, subject) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/walruz/manager.rb', line 33

def satisfies?(actor, policy_label, subject)
  result = Walruz::Manager.check_policy_authorization(actor,
                                                      policy_label,
                                                      subject)
  result[0]
end