Module: Godmin::Authorization

Extended by:
ActiveSupport::Concern
Defined in:
lib/godmin/authorization.rb,
lib/godmin/authorization/policy.rb,
lib/godmin/authorization/policy_finder.rb

Defined Under Namespace

Classes: NotAuthorizedError, Policy, PolicyFinder

Instance Method Summary collapse

Instance Method Details

#authorize(record, query = nil) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/godmin/authorization.rb', line 16

def authorize(record, query = nil)
  policy = policy(record)

  unless policy.public_send(query || action_name + "?")
    fail NotAuthorizedError
  end
end

#policiesObject



28
29
30
# File 'lib/godmin/authorization.rb', line 28

def policies
  @_policies ||= {}
end

#policy(record) ⇒ Object



24
25
26
# File 'lib/godmin/authorization.rb', line 24

def policy(record)
  policies[record] ||= PolicyFinder.find(record, engine_wrapper.namespace).new(admin_user, record)
end