A platform for community discussion. Free, open, simple.
FIX: color scheme selection with non-default theme
Penar Musaraj6dd9f2eca253
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 84d7909fa7e..e8c260f7a5a 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -452,7 +452,7 @@ module ApplicationHelperdef discourse_color_scheme_stylesheetsresult = +""- result << Stylesheet::Manager.color_scheme_stylesheet_link_tag(scheme_id)+ result << Stylesheet::Manager.color_scheme_stylesheet_link_tag(scheme_id, 'all', theme_ids)user_dark_scheme_id = current_user&.user_option&.dark_scheme_iddark_scheme_id = user_dark_scheme_id || SiteSetting.default_dark_mode_color_scheme_iddiff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rbindex 5416e381d69..0101847578b 100644--- a/lib/stylesheet/manager.rb+++ b/lib/stylesheet/manager.rb@@ -93,13 +93,15 @@ class Stylesheet::Managerendend- def self.color_scheme_stylesheet_details(color_scheme_id = nil, media)+ def self.color_scheme_stylesheet_details(color_scheme_id = nil, media, theme_id)color_scheme = beginColorScheme.find(color_scheme_id)rescue# don't load fallback when requesting dark color schemereturn false if media != "all"- Theme.find_by_id(SiteSetting.default_theme_id)&.color_scheme || ColorScheme.base++ theme_id = theme_id || SiteSetting.default_theme_id+ Theme.find_by_id(theme_id)&.color_scheme || ColorScheme.baseendreturn false if !color_scheme@@ -121,8 +123,9 @@ class Stylesheet::Managerstylesheetend- def self.color_scheme_stylesheet_link_tag(color_scheme_id = nil, media = 'all')- stylesheet = color_scheme_stylesheet_details(color_scheme_id, media)+ def self.color_scheme_stylesheet_link_tag(color_scheme_id = nil, media = 'all', theme_ids = nil)+ theme_id = theme_ids&.first+ stylesheet = color_scheme_stylesheet_details(color_scheme_id, media, theme_id)return '' if !stylesheethref = stylesheet[:new_href]diff --git a/spec/components/stylesheet/manager_spec.rb b/spec/components/stylesheet/manager_spec.rbindex 0aa0a6c8208..a544d9ee64e 100644--- a/spec/components/stylesheet/manager_spec.rb+++ b/spec/components/stylesheet/manager_spec.rb@@ -208,7 +208,18 @@ describe Stylesheet::Manager doexpect(link).to include("/stylesheets/color_definitions_funky_#{cs.id}_")end- it "uses the correct scheme when colors are passed" do+ it "uses the correct color scheme when a non-default theme is selected and it uses the base 'Light' scheme" do+ cs = Fabricate(:color_scheme, name: 'Not This')+ default_theme = Fabricate(:theme, color_scheme_id: cs.id)+ SiteSetting.default_theme_id = default_theme.id++ user_theme = Fabricate(:theme, color_scheme_id: nil)++ link = Stylesheet::Manager.color_scheme_stylesheet_link_tag(nil, "all", [user_theme.id])+ expect(link).to include("/stylesheets/color_definitions_base_")+ end++ it "uses the correct scheme when a valid scheme id is used" dolink = Stylesheet::Manager.color_scheme_stylesheet_link_tag(ColorScheme.first.id)slug = Slug.for(ColorScheme.first.name) + "_" + ColorScheme.first.id.to_sexpect(link).to include("/stylesheets/color_definitions_#{slug}_")