-
-
Notifications
You must be signed in to change notification settings - Fork 123
Fix locale inconsistence and remove redundant template #224
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
Conversation
They are not compatible with Zeitwerk, which is shipped with Rails 6. Since they are not used in Solidus versions that are compatible with Rails 6, there's no reason to keep them.
|
Thank you @bitberry-dev! I'll investigate the issue with the backend language. For the meantime, can you split the commit into two? Please check out this article on the benefits of making commits atomic. Please also check this article on ways to improve your git commit messages. |
|
Hi @bitberry-dev ! It seems I'm able to reproduce the issue you're having, but I'm not able to confirm if the solution you provided fixes it. Please let me know if I'm correctly reproducing the issue. Expected behaviorGiven I have set up and am running the test Rails app like this: When I visit http://localhost:3000/admin Then I should see that I am redirected to http://localhost:3000/en/admin/login And I should see that the Admin locale selector is set to English When I change the locale in the Admin locale selector to Espanol Then I should see that the login page's locale is switched to Espanol Actual behaviorI remain in http://localhost:3000/en/admin/login. Furthermore, when I refresh the login page, the Result of fixThe Rails app already points to the proposed fix but it doesn't seem to have any effect on the issue. Test app setupNote that the test app is running on Rails 6. I updated the Solidus I18n gems to match this Rails version. The Solidus I18n readme installation steps haven't been updated yet for Rails 6. |
|
Hi :)
If the locale is not in the params then it extracts from the session. And In your version, judging by the URL that includes Here video of the bug I'm talking about: Before patch After patch |
|
In addition to the previous answer* To reproduce this in your test app, you need to set for example And because of the implementation of After that you will have a choice of language at the admin bottom left |
|
@bitberry-dev I appreciate if you can watch this video testing this PR: solidus-auth-devise-224-rails-app-demo.mp4As I mentioned in the video, I'm not able to confirm that this PR fixes the language selector in the admin login page. There are two ways we can move forward with this PR. You can either
Sorry for the inconvenience. I'm looking forward to getting your PR merged! :) |
|
@gsmendoza Yes you are right. Indeed, there is such a bug - an unauthorized user cannot change the locale in the admin. And I also had this bug in my notes! And I missed that in my video this patch was applied, sorry for that :( Here is it :) # frozen_string_literal: true
module Spree
module Admin
module LocaleControllerOverrideGlobalization
extend Spree::Extension
overrode do
# todo send pull request to solidus - unauthorized user can't change language
skip_before_action :authorize_admin, only: [:set]
end
def set
locale = params[:switch_to_locale].to_s.presence
if locale && I18n.available_locales.include?(locale.to_sym)
I18n.locale = locale
session[set_user_language_locale_key] = locale
respond_to do |format|
# overrode only for staying on same page when locale changed todo it is not durable code
format.json { render json: {locale: locale, location: (request.referrer || admin_url)} }
end
else
respond_to do |format|
format.json { render json: {locale: I18n.locale}, status: 404 }
end
end
end
override!
end
end
endIt just skips I was thinking how to check this particular bug (locale inconsistency) - in theory it would be possible to change the locale when user logged in and after log out and then check in what locale the login page is, but devise apparently clears the session and locale resets to default :) As a result, to check this bug, we need to send a PR to solidus_backend 😅 |
|
So, in the end, I sent a PR to your repository with a patch for I also recorded two videos with the current solidus_auth_devise and with my fork. With original solidus_auth_devise: without_fix.mov*as you can see - the locale cannot be set because it set its value to the session using the wrong key With my solidus_auth_devise with_fix.mov*and here we are already using the correct locale key for the admin panel, so everything works I also found a bug with select2 locale and no fallback there, but that's another story) |
|
Thank you @bitberry-dev !
|
|
@gsmendoza commit messages now capitalized 😉 |
Not that dangerous, but it'd mean an unauthorized user can change the admin's locale. That's not ideal. Would it be possible to confirm the change in locale only if the login goes through and revert/not apply if not? |
Let me know what you think! |
My idea was to preserve it if the login is successful, only rolling back when not. But that's probably not going to play well with the current implementation.
And if it didn't come from a guest area, then the user was allowed to change it 🙂 I'm ok with skipping authorization for now, as otherwise, I think it'll be very complex. In the end, physical access to the computer is out of this kind of security scope. |
Sorry, I'm not following this. Let's discuss it offline :)
Yeah, in hindsight, it's a convoluted implementation that does the same thing as skipping admin authorization :D @waiting-for-dev Other than that, do you have any other concerns about this PR? Skipping |
|
I'm worried that if we change What do you think about extracting the upstream method to a standalone module and including it from About removing the template, I'd like to check with @kennyadsl that we're not missing anything, but I think it's ok. |
|
I have not been yet able to review everything, but I think it's ok to remove that partial now. |
|
@waiting-for-dev Something like this? module Spree
module Admin
module SetsUserLanguageLocaleKey
def set_user_language_locale_key
:admin_locale
end
end
end
end
module Spree
module Admin
class BaseController < Spree::BaseController
# ...
private
# Overrides ControllerHelpers::Common
# We want the admin's locale selection to be different than that on the frontend
include SetsUserLanguageLocaleKey
end
end
end
class Spree::Admin::UserPasswordsController < Devise::PasswordsController
# ...
private
include SetsUserLanguageLocaleKey
end
class Spree::Admin::UserSessionsController < Devise::SessionsController
# ...
private
include SetsUserLanguageLocaleKey
end |
Yes, @gsmendoza, I meant that 🙂 WDYT? |
|
It looks good @waiting-for-dev . So, to recap, here are our TODOs:
@bitberry-dev I'll add these to our TODO list, but if you want to work on them, let us know! |
Okay, thanks! |
Devise::SessionsController classes in SolidusAuthDevise will include this module in order to set the user language locale keys to the admin key. See solidusio/solidus_auth_devise#224 (comment).
The admin authorization prevents a guest user from changing the locale while in the admin login page. See solidusio/solidus_auth_devise#224 (comment).
|
Hi @bitberry-dev ! We have just merged solidusio/solidus#4493. We have to wait until Solidus 3.2 is released before we can include |
Great news 👍 Thank you
Yes, that's right, I got around this problem for several years with my overrides. |
Hehe.. Yeah, let's hope we can get this PR merged soon :) |
|
@bitberry-dev Just to let you know that Solidus 3.2 has been released :) Can you update this PR to include |
|
@gsmendoza PR updated, solidus_auth_devise supports solidus since version 2.6, so I check before include if this concern |
|
@bitberry-dev The code looks good. However, can you rebase your branch against master? That might be needed in order to get CI to pass. Thanks! |
|
@gsmendoza Now all checks passed |
kennyadsl
left a comment
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.
Hello @bitberry-dev! Thanks for the PR and for the back and forth in addressing it. I think that in the end, it has been worth the effort since this seems the cleaner solution.
I have a last request though. If I got it correctly, when we stop supporting Solidus 3.1, we can remove the if and just leave the include. Can we add some reference to that for future developers? I think it's acceptable both as code comment, additional paragraph in the commit description or a note in the PR description, up to you!
Thanks again to you and everyone else involved in this change!
… the devise's backend controllers NOTE: ::Spree::Admin::SetsUserLanguageLocaleKey concern added in Solidus 3.2, so as soon as this gem stops supporting Solidus versions < 3.2 this "if" should be replaced with simple include
|
@kennyadsl Sure, added comments in the code and in commit description |
|
Thanks @bitberry-dev!!! |
|
@kennyadsl You are welcome :) |
Hello guys,
I was removing a devise from one of my projects and came across a few of my notes.
set_user_language_locale_keyis not set:admin_localespree/layouts/admin/login_navis not used anywhere 80bd9f9#r79287230This PR fixes this