A platform for community discussion. Free, open, simple.
DEV: change experimental_system_themes setting to list (#33230)
Krzysztof Kotlarekcb7d26fae5ab
diff --git a/app/controllers/admin/config/customize_controller.rb b/app/controllers/admin/config/customize_controller.rbindex 1c235112894..76736bc28a9 100644--- a/app/controllers/admin/config/customize_controller.rb+++ b/app/controllers/admin/config/customize_controller.rb@@ -9,10 +9,9 @@ class Admin::Config::CustomizeController < Admin::AdminController.include_basic_relations.includes(:theme_fields, color_scheme: [:color_scheme_colors]).where(component: false)+ .where("ID > 0 OR LOWER(name) IN (?)", SiteSetting.experimental_system_themes_map).order(:name)- themes = themes.not_system if !SiteSetting.experimental_system_themes-render json: { themes: serialize_data(themes, ThemeIndexSerializer) }enddiff --git a/config/site_settings.yml b/config/site_settings.ymlindex 9d600d9acea..aaafa95f2af 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -4026,5 +4026,10 @@ experimental:client: truevalidator: "LanguageSwitcherSettingValidator"experimental_system_themes:- default: false+ type: list+ default: ""hidden: true+ allow_any: false+ choices:+ - "foundation"+ - "horizon"diff --git a/db/migrate/20250617064103_migrate_experimental_system_themes_site_setting_to_enum.rb b/db/migrate/20250617064103_migrate_experimental_system_themes_site_setting_to_enum.rbnew file mode 100644index 00000000000..8e05b0dbe31--- /dev/null+++ b/db/migrate/20250617064103_migrate_experimental_system_themes_site_setting_to_enum.rb@@ -0,0 +1,32 @@+# frozen_string_literal: true+class MigrateExperimentalSystemThemesSiteSettingToEnum < ActiveRecord::Migration[7.2]+ def up+ execute <<~SQL+ UPDATE+ "site_settings"+ SET+ "data_type" = 8,+ "value" = 'foundation|horizon'+ WHERE+ "name" = 'experimental_system_themes' AND+ "value" = 't' AND+ "data_type" = 5+ SQL++ execute <<~SQL+ UPDATE+ "site_settings"+ SET+ "data_type" = 8,+ "value" = ''+ WHERE+ "name" = 'experimental_system_themes' AND+ "value" = 'f' AND+ "data_type" = 5+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/spec/system/admin_customize_themes_config_area_spec.rb b/spec/system/admin_customize_themes_config_area_spec.rbindex b526805b870..bd771acfe2d 100644--- a/spec/system/admin_customize_themes_config_area_spec.rb+++ b/spec/system/admin_customize_themes_config_area_spec.rb@@ -2,9 +2,9 @@describe "Admin Customize Themes Config Area Page", type: :system dofab!(:admin)- fab!(:theme)+ fab!(:theme) { Fabricate(:theme, name: "First theme") }fab!(:default_theme) { Theme.where(component: false, name: "Default").first }- fab!(:foundation_theme) { Theme.where(component: false, name: "Foundation").first }+ fab!(:foundation_theme) { Theme.foundation_theme }fab!(:theme_child_theme) doFabricate(:theme, name: "Child theme", component: true, enabled: true, parent_themes: [theme])end@@ -15,7 +15,7 @@ describe "Admin Customize Themes Config Area Page", type: :system dolet(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }before do- SiteSetting.experimental_system_themes = true+ SiteSetting.experimental_system_themes = "foundation|horizon"sign_in(admin)end@@ -47,7 +47,9 @@ describe "Admin Customize Themes Config Area Page", type: :system doconfig_area.mark_as_active(theme_2)expect(config_area).to have_badge(theme_2, "--active")expect(config_area).to have_no_badge(foundation_theme, "--active")- expect(find(".theme-card", match: :first).find(".theme-card__title")).to have_text(theme_2.name)+ expect(config_area).to have_themes(+ ["Second theme", "Horizon", "Foundation", "Default", "First theme"],+ )endit "allows to make theme selectable by users" do@@ -79,4 +81,20 @@ describe "Admin Customize Themes Config Area Page", type: :system doI18n.t("admin_js.admin.config_areas.themes_and_components.themes.title"),)end++ it "allows controlling visibility of system themes with experimental_system_themes setting" do+ SiteSetting.experimental_system_themes = ""+ config_area.visit+ expect(config_area).to have_themes(["Default", "First theme", "Second theme"])++ SiteSetting.experimental_system_themes = "foundation"+ config_area.visit+ expect(config_area).to have_themes(["Default", "Foundation", "First theme", "Second theme"])++ SiteSetting.experimental_system_themes = "foundation|horizon"+ config_area.visit+ expect(config_area).to have_themes(+ ["Default", "Horizon", "Foundation", "First theme", "Second theme"],+ )+ endenddiff --git a/spec/system/page_objects/pages/admin_customize_themes_config_area.rb b/spec/system/page_objects/pages/admin_customize_themes_config_area.rbindex b91d56f86ee..e3e963a0dd8 100644--- a/spec/system/page_objects/pages/admin_customize_themes_config_area.rb+++ b/spec/system/page_objects/pages/admin_customize_themes_config_area.rb@@ -32,6 +32,10 @@ module PageObjectsfind_theme_card(theme).has_no_css?(".theme-card__badge.#{badge}")end+ def has_themes?(names)+ expect(all(".theme-card__title").map(&:text)).to eq(names)+ end+def toggle_selectable(theme)open_theme_menu(theme)find(".set-selectable").click