-
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
First pass of Pundit::Context #797
Conversation
eaf3765
to
5e8c0d2
Compare
Right now this change is backwards-compatible, possibly with the exception of our new |
Unless it's far too controversial I'd like to be able to remove the singleton methods on For those who uses |
a2f28ee
to
399fe6e
Compare
@mattzollinhofer I've added some more commits to kinda hint at where I'm going at. A change I haven't gotten to is passing more information to We would achieve backwards-compatibility by having a By then implementing a new cache strategy that's opt-in we can get caching behaviour when passing |
d26960b
to
d725154
Compare
Another idea I had for this is some shortcuts to how one could override the default behavior in specific controllers, e.g: class AdminControllerBase < ApplicationController
def pundit
@pundit ||= super.with_namespace(Admin)
end
end |
Had a few people at RailsConf try this out in their apps, and nothing broke! Thank you all :) |
It has unwanted behaviour, such as being lenient in initialisation parameters and being loose in equality check.
This is not strictly a feature that was intended, but it's how it works so it needs to be supported in the future.
See #774 An API-change in this commit is that we're introducing a new method named `pundit` in `Pundit::Authorization`. We should not take this change lightly, because this is a namespace that is technically not ours as we're being included in controllers. The hope is that the context method will help _reduce_ the overall API surface. Additionally this will hopefully help us introduce an API for a namespaced Pundit.
An `!` means caution, but not much more. These comments help highlight what to be cautious about. Co-authored-by: mattzollinhofer <matt.zollinhofer@gmail.com>
See #801 (comment) We'd like to support caching a few more lookups, but that's backwards-incompatible. By swapping out the cache, we could have a legacy cache (that only caches "the old way"), and a new cache that will cache _more_ things. This allows backwards-compatibility with the same API interface.
This should be backwards-compatible because: * `Pundit.policy` and `Pundit.policy!` are unaffected by this, since they use a non-cache cache. * `Pundit::Context` is new, so nobody is relying on these methods yet. * `Pundit::Authorization#policy` already cached the policy anyway. * `policies` is explicitly discouraged, but even if it is relied upon it works as it always has, by default. This is an improvement because we can change the cache strategy to introduce new features without breaking backwards-compatibility.
... and possibly by extension also the `policy_class`.
d725154
to
6f04482
Compare
This should be backwards-compatible, so let me know if this breaks anything.
See #774 initial draft/rationale.
Caution
Pundit::Authorization#pundit
. This is a namespace that is technically not ours, as this module included in controllers.Hopefully this allows us to:
Pundit::Authorization
.authorize
/policy
.