A platform for community discussion. Free, open, simple.
FIX: Ensure language header selections do not silently get added to 'Languages I understand' (#42294)
Natalie Tay382336da4860
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rbindex c8e538753af..d4fac7bd6eb 100644--- a/app/services/user_updater.rb+++ b/app/services/user_updater.rb@@ -191,13 +191,6 @@ class UserUpdaterattributes[:text_size]end- if attributes.key?(:locale) || attributes.key?(:understood_languages)- understood_languages =- attributes.fetch(:understood_languages) { user.user_option.understood_languages }- interface_locale = user.effective_locale- attributes[:understood_languages] = [interface_locale, *understood_languages].compact.uniq- end-OPTION_ATTR.each do |attribute|if attributes.key?(attribute)save_options = truediff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex e635f0dbcbc..3a466f0c652 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -2720,7 +2720,7 @@ RSpec.describe UsersController do).pluck(:tag_id),).to contain_exactly(tags[0].id, tags[1].id)expect(user.user_option.automatically_translate).to eq(false)- expect(user.user_option.understood_languages).to contain_exactly("en", "ja")+ expect(user.user_option.understood_languages).to contain_exactly("ja")theme = Fabricate(:theme, user_selectable: true)diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex b6a3b4d554b..ce6d5c21194 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -46,24 +46,33 @@ RSpec.describe UserUpdater doexpect(user.reload.name).to eq "Jim Tom"end- it "keeps the interface locale among the user's understood languages" do+ it "preserves explicitly submitted understood languages when the interface locale changes" douser.update!(locale: "en")- user.user_option.update!(understood_languages: ["en"])- UserUpdater.new(user, user).update(locale: "ja", understood_languages: [])+ UserUpdater.new(user, user).update(locale: "ja", understood_languages: %w[ja de])expect(user.reload.locale).to eq("ja")- expect(user.user_option.understood_languages).to eq(["ja"])+ expect(user.user_option.understood_languages).to eq(%w[ja de])end- it "uses the effective interface locale when user locales are disabled" do+ it "preserves understood languages when only the interface locale changes" do+ user.update!(locale: "en")+ user.user_option.update!(understood_languages: ["de"])++ UserUpdater.new(user, user).update(locale: "ja")++ expect(user.reload.locale).to eq("ja")+ expect(user.user_option.understood_languages).to eq(["de"])+ end++ it "preserves explicitly submitted understood languages when user locales are disabled" doSiteSetting.default_locale = "en"SiteSetting.allow_user_locale = falseuser.update!(locale: "fr")- UserUpdater.new(user, user).update(understood_languages: [])+ UserUpdater.new(user, user).update(understood_languages: %w[en ja])- expect(user.user_option.understood_languages).to eq(["en"])+ expect(user.user_option.understood_languages).to eq(%w[en ja])endit "adapts legacy show-original updates to the positive preference" dodiff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rbindex b37382fd63c..94fec5237e1 100644--- a/spec/system/content_localization_spec.rb+++ b/spec/system/content_localization_spec.rb@@ -118,11 +118,11 @@ describe "Content Localization" dopreferences_interface_page.enable_automatic_translation.save_changespage.refreshexpect(preferences_interface_page).to be_automatic_translation_enabled- expect(preferences_interface_page).to have_understood_language("en")+ expect(preferences_interface_page).to have_no_understood_language("en")topic_page.visit_topic(topic)- expect(topic_page).to have_topic_title("Life strategies from The Art of War")- expect(post_1_obj).to have_cooked_content(post_1.raw)+ expect(topic_page).to have_topic_title("孫子兵法からの人生戦略")+ expect(post_1_obj).to have_cooked_content("傑作は単なる軍事戦略についてではありません")expect(post_3_obj).to have_cooked_content(post_3.raw)expect(topic_page).to have_topic_tag("戦略")expect(sidebar).to have_section_link("戦略")diff --git a/spec/system/page_objects/pages/user_preferences_interface.rb b/spec/system/page_objects/pages/user_preferences_interface.rbindex 945f0dcf53d..c398c87372f 100644--- a/spec/system/page_objects/pages/user_preferences_interface.rb+++ b/spec/system/page_objects/pages/user_preferences_interface.rb@@ -70,6 +70,16 @@ module PageObjectsresultend+ def has_no_understood_language?(locale)+ understood_languages_dropdown.expand+ result =+ page.has_no_css?(+ "#understood-languages-selector .selected-choice[data-value='#{locale}']",+ )+ understood_languages_dropdown.collapse+ result+ end+def has_understood_language_option?(locale)understood_languages_dropdown.expandresult =