-
Notifications
You must be signed in to change notification settings - Fork 60
Default pundit authorizer keyword args #95
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
Default pundit authorizer keyword args #95
Conversation
there may be a better way to combine the splat and keyword arguments in the #with call, but I can't see what it is
|
Hi! Thanks for taking a stab at this Looks like the tests are passing right now, nice 👍. Code style linter is causing the CI to be red, but the specs do go through and that's nice. You might want to run The I wonder if, after converting all authorizer methods to use kwargs, will we even need the "non-kwargs" call anyway? So we might be able to get rid of the |
|
Thanks, I'll do that. I'd like to mention a couple of other things, assuming semantic versioning:
I'll continue with the simplest options for now, but as I mentioned it's probably better to get the API right (if that matters? if it's not frequently used maybe it does not) before a major release. |
|
Good question regarding the argument names. I took a look at the current argument names, and only
I think they'll be quite easy to rename after this PR to something else, so you don't have to worry about that here. That is, unless you get some amazing idea for a better name, then we can discuss it 😄
Yeah, that has been the case. We've documented that people can use a different authorizer in the past here: https://github.com/venuu/jsonapi-authorization/blob/v0.8.2/README.md#configuration I've also mentioned that subclassing
I think it's for the best to use keyword arguments for all methods. It makes the authorizer class methods consistent, and also makes it clearer when the method is passed a model class compared to model instance. For example:
☝️ the
☝️ the
That sounds like a good approach to me! 👍 I don't think many people rely on the exact API of |
|
I agree with all of that. Thanks for the feedback. |
spec/support/authorization_stubs.rb
Outdated
| def allow_operation(operation, *args, authorizer: instance_double(AUTHORIZER_CLASS), **kwargs) | ||
| allow(authorizer).to receive(operation).tap {|x| | ||
| if kwargs.empty? then x.with(*args) else x.with(*args, **kwargs) end | ||
| kwargs.empty? ? x.with(*args) : x.with(*args, **kwargs) |
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.
I am a bit sad about this change, but I see the benefit of having the style rules enforced automatically & not spending time agonising over lots of custom rules (as I probably now will while adding this setup to my own project).
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.
Yeah, code styles can differ between projects. I'm myself happy about this change, as I prefer ternaries over one line if ... then ... else ... end statements 😛
|
I think this is finished, but would like your opinion on the unused parameters in Otherwise, we either need to do this (what I've done currently, on 2 methods): or set |
now that positional *args have been removed from the authorizer method signatures
|
Thanks! Looking forward to looking into this 😊. I'll get to this on Monday most likely |
|
I actually got to looking into this right now 😊. This looks great to me! I think that it's the best approach to leave the rubocop disable comments in-place, as even if the default authorizer doesn't use those arguments, they can be useful for custom authorizer classes. It's also possible to add only |
|
Is this OK for merging, or is there still something you'd like to do? |
|
I think the code is ready but I haven't checked if any of the documentation needs revising. |
|
Yeah might be useful to check if the generated rubydocs still look good. That can happen in another PR as well. I don't remember off the top of my head that how these rubydocs were generated in the first place 😅 |
|
The classname doesn't appear in the project files outside of the file comments and specs, so I assume there isn't other documentation for this. Upgrading user wise, the runtime documentation (cough error messages cough) should make it clear what to do. So I'm finished on this unless you'd like something else doing. A nice thing for the changelog / version notes for v1 probably needs writing but I'm hoping you will do that? |
|
Yeah I can handle the changelog |
|
Great, thanks! Yes please do. |
I saw in #48 that help was wanted using keyword args for
JSONAPI::Authorization::DefaultPunditAuthorizerso I've had a go at it. I've done 2 methods to see how it goes, and I'd like feedback to check I'm doing what you wanted before continuing.The only hard part I found was making the
AuthorizationStubshelpers work with keyword args as well as splat args. I'm not entirely happy with how I solved that, so any thoughts on that would be great. To see why I've done that, try changing the stub method and re-run the tests and you'll find a lot of things start breaking in various places with wrong-number-of-argument errors and other fun things.