-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add policy_class to permitted_attributes #789
Changes from all commits
2599145
6ca336c
b738d79
b458f0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,9 +98,14 @@ def policy_scope(scope, policy_scope_class: nil) | |
# | ||
# @see https://github.com/varvet/pundit#policies | ||
# @param record [Object] the object we're retrieving the policy for | ||
# @param policy_class [Class] the policy class we want to force use of | ||
# @return [Object, nil] instance of policy class with query methods | ||
def policy(record) | ||
policies[record] ||= Pundit.policy!(pundit_user, record) | ||
def policy(record, policy_class: nil) | ||
policies[{ policy_class: policy_class, record: record }] ||= if policy_class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While We maybe should cache when I believe that the cache behaviour of |
||
policy_class.new(pundit_user, record) | ||
else | ||
Pundit.policy!(pundit_user, record) | ||
end | ||
end | ||
|
||
# Retrieves a set of permitted attributes from the policy by instantiating | ||
|
@@ -113,9 +118,10 @@ def policy(record) | |
# @param record [Object] the object we're retrieving permitted attributes for | ||
# @param action [Symbol, String] the name of the action being performed on the record (e.g. `:update`). | ||
# If omitted then this defaults to the Rails controller action name. | ||
# @param policy_class [Class] the policy class we want to force use of | ||
# @return [Hash{String => Object}] the permitted attributes | ||
def permitted_attributes(record, action = action_name) | ||
policy = policy(record) | ||
def permitted_attributes(record, action = action_name, policy_class: nil) | ||
policy = policy(record, policy_class: policy_class) | ||
method_name = if policy.respond_to?("permitted_attributes_for_#{action}") | ||
"permitted_attributes_for_#{action}" | ||
else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always
nil
here. What's the intention?