Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[34594] Show confirmation message in the selected language

Christophe Bliarddfbe67205b6a
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index f6711bd12b4..0de84fa887e 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -149,18 +149,14 @@ class MyController < ApplicationController
end
def write_settings
- user_params = permitted_params.my_account_settings
-
result = Users::UpdateService
.new(user: current_user, model: current_user)
- .call(user_params.to_h)
+ .call(user_params)
if result&.success
- flash[:notice] = t(:notice_account_updated)
+ flash[:notice] = notice_account_updated
else
- errors = result ? result.errors.full_messages.join("\n") : ''
- flash[:error] = [t(:notice_account_update_failed)]
- flash[:error] << errors
+ flash[:error] = error_account_update_failed(result)
end
redirect_back(fallback_location: my_account_path)
@@ -172,6 +168,21 @@ class MyController < ApplicationController
Setting.feeds_enabled? || Setting.rest_api_enabled?
end
+ def user_params
+ permitted_params.my_account_settings.to_h
+ end
+
+ def notice_account_updated
+ OpenProject::LocaleHelper.with_locale_for(current_user) do
+ t(:notice_account_updated)
+ end
+ end
+
+ def error_account_update_failed(result)
+ errors = result ? result.errors.full_messages.join("\n") : ''
+ [t(:notice_account_update_failed), errors]
+ end
+
def set_current_user
@user = current_user
end
diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb
index 16571b5ad89..60e2f2d5771 100644
--- a/spec/controllers/my_controller_spec.rb
+++ b/spec/controllers/my_controller_spec.rb
@@ -155,18 +155,20 @@ describe MyController do
end
describe 'settings' do
- context 'PATCH' do
+ describe 'PATCH' do
+ let(:language) { 'en' }
+
before do
as_logged_in_user user do
user.pref.comments_sorting = 'desc'
user.pref.auto_hide_popups = true
- patch :update_settings, params: { user: { language: 'en' }, pref: { auto_hide_popups: 0 } }
+ patch :update_settings, params: { user: { language: }, pref: { auto_hide_popups: 0 } }
end
end
it 'updates the settings appropriately', :aggregate_failures do
- expect(assigns(:user).language).to eq 'en'
+ expect(assigns(:user).language).to eq language
expect(assigns(:user).pref.comments_sorting).to eql 'desc'
expect(assigns(:user).pref.auto_hide_popups?).to be_falsey
@@ -186,6 +188,15 @@ describe MyController do
expect(request.path).to eq(my_settings_path)
end
end
+
+ context 'when changing language' do
+ let(:language) { 'de' }
+
+ it 'shows a flash message translated in the selected language' do
+ expect(assigns(:user).language).to eq(language)
+ expect(flash[:notice]).to eq(I18n.t(:notice_account_updated, locale: language))
+ end
+ end
end
end