A platform for community discussion. Free, open, simple.
FIX: show target user's interface preferences when viewed by admin (#37853)
Régis Hanola00309030276
diff --git a/frontend/discourse/app/controllers/preferences/interface.js b/frontend/discourse/app/controllers/preferences/interface.jsindex 789a1454c9c..7b3a435d417 100644--- a/frontend/discourse/app/controllers/preferences/interface.js+++ b/frontend/discourse/app/controllers/preferences/interface.js@@ -52,12 +52,6 @@ export default class InterfaceController extends Controller {@propertyEqual("model.id", "currentUser.id") isViewingOwnProfile;subpageTitle = i18n("user.preferences_nav.interface");- init() {- super.init(...arguments);- this.set("selectedDarkColorSchemeId", this.session.userDarkSchemeId);- this.set("selectedColorSchemeId", this.getSelectedColorSchemeId());- }-@discourseComputed("makeThemeDefault")saveAttrNames(makeThemeDefault) {let attrs = [@@ -147,6 +141,10 @@ export default class InterfaceController extends Controller {@discourseComputed("themeId")themeIdChanged(themeId) {+ if (!this.isViewingOwnProfile) {+ return false;+ }+if (this.currentThemeId === -1) {this.set("currentThemeId", themeId);return false;@@ -182,11 +180,19 @@ export default class InterfaceController extends Controller {@discourseComputed("model.user_option.theme_ids", "themeId")showThemeSetDefault(userOptionThemes, selectedTheme) {+ if (!this.isViewingOwnProfile) {+ return false;+ }+return !userOptionThemes || userOptionThemes[0] !== selectedTheme;}@discourseComputed("model.user_option.text_size", "textSize")showTextSetDefault(userOptionTextSize, selectedTextSize) {+ if (!this.isViewingOwnProfile) {+ return false;+ }+return userOptionTextSize !== selectedTextSize;}@@ -413,40 +419,40 @@ export default class InterfaceController extends Controller {.then(() => {this.set("saved", true);- if (makeThemeDefault) {- setLocalTheme([]);- } else {- setLocalTheme(- [this.themeId],- this.get("model.user_option.theme_key_seq")- );- }- if (makeTextSizeDefault) {- this.model.updateTextSizeCookie(null);- } else {- this.model.updateTextSizeCookie(this.textSize);- }-- if (this.makeColorSchemeDefault) {- updateColorSchemeCookie(null);- updateColorSchemeCookie(null, { dark: true });- } else {- updateColorSchemeCookie(this.selectedColorSchemeId);+ if (this.isViewingOwnProfile) {+ if (makeThemeDefault) {+ setLocalTheme([]);+ } else {+ setLocalTheme(+ [this.themeId],+ this.get("model.user_option.theme_key_seq")+ );+ }+ if (makeTextSizeDefault) {+ this.model.updateTextSizeCookie(null);+ } else {+ this.model.updateTextSizeCookie(this.textSize);+ }- if (- this.defaultDarkSchemeId > 0 &&- this.selectedDarkColorSchemeId === this.defaultDarkSchemeId- ) {+ if (this.makeColorSchemeDefault) {+ updateColorSchemeCookie(null);updateColorSchemeCookie(null, { dark: true });} else {- updateColorSchemeCookie(this.selectedDarkColorSchemeId, {- dark: true,- });+ updateColorSchemeCookie(this.selectedColorSchemeId);++ if (+ this.defaultDarkSchemeId > 0 &&+ this.selectedDarkColorSchemeId === this.defaultDarkSchemeId+ ) {+ updateColorSchemeCookie(null, { dark: true });+ } else {+ updateColorSchemeCookie(this.selectedDarkColorSchemeId, {+ dark: true,+ });+ }}- }- if (this.selectedInterfaceColorModeId) {- if (this.isViewingOwnProfile) {+ if (this.selectedInterfaceColorModeId) {const modeId = this.selectedInterfaceColorModeId;if (modeId === INTERFACE_COLOR_MODES.AUTO) {this.interfaceColor.useAutoMode();@@ -456,13 +462,16 @@ export default class InterfaceController extends Controller {this.interfaceColor.forceDarkMode();}}- this.selectedInterfaceColorModeId = null;- }- this.homeChanged();+ this.homeChanged();- if (this.themeId && this.themeId !== this.currentThemeId) {- reload();+ if (this.themeId && this.themeId !== this.currentThemeId) {+ reload();+ }+ }++ if (this.selectedInterfaceColorModeId) {+ this.selectedInterfaceColorModeId = null;}}).catch(popupAjaxError);@@ -470,19 +479,22 @@ export default class InterfaceController extends Controller {@actionselectTextSize(newSize) {- const classList = document.documentElement.classList;-- TEXT_SIZES.forEach((name) => {- const className = `text-size-${name}`;- if (newSize === name) {- classList.add(className);- } else {- classList.remove(className);- }- });+ if (this.isViewingOwnProfile) {+ const classList = document.documentElement.classList;++ TEXT_SIZES.forEach((name) => {+ const className = `text-size-${name}`;+ if (newSize === name) {+ classList.add(className);+ } else {+ classList.remove(className);+ }+ });++ // Force refresh when leaving this screen+ this.session.requiresRefresh = true;+ }- // Force refresh when leaving this screen- this.session.requiresRefresh = true;this.set("textSize", newSize);}diff --git a/frontend/discourse/app/routes/preferences/interface.js b/frontend/discourse/app/routes/preferences/interface.jsindex 8fe1427b1a4..b6f95c26638 100644--- a/frontend/discourse/app/routes/preferences/interface.js+++ b/frontend/discourse/app/routes/preferences/interface.js@@ -3,15 +3,39 @@ import RestrictedUserRoute from "discourse/routes/restricted-user";export default class PreferencesInterface extends RestrictedUserRoute {setupController(controller, user) {+ controller.set("model", user);++ const userThemeIds = user.get("user_option.theme_ids");+ const themeId = controller.isViewingOwnProfile+ ? currentThemeId()+ : (userThemeIds?.[0] ?? currentThemeId());++ const textSize = controller.isViewingOwnProfile+ ? user.get("currentTextSize")+ : user.get("user_option.text_size");+controller.setProperties({- model: user,- textSize: user.get("currentTextSize"),- themeId: currentThemeId(),+ textSize,+ themeId,makeThemeDefault:- !user.get("user_option.theme_ids") ||- currentThemeId() === user.get("user_option.theme_ids")[0],+ !controller.isViewingOwnProfile ||+ !userThemeIds ||+ themeId === userThemeIds[0],makeTextSizeDefault:- user.get("currentTextSize") === user.get("user_option.text_size"),+ !controller.isViewingOwnProfile ||+ textSize === user.get("user_option.text_size"),});++ if (controller.isViewingOwnProfile) {+ controller.setProperties({+ selectedColorSchemeId: controller.getSelectedColorSchemeId(),+ selectedDarkColorSchemeId: controller.session.userDarkSchemeId,+ });+ } else {+ controller.setProperties({+ selectedColorSchemeId: user.get("user_option.color_scheme_id"),+ selectedDarkColorSchemeId: user.get("user_option.dark_scheme_id"),+ });+ }}}diff --git a/spec/system/page_objects/pages/user_preferences_interface.rb b/spec/system/page_objects/pages/user_preferences_interface.rbindex 0d3bf25740c..291742b569d 100644--- a/spec/system/page_objects/pages/user_preferences_interface.rb+++ b/spec/system/page_objects/pages/user_preferences_interface.rb@@ -20,6 +20,14 @@ module PageObjectsselfend+ def theme_dropdown+ PageObjects::Components::SelectKit.new("[data-setting-name='user-theme'] .combo-box")+ end++ def text_size_dropdown+ PageObjects::Components::SelectKit.new("[data-setting-name='user-text-size'] .combo-box")+ end+def light_scheme_dropdownPageObjects::Components::SelectKit.new(".light-color-scheme .select-kit")enddiff --git a/spec/system/user_page/user_preferences_interface_spec.rb b/spec/system/user_page/user_preferences_interface_spec.rbindex 72b509c944b..2cacfc601c7 100644--- a/spec/system/user_page/user_preferences_interface_spec.rb+++ b/spec/system/user_page/user_preferences_interface_spec.rb@@ -324,6 +324,21 @@ describe "User preferences | Interface", type: :system docontext "when changing another user's preferences as an admin" dofab!(:admin)+ fab!(:user_selectable_theme) { Fabricate(:theme, user_selectable: true) }+ fab!(:user_selectable_color_scheme) do+ Fabricate(+ :color_scheme,+ base_scheme_id: ColorScheme::NAMES_TO_ID_MAP["Light"],+ user_selectable: true,+ )+ end+ fab!(:user_selectable_dark_color_scheme) do+ Fabricate(+ :color_scheme,+ base_scheme_id: ColorScheme::NAMES_TO_ID_MAP["Dark"],+ user_selectable: true,+ )+ endbefore dosign_in(admin)@@ -335,6 +350,43 @@ describe "User preferences | Interface", type: :system do)end+ it "shows the target user's theme, color palette, and text size, not the admin's" do+ admin.user_option.update!(+ theme_ids: [SiteSetting.default_theme_id],+ color_scheme_id: nil,+ dark_scheme_id: nil,+ text_size: :normal,+ )+ user.user_option.update!(+ theme_ids: [user_selectable_theme.id],+ color_scheme_id: user_selectable_color_scheme.id,+ dark_scheme_id: user_selectable_dark_color_scheme.id,+ text_size: :larger,+ )++ user_preferences_interface_page.visit(user)++ expect(user_preferences_interface_page.theme_dropdown).to have_selected_value(+ user_selectable_theme.id,+ ),+ "the theme dropdown should show the target user's theme"++ expect(user_preferences_interface_page.light_scheme_dropdown).to have_selected_value(+ user_selectable_color_scheme.id,+ ),+ "the light color palette dropdown should show the target user's color scheme"++ expect(user_preferences_interface_page.dark_scheme_dropdown).to have_selected_value(+ user_selectable_dark_color_scheme.id,+ ),+ "the dark color palette dropdown should show the target user's dark color scheme"++ expect(user_preferences_interface_page.text_size_dropdown).to have_selected_name(+ I18n.t("js.user.text_size.larger"),+ ),+ "the text size dropdown should show the target user's text size"+ end+it "doesn't affect the viewing admin preferences and changes the target user's default preference for all devices" douser_preferences_interface_page.visit(user)