Class: ActiveAdmin::PunditAdapter
Instance Attribute Summary
#resource, #user
Instance Method Summary
collapse
#initialize
Instance Method Details
#authorized?(action, subject = nil) ⇒ Boolean
7
8
9
10
11
12
|
# File 'lib/active_admin/pundit_adapter.rb', line 7
def authorized?(action, subject = nil)
policy = retreive_policy(subject)
action = format_action(action, subject)
policy.class.method_defined?(action) && policy.send(action)
end
|
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/active_admin/pundit_adapter.rb', line 29
def format_action(action, subject)
case action
when Auth::CREATE then :create?
when Auth::UPDATE then :update?
when Auth::READ then subject.is_a?(Class) ? :index? : :show?
when Auth::DESTROY then subject.is_a?(Class) ? :destroy_all? : :destroy?
else "#{action}?"
end
end
|
#retreive_policy(subject) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/active_admin/pundit_adapter.rb', line 21
def retreive_policy(subject)
case subject
when nil then Pundit.policy!(user, resource)
when Class then Pundit.policy!(user, subject.new)
else Pundit.policy!(user, subject)
end
end
|
#scope_collection(collection, action = Auth::READ) ⇒ Object
14
15
16
17
18
|
# File 'lib/active_admin/pundit_adapter.rb', line 14
def scope_collection(collection, action = Auth::READ)
Pundit.policy_scope!(user, collection)
end
|