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

CanCan auth-fails redirect from backend to frontend login path #371

Open
bxt opened this issue Dec 5, 2016 · 1 comment
Open

CanCan auth-fails redirect from backend to frontend login path #371

bxt opened this issue Dec 5, 2016 · 1 comment

Comments

@bxt
Copy link

bxt commented Dec 5, 2016

So spree_auth_devise already patches Spree::Admin::BaseController#unauthorized such that unauthorized actions go to the backend login form.

However, when the authorization failures come from exceptions from CanCan's authorize! method, spree calls a method named redirect_unauthorized_access. So if you access certain backend features, you might be redirected to the frontend login instead.

Maybe a alias_method :redirect_unauthorized_access, :unauthorized in the admin_controller_decorator would already fix this.

@bxt bxt changed the title CanCan auth fails redirect from backend to frontend login path CanCan auth-fails redirect from backend to frontend login path Dec 5, 2016
@bxt
Copy link
Author

bxt commented Dec 5, 2016

I just found the file lib/controllers/backend/spree/admin/admin_resource_controller_decorator.rb. It extends Spree::Admin::ResourceController to instead use the method unauthorized on CanCan errors, so this actually works in almost all cases.

I guess we have some custom controllers that only inherit from Spree::Admin::BaseController, so they don't get this patch, but they still use CanCan. Maybe it would be better to override the rescue_from in Spree::Admin::BaseController since this is the topmost admin controller which also includes CanCan stuff via Spree::BaseController from core and its concern Spree::Core::ControllerHelpers::Auth.

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

No branches or pull requests

1 participant