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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[34594] Show confirmation message in the selected language
Christophe Bliarddfbe67205b6a
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rbindex f6711bd12b4..0de84fa887e 100644--- a/app/controllers/my_controller.rb+++ b/app/controllers/my_controller.rb@@ -149,18 +149,14 @@ class MyController < ApplicationControllerenddef 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_updatedelse- 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)endredirect_back(fallback_location: my_account_path)@@ -172,6 +168,21 @@ class MyController < ApplicationControllerSetting.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_userenddiff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rbindex 16571b5ad89..60e2f2d5771 100644--- a/spec/controllers/my_controller_spec.rb+++ b/spec/controllers/my_controller_spec.rb@@ -155,18 +155,20 @@ describe MyController doenddescribe 'settings' do- context 'PATCH' do+ describe 'PATCH' do+ let(:language) { 'en' }+before doas_logged_in_user user douser.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 } }endendit 'updates the settings appropriately', :aggregate_failures do- expect(assigns(:user).language).to eq 'en'+ expect(assigns(:user).language).to eq languageexpect(assigns(:user).pref.comments_sorting).to eql 'desc'expect(assigns(:user).pref.auto_hide_popups?).to be_falsey@@ -186,6 +188,15 @@ describe MyController doexpect(request.path).to eq(my_settings_path)endend++ 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+ endendend