Skip to content

Commit

Permalink
Revert pundit_policy_namespace use in controllers
Browse files Browse the repository at this point in the history
Revert pundit_policy_namespace use in controllers
Use pundit policy_namespace in controllers
  • Loading branch information
bhtabor committed Jun 4, 2023
1 parent 2b6a461 commit 51cc9fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
18 changes: 5 additions & 13 deletions app/controllers/concerns/administrate/punditize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,25 @@ module Punditize
include Pundit
end

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

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

private

def policy_namespaces
self.class._policy_namespaces
def policy_namespace
[]
end

def scoped_resource
namespaced_scope = policy_namespaces + [super]
namespaced_scope = policy_namespace + [super]
policy_scope!(pundit_user, namespaced_scope)
end

def authorize_resource(resource)
namespaced_resource = policy_namespaces + [resource]
namespaced_resource = policy_namespace + [resource]
authorize namespaced_resource
end

def authorized_action?(resource, action)
namespaced_resource = policy_namespaces + [resource]
namespaced_resource = policy_namespace + [resource]
policy = Pundit.policy!(pundit_user, namespaced_resource)
policy.send("#{action}?".to_sym)
end
Expand Down
5 changes: 4 additions & 1 deletion spec/controllers/admin/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
context "with namespaced Punditize concern" do
controller(Admin::OrdersController) do
include Administrate::Punditize
pundit_policy_namespace Own

def policy_namespace
[:own]
end

def pundit_user
Customer.find_by(name: "Current User")
Expand Down

0 comments on commit 51cc9fd

Please sign in to comment.