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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread-safe locale switching #4237

Merged
merged 1 commit into from Oct 5, 2018
Merged

Conversation

deivid-rodriguez
Copy link
Contributor

@deivid-rodriguez deivid-rodriguez commented Oct 5, 2018

馃帺 What? Why?

Decidim is not changing locales in a thread-safe manner, as explained in this rails issue. So after one request changes the locale, another request could accidentally use the changed value.

馃搶 Related Issues

馃搵 Subtasks

  • Add CHANGELOG entry
  • Add documentation regarding the feature
  • Add/modify seeds
  • Add tests
  • Another subtask

馃摲 Screenshots (optional)

None.

@ghost ghost assigned deivid-rodriguez Oct 5, 2018
@ghost ghost added the status: WIP label Oct 5, 2018
locale = if params["locale"]
params["locale"]
elsif current_user && current_user.locale.present?
current_user.locale
end

I18n.locale = available_locales.include?(locale) ? locale : default_locale
I18n.with_locale(available_locales.include?(locale) ? locale : default_locale, &action)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case someone checks this code and wonders (like me) where are we changing the user locale, we currently do this here:

def create
enforce_permission_to :create, :locales
current_user.update!(locale: params["locale"]) if current_user && params["locale"] && available_locales.include?(params["locale"])
redirect_to referer_with_new_locale
end

mrcasals
mrcasals previously approved these changes Oct 5, 2018
Copy link
Contributor

@mrcasals mrcasals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for the PR! 馃槃

@mrcasals
Copy link
Contributor

mrcasals commented Oct 5, 2018

I don't think this requires a Changelog entry.

@deivid-rodriguez is this ready for merge? 馃槃

@deivid-rodriguez
Copy link
Contributor Author

deivid-rodriguez commented Oct 5, 2018

Actually I wrote a changelog entry, but forgot to push it! Since this might fix a real end user problem, I think a changelog entry is good!

@mrcasals
Copy link
Contributor

mrcasals commented Oct 5, 2018

Cool, thanks! Merging this! 馃槃

@mrcasals mrcasals merged commit 03fe62e into master Oct 5, 2018
@mrcasals mrcasals deleted the thread_safe_locale_switching branch October 5, 2018 11:59
tramuntanal pushed a commit that referenced this pull request Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notification in French with Decidim in Catalan and Spanish
2 participants