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 support in 3.2.0 is a breaking change #677

Closed
Fryie opened this issue Dec 18, 2020 · 9 comments
Closed

STI support in 3.2.0 is a breaking change #677

Fryie opened this issue Dec 18, 2020 · 9 comments

Comments

@Fryie
Copy link

Fryie commented Dec 18, 2020

Steps to reproduce

So, here is some fun change in behaviour in the 3.2.0 release, related to the STI support.

The following tests fail in 3.2.0, but they pass in the previous 3.1.0 version: https://gist.github.com/Fryie/46b759ca19efa28e1dfdb41a54742e1b

Basically, calling index on some resource may lead to an authorization failure if access to a subclass of that resource is disallowed. Changing the order of the two ability rules also affects the code in a somewhat unintuitive(?) way: the previously failing assertion passes, but the one that used to pass doesn't anymore. (This seems due to the fact that matching rules are selected in reverse order).

Expected behavior

I'm not sure what the expected behaviour should be here. Inheritance generally makes reasoning about something like this harder: should I be able to index all parents even if some of them might actually be children, which I'm not technically able to access? Maybe not (but then again, what if my controller automatically filters the children out?)? But probably this change is also unexpected in a minor release. At least a gotcha/workaround could be added somewhere in the documentation.

The problem is unfortunately compounded in my case by the fact that ActiveAdmin doesn't distinguish between index and show. So saying something like "the user should be able to list all parents (including, or excluding children), but the show action should be forbidden for children" doesn't actually seem to be possible. As far as I am aware, this used to work in 3.1.0.

Actual behavior

See above

System configuration

Rails version:
see gist

Ruby version:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]

CanCanCan version
see gist

@coorasse
Copy link
Member

The test on line https://gist.github.com/Fryie/46b759ca19efa28e1dfdb41a54742e1b#file-cancan_bug-rb-L62 should definitely return true in my opinion, so we have a regression.
can :index, ModelClass should return true since you can index the class itself. I don't think is possible to use STI here in a smart way.

@Liberatys what is your opinion on this issue?

@tagliala
Copy link

tagliala commented Jan 1, 2021

Hi,

I'm experiencing a similar regression with breaking change when permissions is only assigned to a subclass, propagating to the parent class.

Git bisect indicates that the breaking change has been introduced in this commit: 5d39575

class Motorbike < ApplicationRecord
end

class Suzuki < Motorbike
end

class Ability
  include CanCan::Ability

  def initialize(user = nil)
    can :manage, Suzuki
  end
end

3.1

> CanCan::VERSION
=> "3.1.0"
> Ability.new.can? :manage, Suzuki
=> true
> Ability.new.can? :manage, Motorbike
=> false

3.2

> CanCan::VERSION
=> "3.2.1"
> Ability.new.can? :manage, Suzuki
=> true
> Ability.new.can? :manage, Motorbike
=> true

@axlekb
Copy link

axlekb commented Jan 12, 2021

@Liberatys, would you be able to assist here as it appears that your commit introduced a regression?

@ghost
Copy link

ghost commented Jan 13, 2021

@axlekb, of course, ^^ I'll look into finding a solution for the issue over the weekend as it has caused quite some issues and it will take a bit more time as it affects multiple operations :D

@tagliala
Copy link

Any news about this?

I can see there was an attempt to fix at #688, but the PR is now closed

@ghost
Copy link

ghost commented Apr 16, 2021

@tagliala The initial solution was somewhat difficult to extend and I tried to extract it into an easier format. #689 - Should fix the issue.

@tagliala
Copy link

@Liberatys thanks. Didn't see that PR linked to this issue

@georf
Copy link

georf commented Dec 8, 2021

What is the argument against merging the PR? #689

@coorasse
Copy link
Member

This should be closed in 3.4.0 now.

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

5 participants