Skip to content

Check rule's subject's inheritance if subject is a Class or Module#877

Open
kevinluo201 wants to merge 1 commit intoCanCanCommunity:developfrom
kevinluo201:feature/fix_sti_can_with_class
Open

Check rule's subject's inheritance if subject is a Class or Module#877
kevinluo201 wants to merge 1 commit intoCanCanCommunity:developfrom
kevinluo201:feature/fix_sti_can_with_class

Conversation

@kevinluo201
Copy link
Copy Markdown

This change fixes the following problem of STI classes

# given "class Child < Parent"
can :read, Parent
cannot :read, Child

can? :read, Parent # => false, but should be true

The reason is that relevant_rules will fetch both ancestors and subclasses rules when ActiveRecord is used, where non-sti classes don't have this problem.

The fix is simple: just check if the rule's subject is a ancestor or itself

@kevinluo201
Copy link
Copy Markdown
Author

kevinluo201 commented Mar 2, 2025

Hi @coorasse, this is my first time contributing to this project. Would you mind helping me review this PR? Does it need to pass any CI? Thank you 🙏

@kevinluo201
Copy link
Copy Markdown
Author

@brynary @macav @Senjai @amitsuryavanshi Sorry to bother you 🥹 I just want to ask if anyone can review this PR if they're available. 🙏

@dalezak
Copy link
Copy Markdown

dalezak commented Jun 20, 2025

@coorasse any ETA when this PR will be merged? I'm running into this issue on a project, trying to decided whether to monkey patch or wait for this to be merged. /cc @kevinluo201

@23tux
Copy link
Copy Markdown

23tux commented Oct 20, 2025

@kevinluo201 any updates on this?

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