-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Adds support for rules at the attribute/method level #474
Adds support for rules at the attribute/method level #474
Conversation
@coorasse something I would like you to weigh in on. For the Unfortunately, in the main code base, he also added an Which is part of the code base now. I thought it might be an undocumented or unused feature that could be replaced, but there are clearly tests for it here: https://github.com/CanCanCommunity/cancancan/blob/develop/spec/cancan/ability_spec.rb#L273 Because Thoughts? |
58b8a85
to
c4345d8
Compare
This is based on Ryan Bate's Cancan 2.0 code, but modified to match modern Cancancan. Tests are included. I also updated the rubocop config to target Ruby to version 2.2.0 to match the required version in the gemspec and to avoid end of life warnings.
c4345d8
to
4ac0b1b
Compare
Good point. I also didn't remember of the This brings me to a fixed point: we should preserve that feature.
to have
this would not be a breaking change. what do you think? |
From my point of view we could also have a breaking change and be more open to future implementations. changing the syntax to: |
I'm very interested in having fields in our @coorasse, I agree, having to pass can? :update, book, nil, [2, 3] However, I'm not fond of having to write What about going in between your two suggestions and making can? :update, book, extra_args: [2, 3] or this: can? :update, book, [:title, :author], extra_args: [2, 3] because extra_args is a named parameter and the attributes are optional, both would work. This way the three main parameters, @coorasse, what do you think? |
@CyborgMaster I like the suggestion. I'll explore some code around it. I'm interested in this because I'm working on a GraphQL API and would love to be able to easily define attribute-level permissions in a simple, straightforward way. @coorasse I like the symmetry of |
@coorasse When I run the tests locally they all pass. I'm not sure how to solve the |
I have removed the That is, the |
I also need this PR. Thx @phaedryx 👍 |
Note: because of how I handled the initialize method of Rule, the change isn't as breaking as I initially thought it would be. The only incompatibility, like I mentioned above, is if you are passing a symbol or array of symbols as extra arguments (passing conditions works the same as before). The extra arguments functionality is barely remembered and undocumented, so I assume it is rarely used, let alone with an array of symbols. Adding a |
Currently, the latest version of pg is 1.0.0, but activerecord 5.1.0 is not compatible with it (see https://goo.gl/L14fPa for an example). It is better to pin to a known compatible version.
This adds a |
I've been trying to make |
@coorasse |
@stalniy this refactor addresses your comments |
this is proceeding well. it will take still some time but I have an eye on it 👍 |
This branch does everything I need it to do and I've fixed all of the bugs I can think of. I consider it complete. |
Is there any reason not to use some of these features @phaedryx ? I don't think I see them documented in the wiki, but they would be useful for a project I'm working on. |
The feature is available and can be used. Is not well documented because we are moving the wiki at the moment. Please use it! 👍 |
Great, thank you! |
Hi, i'm using this feature (so, thanks for your work 😅), and when I use it with one attribute works perfect:
But when I use an array of attributes:
I get: "undefined method `to_sym' for #Array:0x000055f77c97a350." Looking rapidly at the code, it seems like It's not supported yet? Is there a workaround? Or maybe I'm doing something wrong? |
- Cancancan supports attribute-level rules added argument to can? so it also needs to be applied to Draper Cancancan extension to work correctly Refs - https://github.com/CanCanCommunity/cancancan/blob/main/CHANGELOG.md#300 - CanCanCommunity/cancancan#474
Allows you to add attribute-level rules, e.g.