-
-
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
Support scopes of STI classes as ability conditions #702
Support scopes of STI classes as ability conditions #702
Conversation
Hi @coorasse—is there any interest in merging this PR? It would address a big pain point for us. |
@@ -30,8 +30,16 @@ def update_rule(subject, rule, rules_cache) | |||
|
|||
# create a new rule for the subclasses that links on the inheritance_column | |||
def build_rule_for_subclass(rule, subject) | |||
sti_conditions = { subject.inheritance_column => subject.name } |
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.
sti_conditions = { subject.inheritance_column => subject.name } | |
sti_conditions = { subject.inheritance_column => subject.sti_name } |
@honigc thank you very much, can you please look at the suggestions from @Liberatys and also rebase? Thanks! |
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.
LGTM 👍🏻 Small edit: { We recently changed subject.name to subject.sti_name }. Thank you for the change.
@coorasse @Liberatys Made the requested change and rebased. Thank you! |
@coorasse LGTM |
Thanks! |
This fixes a bug introduced in #649 that broke using scopes of STI models as conditions. Without the change the new test produces this error:
This happens because the STI normalizer calls
#merge
on the scope, which assumes the argument will be a relation or a hash of relation options. Using#where_values_hash
in this case is the same thing already done in CanCan::Rule#inspect. This PR does not address the case of string conditions, which probably have a similar issue right now.