mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 18:48:01 +08:00
When an admin viewed another user's interface preferences page, the theme, color palette, text size, and color mode dropdowns all showed the admin's own values instead of the target user's. Saving changes also incorrectly set cookies and applied live previews in the admin's browser. This happened because the route and controller sourced display values from the current session (DOM meta tags, cookies, session store) rather than from the target user's serialized `user_option`. The fix checks `isViewingOwnProfile` (already defined on the controller) and branches accordingly: - Route: sets `themeId`, `textSize`, `selectedColorSchemeId`, and `selectedDarkColorSchemeId` from the target user's `user_option` when viewing another user, and from session/cookies when viewing own profile. - Controller: guards all live preview side effects (`selectTextSize` DOM class changes, `save()` cookie writes, theme reload, homepage change) behind `isViewingOwnProfile`. - Hides "Make this the default on all my devices" checkboxes and the "theme will update" alert when viewing another user, since per-device overrides don't apply. - Removes the now-redundant `init()` color scheme initialization since `setupController` always sets these values. https://meta.discourse.org/t/387511
72 lines
2.1 KiB
Ruby
72 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module PageObjects
|
|
module Pages
|
|
class UserPreferencesInterface < PageObjects::Pages::Base
|
|
def visit(user)
|
|
page.visit("/u/#{user.username}/preferences/interface")
|
|
self
|
|
end
|
|
|
|
def has_bookmark_after_notification_mode?(value)
|
|
page.has_css?(
|
|
"#bookmark-after-notification-mode .select-kit-header[data-value=\"#{value}\"]",
|
|
)
|
|
end
|
|
|
|
def select_bookmark_after_notification_mode(value)
|
|
page.find("#bookmark-after-notification-mode").click
|
|
page.find(".select-kit-row[data-value=\"#{value}\"]").click
|
|
self
|
|
end
|
|
|
|
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_dropdown
|
|
PageObjects::Components::SelectKit.new(".light-color-scheme .select-kit")
|
|
end
|
|
|
|
def dark_scheme_dropdown
|
|
PageObjects::Components::SelectKit.new(".dark-color-scheme .select-kit")
|
|
end
|
|
|
|
def has_light_scheme_css?(color_scheme)
|
|
expect(page).to have_css(
|
|
"link.light-scheme[data-scheme-id=\"#{color_scheme.id}\"]",
|
|
visible: false,
|
|
)
|
|
end
|
|
|
|
def has_dark_scheme_css?(color_scheme)
|
|
expect(page).to have_css(
|
|
"link.dark-scheme[data-scheme-id=\"#{color_scheme.id}\"]",
|
|
visible: false,
|
|
)
|
|
end
|
|
|
|
def color_mode_dropdown
|
|
PageObjects::Components::SelectKit.new(".interface-color-mode .select-kit")
|
|
end
|
|
|
|
def default_palette_and_mode_for_all_devices_checkbox
|
|
find(".color-scheme-checkbox input[type='checkbox']")
|
|
end
|
|
|
|
def has_no_default_palette_and_mode_for_all_devices_checkbox?
|
|
has_no_css?(".color-scheme-checkbox input[type='checkbox']")
|
|
end
|
|
|
|
def save_changes
|
|
click_button "Save Changes"
|
|
expect(page).to have_content(I18n.t("js.saved"))
|
|
self
|
|
end
|
|
end
|
|
end
|
|
end
|