-
Notifications
You must be signed in to change notification settings - Fork 634
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
Support new params expect
method to permit parameters
#841
Comments
This is probably my fastest reply ever. Luckily we're using it in a very limited capacity, a single call-site: pundit/lib/pundit/authorization.rb Lines 232 to 238 in 54cc64e
Pundit should definitely support Rails 8. Will ponder some more! |
So if I understand correctly, behaviour doesn't change in an upgrade to Rails 8. It's just that However, pundit/lib/pundit/authorization.rb Lines 222 to 230 in 54cc64e
It effectively would reduce to something more like: params.expect(PolicyFinder.new(record).param_key => policy.public_send(method_name)) ... which I don't know if it works, but is indeed rather different and even makes |
Two things important to me:
We can achieve backwards-compatibility by adding to the API surface, e.g. However, what's important with that approach is that it's battle-tested before we recommend it. At the moment I'm not maintaining client projects with significant Pundit-usage (they don't need authorization), so I'm limited in my ability to battle-test it. |
Kinda related to #742 |
Yes. Currently basically all Rails apps crash when you send some unexpected params (if they follow the recommended approach) which has been raised many times in the Rails repo. Now the
For sure!
Good idea 👍
Sure, but Rails is already recommending it so I think we can too? But yeah we can give the option now and then change any recommendations later :) |
I think my main worry is how Pundit integrates with the API, i.e. how we hook up all the helper methods and how they relate to each other.
... maybe some more thoughts, but it's still a bit too vague in my mind. |
Yeah, we don't need to rush anything :) I mainly wanted to open the issue to get the ball rolling a bit. We will probably experiment with this a bit anyway, and I will get back later when we have some more experience with it. We already do some custom Pundit stuff so I don't think there will be any issues getting this to work in our app without changing pundit :) |
In Rails 8 the method
expect
has been introduced to mitigate some issues with the currentparams.require(:foo).permit(:bar)
approach. One issue with the current approach is that if someone sends unexpected data, sayPOST { foo: "bam" }
the Rails app will crash with aNoMethodError
because the.permit
method doesn't exist onString
. Theexpect
method handles this issue and will instead return a proper 400 error.So, we should support this in upcoming versions of Pundit.
The
expect
method has a bit of a different syntax unfortunately so we can't just change it. I guess we either we have to make it required > some version, or configurable in Pundit. I haven't looked closely on how to best handle this yet.Docs: https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect
The text was updated successfully, but these errors were encountered: