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

Implement detection for sti for including subclasses in check #689

Merged
merged 7 commits into from Mar 23, 2022
Merged

Implement detection for sti for including subclasses in check #689

merged 7 commits into from Mar 23, 2022

Conversation

ghost
Copy link

@ghost ghost commented Jan 24, 2021

  • Remove subclass rule inclusion for non sti classes
  • Start of implementing more sti detection utilities which are going to be used in a rewrite (coming)

@coorasse how do you want to handle this ? It seems like STI will have some issues with the current implementation. I'll probably have to add conditional loading at 3 places to fully comply with the expected behaviour.

@@ -12,6 +14,8 @@ def self.matches_subject_class?(subjects, subject)
def self.matching_class_check(subject, sub, has_subclasses)
matches = matches_class_or_is_related(subject, sub)
if has_subclasses
return matches unless StiDetector.sti_class?(sub)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only include the subclasses in the check if the model is an sti class

@@ -0,0 +1,10 @@
class StiDetector
def self.sti_class?(subject)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general detection for STI classes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love its isolation

@@ -909,6 +909,37 @@ class JsonTransaction < ActiveRecord::Base
end
end

context 'with rule application to subclass for non sti class' do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that rules are no longer applied to parents for non sti

@winstonwolff
Copy link

Thank you for working on this. We've tried this code and it seems to work—our test cases pass and it seems to block a parent class of resources as we expected. If we see any problems with it, we'll report back.

@swelther
Copy link

swelther commented Dec 3, 2021

Any news on this? 🙏 This issue prevents us from updating to cancancan 3.2+ :(

Copy link
Member

@coorasse coorasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Liberatys do we need to check further scenarios here, like @phallstrom suggested, or are they covered already somewhere else?

@@ -0,0 +1,10 @@
class StiDetector
def self.sti_class?(subject)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love its isolation

@ghost
Copy link
Author

ghost commented Mar 23, 2022

@coorasse I now also added the spec that covers the example from #677(as per @phallstrom). CI is blue/green ^^

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

Successfully merging this pull request may close these issues.

4 participants