lib/pundit/resource.rb in pundit-resources-1.0.1 vs lib/pundit/resource.rb in pundit-resources-1.1.0
- old
+ new
@@ -3,10 +3,12 @@
module Pundit
module Resource
extend ActiveSupport::Concern
included do
+ define_jsonapi_resources_callbacks :policy_authorize
+
before_save :authorize_create_or_update
before_remove :authorize_destroy
end
module ClassMethods
@@ -30,11 +32,13 @@
end
protected
def can(method)
- context[:policy_used]&.call
- policy.public_send(method)
+ run_callbacks :policy_authorize do
+ context[:policy_used]&.call
+ policy.public_send(method)
+ end
end
def current_user
context&.[](:current_user)
end