-
-
Notifications
You must be signed in to change notification settings - Fork 642
Allow can with query on single resource #785
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
base: develop
Are you sure you want to change the base?
Allow can with query on single resource #785
Conversation
ebf633e to
02f63ac
Compare
|
Did anyone have time to take a look at this? :-) |
lib/cancan/conditions_matcher.rb
Outdated
| selects = query.values[:select] | ||
|
|
||
| if selects&.length != 1 | ||
| raise "Only one column should be selected and not #{selects&.length || 0} for: #{value.to_sql}" |
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.
can you please add a test for this error?
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.
@coorasse I have added a test and fixed the issue with the wrong variable name :-)
|
@coorasse I feel like fixing the offence would require me to do an unrelated big refactor to CanCan::ConditionsMatcher. How would you prefer I continue? :-) |
garrettblehm
left a comment
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 would love to have this pushed through
| if defined?(ActiveRecord) && | ||
| (value.is_a?(ActiveRecord::AssociationRelation) || value.is_a?(ActiveRecord::Relation)) | ||
| return condition_match_query?(attribute, value) | ||
| end |
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 think this could be moved within the case statement.
Passing a query to a rule is already supported by
accessible_bybut not when checking on a single resource. This PR fixes that and adds specs for it.Example usage: