You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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.
The text was updated successfully, but these errors were encountered:
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.
Steps to reproduce
Hi, We're using Rails STI, so, for example, let's say we have the following models:
Survey
,Climate
andEvaluation
.Climate
andEvaluation
inherit fromSurvey
. (Survey has a type column to make STI work)When you define an ability for
Survey
, those abilities are inherited byClimate
andEvaluation
, but, when I define an ability for a child class (Climate) and I try to use theaccessible_by
method from the parent class, the child class abilities are ignored.Let's say this is in my ability:
If I try to do the following:
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)
Gist: https://gist.github.com/lcjury/e13f706f33010d3cb80c58e87fbe5706
Expected behavior
Survey.accessible_by(ability, :destroy)
should return all the Surveys whereability.can? survey, :destroy
whould evaluate to trueActual behavior
ability.can? Survey.second, :destroy #true
is true, but it's not returned bySurvey.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.
The text was updated successfully, but these errors were encountered: