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

Using STI with cancan #532

Closed
lcjury opened this issue Sep 14, 2018 · 3 comments
Closed

Using STI with cancan #532

lcjury opened this issue Sep 14, 2018 · 3 comments

Comments

@lcjury
Copy link

lcjury commented Sep 14, 2018

Steps to reproduce

Hi, We're using Rails STI, so, for example, let's say we have the following models: Survey, Climate and Evaluation. Climate and Evaluation inherit from Survey. (Survey has a type column to make STI work)

When you define an ability for Survey, those abilities are inherited by Climate and Evaluation, but, when I define an ability for a child class (Climate) and I try to use the accessible_by method from the parent class, the child class abilities are ignored.

Let's say this is in my ability:

can :destroy, Evaluation

If I try to do the following:

Survey.accessible_by(ability, :destroy)

it returns nothing. I expect it to return all the Surveys of type Evaluation (or all the Evaluations). The following works:
(let's say the first Survey is a Climate and the second a Evaluation)

ability.can? Survey.first, :destroy #false
ability.can? Survey.second, :destroy #true

Gist: https://gist.github.com/lcjury/e13f706f33010d3cb80c58e87fbe5706

Expected behavior

Survey.accessible_by(ability, :destroy) should return all the Surveys where ability.can? survey, :destroy whould evaluate to true

Actual behavior

ability.can? Survey.second, :destroy #true is true, but it's not returned by Survey.accessible_by(ability, :destroy)

System configuration

Rails version:
5.0
Ruby version:
2.5
CanCanCan version
1.17

Note: I have troubles running the gist, I get the following message: "CanCan::NotImplemented: This model adapter does not support fetching records from the database.". So, I wasn't able to test that the last lines trully works as I have told here, but I tested everything inside a running rails project.

@coorasse coorasse self-assigned this Sep 16, 2018
@coorasse coorasse added the bug label Sep 16, 2018
@coorasse
Copy link
Member

I see the issue. Of course, we can fix this even though it may not be very easy. Temporarily defining you rule as can :destroy, Survey, type: 'Evaluation' will do it.

@ghost
Copy link

ghost commented Nov 9, 2020

cc @coorasse As far as I can tell this issue was address by #649

@coorasse
Copy link
Member

Yes, this can be closed since is released in 3.2.0

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

No branches or pull requests

2 participants