chaps-io / access-granted

Multi-role and whitelist based authorization gem for Rails (and not only Rails!)
MIT License
774 stars 41 forks source link

Support for :all #52

Closed alexr17 closed 5 years ago

alexr17 commented 5 years ago

CanCanCan has a nice shortcut for managing all models: can :manage, :all and it would be great if this gem had that too, or something similar. I noticed a quick fix that would allow something like this to work: can :read, ApplicationRecord

In permission.rb:

def matches_subject?(subject)
    subject == @subject || subject.class <= @subject
end

Adding .class onto the end of @subject allows the second condition to work successfully. Otherwise, it evaluates to nil.

def matches_subject?(subject)
    subject == @subject || subject.class <= @subject.class
end
alexr17 commented 5 years ago

I'm going to close this because it can be monkey patched, and my solution actually introduces a different bug.