2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-17 18:04:11 +08:00

FIX: Don't make Horizon's palettes user-selectable (#34062)

Internal topic: t/160291.
This commit is contained in:
Osama Sayegh 2025-08-12 09:23:20 +03:00 committed by GitHub
parent f9d06a78eb
commit 507a90e93a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 15 deletions

View file

@ -11,24 +11,19 @@ class SystemThemesManager
theme_dir = "#{Rails.root}/themes/#{theme_name}"
remote_theme = RemoteTheme.import_theme_from_directory(theme_dir, theme_id: theme_id)
if remote_theme.color_scheme
remote_theme.color_scheme.update!(user_selectable: true)
alternative_theme_name =
if remote_theme.color_scheme.name =~ / Dark$/
remote_theme.color_scheme.name.sub(" Dark", "")
else
"#{remote_theme.color_scheme.name} Dark"
end
is_initial_install = !Theme.exists?(id: theme_id)
alternative_color_scheme =
remote_theme.color_schemes.where(name: alternative_theme_name).first
alternative_color_scheme&.update!(user_selectable: true)
if remote_theme.dark_color_scheme.blank? && alternative_color_scheme
remote_theme.update!(dark_color_scheme: alternative_color_scheme)
remote_theme = RemoteTheme.import_theme_from_directory(theme_dir, theme_id: theme_id)
remote_theme.update_column(:enabled, true)
if is_initial_install
if theme_id == Theme::CORE_THEMES["horizon"]
remote_theme.update!(
dark_color_scheme: remote_theme.color_schemes.find_by(name: "Horizon Dark"),
)
end
end
remote_theme.update_column(:enabled, true)
Stylesheet::Manager.clear_theme_cache!
end

View file

@ -19,4 +19,21 @@ RSpec.describe SystemThemesManager do
SystemThemesManager.sync!
expect(Theme.horizon_theme.reload.enabled).to be true
end
it "sets up the default light and dark palettes for Horizon on the initial install" do
Theme.delete_all
expect { SystemThemesManager.sync! }.to change { Theme.system.count }.by(2)
expect(Theme.horizon_theme.color_scheme.name).to eq("Horizon")
expect(Theme.horizon_theme.dark_color_scheme.name).to eq("Horizon Dark")
Theme.horizon_theme.update!(color_scheme: nil)
Theme.horizon_theme.update!(dark_color_scheme: nil)
expect { SystemThemesManager.sync! }.not_to change { Theme.system.count }
expect(Theme.horizon_theme.color_scheme).to eq(nil)
expect(Theme.horizon_theme.dark_color_scheme).to eq(nil)
end
end