Module: Glib::Auth::Policy::Overrides

Defined in:
app/controllers/concerns/glib/auth/policy.rb

Instance Method Summary collapse

Instance Method Details

#policy(record, policy_name = nil, context = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/concerns/glib/auth/policy.rb', line 27

def policy(record, policy_name = nil, context = nil)
  policy_name ||= record

  @__pundit_policies ||= {}
  if @__pundit_policies[policy_name]
    @__pundit_policies[policy_name].context = context
    return @__pundit_policies[policy_name]
  end

  # if policy_name.is_a?(Symbol) && policy_name.to_s.ends_with?('_admin')
  #   policy_class = CommonAdminPolicy
  # else
  #   policy_class = Pundit::PolicyFinder.new(policy_name).policy
  # end

  policy_class = Pundit::PolicyFinder.new(policy_name).policy

  raise "Policy not found for #{policy_name.is_a?(Symbol) || policy_name.is_a?(Class) ? policy_name : policy_name.class}" unless policy_class

  policy_instance = policy_class.new(current_user, record, policy_name, self, request, params)
  policy_instance.context = context

  @__pundit_policies[policy_name] = policy_instance
end

#policy_scope(*args, **opts) ⇒ Object

Override



54
55
56
# File 'app/controllers/concerns/glib/auth/policy.rb', line 54

def policy_scope(*args, **opts)
  super
end