-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Authorization Adapter redefines BaseController#authorize! method and clashes with CanCan #2077
Comments
Worked fine in the old active_admin versions. (< 0.6.0) |
Our wiki pages are now out of date with the 0.6 release, read this blurb - you're mixing 0.5 & 0.6 ways of authorization. |
@macfanatic does this means that one can't use authorize_resource? |
I haven't tested, but I suspect that you wouldn't want to mix in two different authentication methods at the same time. The newly added authorization adapter will take care of that for you. |
As I understand authorize_resource is an old method, right? Although I have removed the following line from each admin/*rb file the problem the problem persists. What I'm doing wrong and what should I do? |
Hmm, can you post a backtrace as a gist that I can review? Assuming you removed the |
This is definitely a bug, we're overriding a method originally defined by CanCan and it is declared as private in our code. https://github.com/ryanb/cancan/blob/master/lib/cancan/controller_additions.rb#L336 |
yeah, this is the fix, maybe just move directive from line 43 to 80 (right after authorize! method)? |
@macfanatic, @dirty-hippie is that really a fix? From my reading of the code, if you set your own |
@gregbell thoughts on this? |
I'm encountering the same issue. Any updates on a fix? |
also having the same issue even after removing all references of authorize_resource from active admin |
Thanks for the fast response daxter got to love your work ActiveAdmin.setup do |config|
config.authorization_adapter = ActiveAdmin::CanCanAdapter
...
end
ActiveAdmin.register Post, :namespace => :admin do
### CANCAN ABILITIES ###
controller.authorize_resource
end
class Ability
include CanCan::Ability
def initialize(current_user)
current_user ||= User.new
can :manage, Post do |post|
post.administration_users.include?(current_user)
end
end
end note: post.administration_users.include?(current_user) = true |
+1 |
2 similar comments
+1 |
+1 |
I'm looking into this now, hopefully I can get a PR together. |
I was able to upgrade my application to the 0.6 release and use the new authorization system by doing the following:
ActiveAdmin.setup do |config|
config.authorization_adapter = ActiveAdmin::CanCanAdapter
...
end
ActiveAdmin.register Post, :namespace => :admin do
end
class Ability
include CanCan::Ability
def initialize(current_user)
current_user ||= User.new
can :manage, Post, administration_users: { user_id: current_user.id }
end
end I don't believe that any code action is required. |
I'm going to close this, then. Please feel free to comment if you're still encountering this problem. |
Still having the same error after trying the fix suggested by @macfanatic |
Having the same bug too. CanCan says, that the authorize_resource call in the controller is missing. If i (re)add it than this bug occurs. |
Just wanted to throw my hat in here and say I have the same issue as MacNuke using ActiveAdmin 0.6.0 and CanCan 1.6.9 |
Same issue as MacNuke and jakemauer |
update to 0.6 and this bug shows up again |
Okay, I'm going to re-open this. Anyone, please feel free to add any details about your situation that differ from what's already been said. |
FWIW... I managed to get things working by monkey-patching class ActiveAdmin::BaseController
public :authorized?, :authorize!, :authorize_resource!
end Not suggesting that anyone else do this, and I don't know what other side-effects it might cause... but it did get rid of this error for me. (I am using the |
The fix posted by @macfanatic works for me with ActiveAdmin 0.6.0 and CanCan 1.6.10. |
if you're still seeing this error with AA 0.6.0 and CC 1.6.10 make sure you don't have the gem 'activeadmin-cancan', '0.1.4' still installed that some of the guides recommended. that bit me. as soon as i removed, the @macfanatic fix worked perfect. |
I have time today to update activeadmin v0.6 and test again. Finally it all works and I have to say, it's all about messy configurations but not ActiveAdmin or CanCan problems. I suggest to check these steps, and hopefully it fixes:
|
So we've got a few people with success stories now. @Malet, @MacNuke, @jakemauer, @luca776 are you all still not able to get this working properly? |
the fix suggested by @macfanatic worked for me -- all errors vanished when I removed the activeadmin-cancan gem and fixed up the files (ActiveAdmin 0.6.0 and CanCan 1.6.10) |
fix suggested by @macfanatic worked for me, too make sure
|
Okay, quite a few people have confirmed that @macfanatic's directions work. Re-closing this ticket. |
Now broken again... |
Get this error when using cancan.
My initializers/active_admin:
My controller:
The text was updated successfully, but these errors were encountered: