Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: add modifier to restrict theme color schemes (#38796)

Krisdbcbd0d896f0
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1aecf16575d..e90e0d2eff1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -681,7 +681,11 @@ module ApplicationHelper
def scheme_id
return @scheme_id if defined?(@scheme_id)
- return user_scheme_id if user_scheme_id
+ if user_scheme_id
+ return user_scheme_id unless theme_limits_color_schemes?
+ return user_scheme_id if ColorScheme.exists?(id: user_scheme_id, theme_id: theme_id)
+ end
+
return if theme_id.blank?
@scheme_id = Theme.where(id: theme_id).pick(:color_scheme_id)
@@ -694,8 +698,23 @@ module ApplicationHelper
end
def dark_scheme_id
- user_dark_scheme_id ||
- (theme_id ? Theme.find_by_id(theme_id) : Theme.find_default)&.dark_color_scheme_id || -1
+ if user_dark_scheme_id
+ return user_dark_scheme_id unless theme_limits_color_schemes?
+ return user_dark_scheme_id if ColorScheme.exists?(id: user_dark_scheme_id, theme_id: theme_id)
+ end
+
+ theme = theme_id ? Theme.find_by_id(theme_id) : Theme.find_default
+ dark_id = theme&.dark_color_scheme_id
+ return dark_id if dark_id.present?
+ return theme&.color_scheme_id if theme_limits_color_schemes?
+ -1
+ end
+
+ def theme_limits_color_schemes?
+ return @theme_limits_color_schemes if defined?(@theme_limits_color_schemes)
+ @theme_limits_color_schemes =
+ theme_id.present? &&
+ ThemeModifierSet.exists?(theme_id: theme_id, only_theme_color_schemes: true)
end
def current_homepage
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb
index 5ed758e4eec..95eadfb6b40 100644
--- a/app/models/remote_theme.rb
+++ b/app/models/remote_theme.rb
@@ -493,7 +493,16 @@ class RemoteTheme < ActiveRecord::Base
ColorScheme.unscoped.where(id: to_be_deleted_ids).destroy_all
end
- theme.color_scheme = ordered_schemes.first if theme.new_record?
+ if theme.new_record? && ordered_schemes.present?
+ if theme.theme_modifier_set.only_theme_color_schemes
+ light = ordered_schemes.find { |s| !s.is_dark? } || ordered_schemes.first
+ dark = ordered_schemes.find { |s| s.is_dark? } || ordered_schemes.first
+ theme.color_scheme = light
+ theme.dark_color_scheme = dark
+ else
+ theme.color_scheme = ordered_schemes.first
+ end
+ end
end
def create_theme_site_settings(theme, theme_site_settings)
diff --git a/app/models/theme.rb b/app/models/theme.rb
index 8a831046ee4..778a876f1f4 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -120,6 +120,7 @@ class Theme < ActiveRecord::Base
:user,
:locale_fields,
:theme_translation_overrides,
+ :theme_modifier_set,
color_scheme: %i[theme color_scheme_colors base_scheme],
parent_themes: %i[color_scheme locale_fields theme_translation_overrides],
)
diff --git a/app/models/theme_modifier_set.rb b/app/models/theme_modifier_set.rb
index 35afc214bdc..7b46870758d 100644
--- a/app/models/theme_modifier_set.rb
+++ b/app/models/theme_modifier_set.rb
@@ -29,6 +29,10 @@ class ThemeModifierSet < ActiveRecord::Base
after_save do
SvgSprite.expire_cache if saved_change_to_svg_icons?
CSP::Extension.clear_theme_extensions_cache! if saved_change_to_csp_extensions?
+ if saved_change_to_only_theme_color_schemes?
+ ApplicationSerializer.expire_cache_fragment!("user_color_schemes")
+ ApplicationSerializer.expire_cache_fragment!("user_themes")
+ end
end
# Given the ids of multiple active themes / theme components, this function
@@ -141,16 +145,17 @@ end
# Table name: theme_modifier_sets
#
# id :bigint not null, primary key
-# theme_id :bigint not null
-# serialize_topic_excerpts :boolean
# csp_extensions :string is an Array
-# svg_icons :string is an Array
-# topic_thumbnail_sizes :string is an Array
# custom_homepage :boolean
+# only_theme_color_schemes :boolean
# serialize_post_user_badges :string is an Array
-# theme_setting_modifiers :jsonb
-# serialize_topic_op_likes_data :boolean
+# serialize_topic_excerpts :boolean
# serialize_topic_is_hot :boolean
+# serialize_topic_op_likes_data :boolean
+# svg_icons :string is an Array
+# theme_setting_modifiers :jsonb
+# topic_thumbnail_sizes :string is an Array
+# theme_id :bigint not null
#
# Indexes
#
diff --git a/app/serializers/color_scheme_serializer.rb b/app/serializers/color_scheme_serializer.rb
index b0391680f6a..d0e91858bee 100644
--- a/app/serializers/color_scheme_serializer.rb
+++ b/app/serializers/color_scheme_serializer.rb
@@ -8,13 +8,18 @@ class ColorSchemeSerializer < ApplicationSerializer
:theme_id,
:theme_name,
:user_selectable,
- :is_builtin_default
+ :is_builtin_default,
+ :is_dark
has_many :colors, serializer: ColorSchemeColorSerializer, embed: :objects
def theme_name
object.theme&.name
end
+ def is_dark
+ object.is_dark?
+ end
+
def colors
db_colors = object.colors.sort_by(&:name).index_by(&:name)
resolved = ColorScheme.sort_colors(object.resolved_colors)
diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb
index 0dbffed075d..9138d76e7fd 100644
--- a/app/serializers/site_serializer.rb
+++ b/app/serializers/site_serializer.rb
@@ -62,10 +62,19 @@ class SiteSerializer < ApplicationSerializer
def user_themes
cache_fragment("user_themes") do
- Theme
- .where("id = :default OR user_selectable", default: SiteSetting.default_theme_id)
- .order("lower(name)")
- .pluck(:id, :name, :color_scheme_id, :dark_color_scheme_id)
+ themes =
+ Theme
+ .where("id = :default OR user_selectable", default: SiteSetting.default_theme_id)
+ .order("lower(name)")
+ .pluck(:id, :name, :color_scheme_id, :dark_color_scheme_id)
+
+ modifier_theme_ids =
+ ThemeModifierSet
+ .where(theme_id: themes.map(&:first), only_theme_color_schemes: true)
+ .pluck(:theme_id)
+ .to_set
+
+ themes
.map do |id, name, color_scheme_id, dark_color_scheme_id|
{
theme_id: id,
@@ -73,6 +82,7 @@ class SiteSerializer < ApplicationSerializer
default: id == SiteSetting.default_theme_id,
color_scheme_id: color_scheme_id,
dark_color_scheme_id: dark_color_scheme_id,
+ only_theme_color_schemes: modifier_theme_ids.include?(id),
}
end
.as_json
@@ -81,7 +91,16 @@ class SiteSerializer < ApplicationSerializer
def user_color_schemes
cache_fragment("user_color_schemes") do
- schemes = ColorScheme.includes(:color_scheme_colors).where("user_selectable").order(:name)
+ theme_ids_with_modifier =
+ ThemeModifierSet.where(only_theme_color_schemes: true).pluck(:theme_id)
+
+ schemes =
+ ColorScheme
+ .includes(:color_scheme_colors)
+ .where(user_selectable: true)
+ .or(ColorScheme.where(theme_id: theme_ids_with_modifier))
+ .order(:name)
+
ActiveModel::ArraySerializer.new(
schemes,
each_serializer: ColorSchemeSelectableSerializer,
diff --git a/app/serializers/theme_serializer.rb b/app/serializers/theme_serializer.rb
index a334e8fdbbf..7406eb94807 100644
--- a/app/serializers/theme_serializer.rb
+++ b/app/serializers/theme_serializer.rb
@@ -17,7 +17,8 @@ class ThemeSerializer < BasicThemeSerializer
:theme_fields,
:screenshot_dark_url,
:screenshot_light_url,
- :system
+ :system,
+ :only_theme_color_schemes
has_one :color_scheme, serializer: ColorSchemeSerializer, embed: :object
has_one :user, serializer: UserNameSerializer, embed: :object
@@ -105,4 +106,8 @@ class ThemeSerializer < BasicThemeSerializer
def system
object.system?
end
+
+ def only_theme_color_schemes
+ object.theme_modifier_set&.only_theme_color_schemes || false
+ end
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 46929d7869b..8eadd504d71 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7494,6 +7494,7 @@ en:
dark_color_scheme: "Dark Color Palette"
default_light_scheme: "Light (default)"
color_scheme_select: "Select colors to be used by theme."
+ only_theme_color_schemes: "This theme limits which color palettes can be used."
dark_color_scheme_select: "Select colors to be used by theme in dark mode."
edit_colors: "Edit colors"
custom_sections: "Custom sections:"
diff --git a/db/migrate/20260323145627_add_limit_color_schemes_to_theme_modifier.rb b/db/migrate/20260323145627_add_limit_color_schemes_to_theme_modifier.rb
new file mode 100644
index 00000000000..9d1db2448f5
--- /dev/null
+++ b/db/migrate/20260323145627_add_limit_color_schemes_to_theme_modifier.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: true
+class AddLimitColorSchemesToThemeModifier < ActiveRecord::Migration[8.0]
+ def change
+ add_column :theme_modifier_sets, :only_theme_color_schemes, :boolean, null: true
+ end
+end
diff --git a/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js b/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js
index 32c06eaa62b..db9b73e2377 100644
--- a/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js
+++ b/frontend/discourse/admin/controllers/admin-customize-themes/show/index.js
@@ -89,6 +89,31 @@ export default class AdminCustomizeThemesShowIndexController extends Controller
return descriptions;
}
+ @computed("colorSchemes.[]", "model.only_theme_color_schemes", "model.id")
+ get filteredColorSchemes() {
+ if (!this.model?.only_theme_color_schemes) {
+ return this.colorSchemes;
+ }
+ const themeSchemes = this.colorSchemes?.filter(
+ (scheme) => scheme.theme_id === this.model.id
+ );
+ return themeSchemes?.length > 0 ? themeSchemes : this.colorSchemes;
+ }
+
+ @computed("filteredColorSchemes.[]", "model.only_theme_color_schemes")
+ get showColorSchemePickers() {
+ if (!this.model?.only_theme_color_schemes) {
+ return true;
+ }
+ const schemes = this.filteredColorSchemes;
+ if (!schemes) {
+ return true;
+ }
+ const lightCount = schemes.filter((s) => !s.is_dark).length;
+ const darkCount = schemes.filter((s) => s.is_dark).length;
+ return lightCount > 1 || darkCount > 1;
+ }
+
@computed("colorSchemeId", "model.color_scheme_id")
get lightColorSchemeChanged() {
const colorSchemeId =
diff --git a/frontend/discourse/admin/templates/admin-customize-themes/show.gjs b/frontend/discourse/admin/templates/admin-customize-themes/show.gjs
index 0fb9283f8a0..10d7dcfb74a 100644
--- a/frontend/discourse/admin/templates/admin-customize-themes/show.gjs
+++ b/frontend/discourse/admin/templates/admin-customize-themes/show.gjs
@@ -245,6 +245,12 @@ export default <template>
</div>
{{/if}}
+ {{#if @controller.model.only_theme_color_schemes}}
+ <div class="alert alert-info">
+ {{i18n "admin.customize.theme.only_theme_color_schemes"}}
+ </div>
+ {{/if}}
+
{{outlet}}
{{/if}}
</div>
diff --git a/frontend/discourse/admin/templates/admin-customize-themes/show/index.gjs b/frontend/discourse/admin/templates/admin-customize-themes/show/index.gjs
index a629849286a..e6ed5251959 100644
--- a/frontend/discourse/admin/templates/admin-customize-themes/show/index.gjs
+++ b/frontend/discourse/admin/templates/admin-customize-themes/show/index.gjs
@@ -117,110 +117,116 @@ export default <template>
{{/if}}
{{#unless @controller.model.component}}
- <section
- class="form-horizontal theme settings control-unit theme-settings__light-color-scheme"
- >
- <div class="row setting">
- <div class="setting-label">
- {{i18n "admin.customize.theme.color_scheme"}}
- </div>
+ {{#if @controller.showColorSchemePickers}}
+ <section
+ class="form-horizontal theme settings control-unit theme-settings__light-color-scheme"
+ >
+ <div class="row setting">
+ <div class="setting-label">
+ {{i18n "admin.customize.theme.color_scheme"}}
+ </div>
+
+ <div class="setting-value">
+ <div class="color-palette-input-group">
+ <ColorPalettePicker
+ @content={{@controller.filteredColorSchemes}}
+ @value={{@controller.colorSchemeId}}
+ @icon="paintbrush"
+ @options={{hash
+ filterable=true
+ translatedNone=(unless
+ @controller.model.only_theme_color_schemes
+ (i18n "admin.customize.theme.default_light_scheme")
+ )
+ }}
+ />
+ </div>
- <div class="setting-value">
- <div class="color-palette-input-group">
- <ColorPalettePicker
- @content={{@controller.colorSchemes}}
- @value={{@controller.colorSchemeId}}
- @icon="paintbrush"
- @options={{hash
- filterable=true
- translatedNone=(i18n
- "admin.customize.theme.default_light_scheme"
- )
+ <div class="desc">{{i18n
+ "admin.customize.theme.color_scheme_select"
}}
- />
- </div>
- <div class="desc">{{i18n "admin.customize.theme.color_scheme_select"}}
+ {{#if @controller.colorSchemeId}}
+ <LinkTo
+ @route="adminConfig.colorPalettes.show"
+ @model={{@controller.colorSchemeId}}
+ >
+ {{i18n "admin.customize.theme.edit_colors"}}
+ </LinkTo>
+ {{/if}}
+ </div>
+ </div>
- {{#if @controller.colorSchemeId}}
- <LinkTo
- @route="adminConfig.colorPalettes.show"
- @model={{@controller.colorSchemeId}}
- >
- {{i18n "admin.customize.theme.edit_colors"}}
- </LinkTo>
+ <div class="setting-controls">
+ {{#if @controller.lightColorSchemeChanged}}
+ <DButton
+ @action={{@controller.changeLightScheme}}
+ @icon="check"
+ class="ok submit-light-edit"
+ />
+ <DButton
+ @action={{@controller.cancelChangeLightScheme}}
+ @icon="xmark"
+ class="cancel cancel-light-edit"
+ />
{{/if}}
</div>
</div>
-
- <div class="setting-controls">
- {{#if @controller.lightColorSchemeChanged}}
- <DButton
- @action={{@controller.changeLightScheme}}
- @icon="check"
- class="ok submit-light-edit"
- />
- <DButton
- @action={{@controller.cancelChangeLightScheme}}
- @icon="xmark"
- class="cancel cancel-light-edit"
- />
- {{/if}}
- </div>
- </div>
- </section>
- <section
- class="form-horizontal theme settings control-unit theme-settings__dark-color-scheme"
- >
- <div class="row setting">
- <div class="setting-label">
- {{i18n "admin.customize.theme.dark_color_scheme"}}
- </div>
-
- <div class="setting-value">
- <div class="color-palette-input-group">
- <ColorPalettePicker
- @content={{@controller.colorSchemes}}
- @value={{@controller.darkColorSchemeId}}
- @icon="paintbrush"
- @options={{hash
- filterable=true
- translatedNone=(i18n
- "admin.customize.theme.default_light_scheme"
- )
- }}
- />
+ </section>
+ <section
+ class="form-horizontal theme settings control-unit theme-settings__dark-color-scheme"
+ >
+ <div class="row setting">
+ <div class="setting-label">
+ {{i18n "admin.customize.theme.dark_color_scheme"}}
</div>
- <div class="desc">
- {{i18n "admin.customize.theme.dark_color_scheme_select"}}
+ <div class="setting-value">
+ <div class="color-palette-input-group">
+ <ColorPalettePicker
+ @content={{@controller.filteredColorSchemes}}
+ @value={{@controller.darkColorSchemeId}}
+ @icon="paintbrush"
+ @options={{hash
+ filterable=true
+ translatedNone=(unless
+ @controller.model.only_theme_color_schemes
+ (i18n "admin.customize.theme.default_light_scheme")
+ )
+ }}
+ />
+ </div>
- {{#if @controller.darkColorSchemeId}}
- <LinkTo
- @route="adminConfig.colorPalettes.show"
- @model={{@controller.darkColorSchemeId}}
- >
- {{i18n "admin.customize.theme.edit_colors"}}
- </LinkTo>
+ <div class="desc">
+ {{i18n "admin.customize.theme.dark_color_scheme_select"}}
+
+ {{#if @controller.darkColorSchemeId}}
+ <LinkTo
+ @route="adminConfig.colorPalettes.show"
+ @model={{@controller.darkColorSchemeId}}
+ >
+ {{i18n "admin.customize.theme.edit_colors"}}
+ </LinkTo>
+ {{/if}}
+ </div>
+ </div>
+ <div class="setting-controls">
+ {{#if @controller.darkColorSchemeChanged}}
+ <DButton
+ @action={{@controller.changeDarkScheme}}
+ @icon="check"
+ class="ok submit-dark-edit"
+ />
+ <DButton
+ @action={{@controller.cancelChangeDarkScheme}}
+ @icon="xmark"
+ class="cancel cancel-dark-edit"
+ />
{{/if}}
</div>
</div>
- <div class="setting-controls">
- {{#if @controller.darkColorSchemeChanged}}
- <DButton
- @action={{@controller.changeDarkScheme}}
- @icon="check"
- class="ok submit-dark-edit"
- />
- <DButton
- @action={{@controller.cancelChangeDarkScheme}}
- @icon="xmark"
- class="cancel cancel-dark-edit"
- />
- {{/if}}
- </div>
- </div>
- </section>
+ </section>
+ {{/if}}
{{/unless}}
{{#if @controller.model.component}}
diff --git a/frontend/discourse/app/controllers/preferences/interface.js b/frontend/discourse/app/controllers/preferences/interface.js
index 7f389b53890..e2ae140294b 100644
--- a/frontend/discourse/app/controllers/preferences/interface.js
+++ b/frontend/discourse/app/controllers/preferences/interface.js
@@ -154,9 +154,19 @@ export default class InterfaceController extends Controller {
}
}
- @computed
+ @computed("currentThemeId")
+ get currentThemeForColorSchemes() {
+ const theme = this.userSelectableThemes?.find(
+ (t) => t.id === this.currentThemeId
+ );
+ return theme;
+ }
+
+ @computed("currentThemeId")
get userSelectableColorSchemes() {
- return listColorSchemes(this.site);
+ return listColorSchemes(this.site, {
+ currentTheme: this.currentThemeForColorSchemes,
+ });
}
@computed("userSelectableThemes", "userSelectableColorSchemes", "themeId")
@@ -301,10 +311,11 @@ export default class InterfaceController extends Controller {
);
}
- @computed
+ @computed("currentThemeId")
get userSelectableDarkColorSchemes() {
return listColorSchemes(this.site, {
darkOnly: true,
+ currentTheme: this.currentThemeForColorSchemes,
});
}
@@ -317,20 +328,30 @@ export default class InterfaceController extends Controller {
);
}
- @computed("userSelectableColorSchemes")
+ @computed("userSelectableColorSchemes", "currentThemeId")
get showLightColorSchemeSelector() {
- return (
- this.userSelectableColorSchemes &&
- this.userSelectableColorSchemes.length > 1
- );
+ const schemes = this.userSelectableColorSchemes;
+ if (!schemes || schemes.length <= 1) {
+ return false;
+ }
+ const theme = this.currentThemeForColorSchemes;
+ if (theme?.only_theme_color_schemes) {
+ return schemes.filter((s) => !s.is_dark).length > 1;
+ }
+ return true;
}
- @computed("userSelectableDarkColorSchemes")
+ @computed("userSelectableDarkColorSchemes", "currentThemeId")
get showDarkColorSchemeSelector() {
- return (
- this.userSelectableDarkColorSchemes &&
- this.userSelectableDarkColorSchemes.length > 1
- );
+ const schemes = this.userSelectableDarkColorSchemes;
+ if (!schemes || schemes.length <= 1) {
+ return false;
+ }
+ const theme = this.currentThemeForColorSchemes;
+ if (theme?.only_theme_color_schemes) {
+ return schemes.filter((s) => s.is_dark).length > 1;
+ }
+ return true;
}
get interfaceColorModes() {
diff --git a/frontend/discourse/app/lib/color-scheme-picker.js b/frontend/discourse/app/lib/color-scheme-picker.js
index aa297accd49..f70fcaccc16 100644
--- a/frontend/discourse/app/lib/color-scheme-picker.js
+++ b/frontend/discourse/app/lib/color-scheme-picker.js
@@ -11,12 +11,20 @@ export function listColorSchemes(site, options = {}) {
return null;
}
+ const currentTheme = options.currentTheme;
+ const limitToTheme =
+ currentTheme?.only_theme_color_schemes &&
+ schemes.some((s) => s.theme_id === currentTheme.id);
+
let results = [];
if (!options.darkOnly) {
schemes = schemes.sort((a, b) => Number(a.is_dark) - Number(b.is_dark));
}
schemes.forEach((s) => {
+ if (limitToTheme && s.theme_id !== currentTheme.id) {
+ return;
+ }
if ((options.darkOnly && s.is_dark) || !options.darkOnly) {
results.push({
name: s.name,
@@ -31,13 +39,15 @@ export function listColorSchemes(site, options = {}) {
const defaultLightColorScheme = site.get("default_light_color_scheme");
const defaultDarkColorScheme = site.get("default_dark_color_scheme");
- results.unshift({
- id: -1,
- name: `${i18n("user.color_schemes.default_description")}`,
- colors: options.darkOnly
- ? defaultDarkColorScheme?.colors || []
- : defaultLightColorScheme?.colors || [],
- });
+ if (!limitToTheme) {
+ results.unshift({
+ id: -1,
+ name: `${i18n("user.color_schemes.default_description")}`,
+ colors: options.darkOnly
+ ? defaultDarkColorScheme?.colors || []
+ : defaultLightColorScheme?.colors || [],
+ });
+ }
return results.length === 0 ? null : results;
}
diff --git a/frontend/discourse/app/lib/theme-selector.js b/frontend/discourse/app/lib/theme-selector.js
index 9f5d479c723..7e5d3437d9d 100644
--- a/frontend/discourse/app/lib/theme-selector.js
+++ b/frontend/discourse/app/lib/theme-selector.js
@@ -81,6 +81,7 @@ export function listThemes(site) {
id: t.theme_id,
color_scheme_id: t.color_scheme_id,
dark_color_scheme_id: t.dark_color_scheme_id,
+ only_theme_color_schemes: t.only_theme_color_schemes,
});
});
diff --git a/spec/integration/remote_theme_color_schemes_spec.rb b/spec/integration/remote_theme_color_schemes_spec.rb
index 59e3bd32cf5..7f582fe304a 100644
--- a/spec/integration/remote_theme_color_schemes_spec.rb
+++ b/spec/integration/remote_theme_color_schemes_spec.rb
@@ -150,6 +150,38 @@ RSpec.describe "Remote theme update" do
expect(ColorScheme.unscoped.exists?(id: scheme2.id)).to eq(false)
end
+ it "auto-assigns light and dark color schemes when only_theme_color_schemes modifier is set" do
+ add_to_git_repo(
+ initial_repo,
+ "about.json" =>
+ JSON
+ .parse(about_json)
+ .merge(
+ "modifiers" => {
+ "only_theme_color_schemes" => true,
+ },
+ "color_schemes" => {
+ "Light Theme" => {
+ "primary" => "333333",
+ "secondary" => "FFFFFF",
+ },
+ "Dark Theme" => {
+ "primary" => "DDDDDD",
+ "secondary" => "222222",
+ },
+ },
+ )
+ .to_json,
+ )
+
+ theme = RemoteTheme.import_theme(initial_repo_url)
+ light = theme.color_schemes.find_by(name: "Light Theme")
+ dark = theme.color_schemes.find_by(name: "Dark Theme")
+
+ expect(theme.color_scheme_id).to eq(light.id)
+ expect(theme.dark_color_scheme_id).to eq(dark.id)
+ end
+
it "does not delete custom color schemes when installing a new theme" do
custom_scheme = ColorScheme.create!(name: "My Custom Palette")
custom_scheme.color_scheme_colors.create!(name: "primary", hex: "ff0000")
diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb
index 3d2fee004b6..463c2ce7c4d 100644
--- a/spec/models/site_spec.rb
+++ b/spec/models/site_spec.rb
@@ -19,6 +19,7 @@ RSpec.describe Site do
"default" => id == SiteSetting.default_theme_id,
"color_scheme_id" => color_scheme_id,
"dark_color_scheme_id" => dark_color_scheme_id,
+ "only_theme_color_schemes" => false,
}
end
diff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.json
index a168b498fc7..606e6090d0d 100644
--- a/spec/requests/api/schemas/json/site_response.json
+++ b/spec/requests/api/schemas/json/site_response.json
@@ -537,6 +537,9 @@
"integer",
"null"
]
+ },
+ "only_theme_color_schemes": {
+ "type": "boolean"
}
},
"required": [
diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb
index bc6e825380d..73d689ae09e 100644
--- a/spec/serializers/site_serializer_spec.rb
+++ b/spec/serializers/site_serializer_spec.rb
@@ -101,6 +101,28 @@ RSpec.describe SiteSerializer do
expect(serialized[:user_color_schemes][0][:is_dark]).to eq(true)
end
+ describe "only_theme_color_schemes modifier" do
+ fab!(:theme)
+ fab!(:color_scheme) { Fabricate(:color_scheme, theme_id: theme.id, user_selectable: false) }
+
+ before do
+ theme.update!(user_selectable: true)
+ theme.theme_modifier_set.update!(only_theme_color_schemes: true)
+ end
+
+ it "includes theme color schemes in user_color_schemes when modifier is active" do
+ serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
+ scheme_ids = serialized[:user_color_schemes].map { |s| s[:id] }
+ expect(scheme_ids).to include(color_scheme.id)
+ end
+
+ it "includes only_theme_color_schemes flag in user_themes" do
+ serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
+ theme_data = serialized[:user_themes].find { |t| t["theme_id"] == theme.id }
+ expect(theme_data["only_theme_color_schemes"]).to eq(true)
+ end
+ end
+
it "includes default dark mode scheme" do
scheme = ColorScheme.last
Theme.find_default.update!(dark_color_scheme_id: scheme.id)