Class: Walruz::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/walruz/manager.rb

Overview

The objective of this class is to start the invocation of the authorization process, the methods of this class are used internally by the actor and subject classes.

Defined Under Namespace

Modules: AuthorizationQuery

Class Method Summary collapse

Class Method Details

.check_action_authorization(actor, action, subject) ⇒ Object

core method used on all the actor methods: can? authorize! authorize :private:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/walruz/manager.rb', line 70

def self.check_action_authorization(actor, action, subject)
  check_action_authorization_is_declared_on_subject(subject, action)
  action = if subject.class._walruz_policies.key?(:default)
            subject.class._walruz_policies.key?(action) ? action : :default
          else
            if subject.class._walruz_policies.key?(action)
              action
            else
              raise ActionNotFound.new(:subject_action, :subject => subject,
                                                        :action => action)
            end
          end

  begin
    result = subject.class._walruz_policies[action].
                          return_policy.
                          new.
                          safe_authorized?(actor, subject)
  rescue PolicyHalted => e
    result = [false, {:error_message => e.message }]
  end

  result
end

.check_policy_authorization(actor, policy_label, subject) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/walruz/manager.rb', line 95

def self.check_policy_authorization(actor, policy_label, subject)
  policy_clz = Walruz.fetch_policy(policy_label)

  begin
    result = policy_clz.return_policy.new.safe_authorized?(actor, subject)
  rescue PolicyHalted => e
    result = [false, { :error_message => e.message }]
  end

  result
end