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

STI parent access denied after adding cannot on child #768

Open
gryphon opened this issue Feb 11, 2022 · 2 comments
Open

STI parent access denied after adding cannot on child #768

gryphon opened this issue Feb 11, 2022 · 2 comments

Comments

@gryphon
Copy link

gryphon commented Feb 11, 2022

Steps to reproduce

We have the following STI inheritance: Toyota < Car

Setting the rules:

can :read, Car
cannot :read, Toyota

Checking the roles:

can? :read, Car # results to false

Expected behavior

can? :read, Car # should be true

Because we granted an access to all types of Car except Toyota

Actual behavior

can? :read, Car # results to false

System configuration

Rails version: 7.0.2

Ruby version: 3.0.3

CanCanCan version: 3.3.0

@ghost
Copy link

ghost commented Feb 15, 2022

There is currently an open pull request: #689 which should fix this issue.

@gryphon
Copy link
Author

gryphon commented Feb 27, 2023

Seems that this issue is not still fixed.
There is the test in repo but it works only for non-STI relation:

    it 'cannot rules are not effecting parent class' do
      u1 = User.create!(name: 'pippo')
      ability = Ability.new(u1)
      ability.can :manage, Parent
      ability.cannot :manage, Child
      expect(ability).not_to be_able_to(:index, Child)
      expect(ability).to be_able_to(:index, Parent)
    end

If we have Child inherited from Parent using STI, this would not pass.

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

No branches or pull requests

1 participant