Skip to content
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

Allow can with query on single resource #785

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

kaspernj
Copy link
Contributor

@kaspernj kaspernj commented May 3, 2022

Passing a query to a rule is already supported by accessible_by but not when checking on a single resource. This PR fixes that and adds specs for it.

Example usage:

can :read, ProjectPart, state: "won", offer_won: {account_id: current_accounts.select(:id)}

@kaspernj kaspernj force-pushed the allow-can-on-single-resource branch from ebf633e to 02f63ac Compare May 3, 2022 13:25
@kaspernj
Copy link
Contributor Author

Did anyone have time to take a look at this? :-)

lib/cancan/conditions_matcher.rb Show resolved Hide resolved
selects = query.values[:select]

if selects&.length != 1
raise "Only one column should be selected and not #{selects&.length || 0} for: #{value.to_sql}"
Copy link
Member

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?

Copy link
Contributor Author

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 :-)

@oboxodo
Copy link

oboxodo commented Jan 23, 2023

I just posted an issue related to this (but a bit more general maybe?): #812

And a PR with a proposed change: #813

Open for feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants