Skip to content

Commit

Permalink
Fix pundit_policy_namespace inheritance
Browse files Browse the repository at this point in the history
Fix pundit_policy_namespace inheritance
  • Loading branch information
bhtabor committed Jun 4, 2023
1 parent 5b507af commit 2b6a461
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/controllers/concerns/administrate/punditize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ module Punditize

class_methods do
def pundit_policy_namespace(namespace)
@policy_namespaces = namespace.to_s.split("::").map(&:to_sym)
self._policy_namespaces = namespace.to_s.split("::").map(&:to_sym)
end

private

attr_reader :policy_namespaces
end

included do
class_attribute :_policy_namespaces, instance_predicate: false, default: []

private

def policy_namespaces
self.class._policy_namespaces
end

def scoped_resource
policy_namespaces = Array(self.class.send(:policy_namespaces))
namespaced_scope = policy_namespaces + [super]
policy_scope!(pundit_user, namespaced_scope)
end

def authorize_resource(resource)
policy_namespaces = Array(self.class.send(:policy_namespaces))
namespaced_resource = policy_namespaces + [resource]
authorize namespaced_resource
end

def authorized_action?(resource, action)
policy_namespaces = Array(self.class.send(:policy_namespaces))
namespaced_resource = policy_namespaces + [resource]
policy = Pundit.policy!(pundit_user, namespaced_resource)
policy.send("#{action}?".to_sym)
Expand Down

0 comments on commit 2b6a461

Please sign in to comment.