-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
When a controller action fails to be authorized, redirect back or default to /unauthorized #3118
When a controller action fails to be authorized, redirect back or default to /unauthorized #3118
Conversation
75d3b36
to
a3ac7bd
Compare
Thanks! Are you using |
ah! thanks for pointing that out. I can make the change in |
Sound good to me, please note that for the Admin controller there's another point where this is set, other than what I've previously linked: https://github.com/solidusio/solidus_auth_devise/blob/335991f79557bc36ea08943b9e1fbb151154d020/lib/spree/auth/engine.rb#L37 |
If we create a preference for letting people opt-in for this new behavior, we can deprecate the old one and use this preference into solidusio/solidus_auth_devise#192 as well. |
a3ac7bd
to
4a3ac73
Compare
73058e1
to
9cc67d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kennyadsl @genarorg thanks for this PR 👍
There's one small typo to fix, otherwise looks good!
core/lib/spree/app_configuration.rb
Outdated
# Whether to try to redirect users back when they try to access | ||
# unauthorized routes, before redirect them to /unauthorized. | ||
# @return [Boolean] (default: +false+) | ||
preference :redirect_back_on_unauthorized, :boolena, default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be :boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, and it's working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works because that information is used for typecasting. In that case, no typecasting would occur as the type would not be recognized.
…ferrer is present or redirect to /unauthorized
With this preference we'll be able to communicate with store owners that the behavior is changing and they have to manually change the preference and be sure that their store is still working as expected. New app will have the new behavior, with the preference set to true, while existing app will keep having the old behavior (false), so they can see the deprecation warning.
9cc67d8
to
34408c2
Compare
@kennyadsl this is good to merge I think? |
Only when the `redirect_back_on_unauthorized` preference exists and is set to true. This preference has been introduced in core with solidusio/solidus#3118 and we can rely on that preference to drive the behavior change here as well. The extra if Spree::Config.redirect_back_on_unauthorized == false check might seem useless but it's needed to avoid printing this deprecation warning on Solidus versions that still do not have the preference. If the Solidus verion used does not have the preference yet, the old behavior will be preserved.
Only when the `redirect_back_on_unauthorized` preference exists and is set to true. This preference has been introduced in core with solidusio/solidus#3118 and we can rely on that preference to drive the behavior change here as well. The extra if Spree::Config.respond_to?(:redirect_back_on_unauthorized) check might seem useless but it's needed to avoid printing this deprecation warning on Solidus versions that still do not have the preference. If the Solidus verion used does not have the preference yet, the old behavior will be preserved.
Only when the `redirect_back_on_unauthorized` preference exists and is set to true. This preference has been introduced in core with solidusio/solidus#3118 and we can rely on that preference to drive the behavior change here as well. The extra if Spree::Config.respond_to?(:redirect_back_on_unauthorized) check might seem useless but it's needed to avoid printing this deprecation warning on Solidus versions that still do not have the preference. If the Solidus verion used does not have the preference yet, the old behavior will be preserved.
Only when the `redirect_back_on_unauthorized` preference exists and is set to true. This preference has been introduced in core with solidusio/solidus#3118 and we can rely on that preference to drive the behavior change here as well. The extra if Spree::Config.respond_to?(:redirect_back_on_unauthorized) check might seem useless but it's needed to avoid printing this deprecation warning on Solidus versions that still do not have the preference. If the Solidus verion used does not have the preference yet, the old behavior will be preserved.
Only when the `redirect_back_on_unauthorized` preference exists and is set to true. This preference has been introduced in core with solidusio/solidus#3118 and we can rely on that preference to drive the behavior change here as well. The extra if Spree::Config.respond_to?(:redirect_back_on_unauthorized) check might seem useless but it's needed to avoid printing this deprecation warning on Solidus versions that still do not have the preference. If the Solidus verion used does not have the preference yet, the old behavior will be preserved.
Only when the `redirect_back_on_unauthorized` preference exists and is set to true. This preference has been introduced in core with solidusio/solidus#3118 and we can rely on that preference to drive the behavior change here as well. The extra if Spree::Config.respond_to?(:redirect_back_on_unauthorized) check might seem useless but it's needed to avoid printing this deprecation warning on Solidus versions that still do not have the preference. If the Solidus verion used does not have the preference yet, the old behavior will be preserved.
Description
This change allows for a user to be redirected back whenever a request is not authorized. The current behavior redirects the user to
/unauthorized
all the time, but this is not ideal when browsing the admin, since you need to manually go back to where you came from.Changes:
Spree::Core::ControllerHelpers::Auth
: Inself.unauthorized_redirect
, useredirect_back
with a fallback location.Checklist: