Skip to content

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

Revert "DEV: enable Foundation and stop Default" (#33599)

Krzysztof Kotlarek19c3beb555aa
diff --git a/app/controllers/admin/color_schemes_controller.rb b/app/controllers/admin/color_schemes_controller.rb
index cc10ad72d01..64059fa0d95 100644
--- a/app/controllers/admin/color_schemes_controller.rb
+++ b/app/controllers/admin/color_schemes_controller.rb
@@ -4,7 +4,10 @@ class Admin::ColorSchemesController < Admin::AdminController
before_action :fetch_color_scheme, only: %i[update destroy]
def index
- schemes = ColorScheme.without_theme_owned_palettes.order("color_schemes.id ASC")
+ schemes =
+ ColorScheme.without_theme_owned_palettes.with_experimental_system_theme_palettes.order(
+ "color_schemes.id ASC",
+ )
schemes = schemes.where(theme_id: nil) if params[:exclude_theme_owned]
diff --git a/app/controllers/admin/config/customize_controller.rb b/app/controllers/admin/config/customize_controller.rb
index 98ab25a8e43..d8ceffeade6 100644
--- a/app/controllers/admin/config/customize_controller.rb
+++ b/app/controllers/admin/config/customize_controller.rb
@@ -8,6 +8,7 @@ class Admin::Config::CustomizeController < Admin::AdminController
Theme
.include_basic_relations
.includes(:theme_fields, color_scheme: [:color_scheme_colors])
+ .with_experimental_system_themes
.where(component: false)
.order(:name)
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index 4f44175e50c..ea2f924773a 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -170,13 +170,14 @@ class Admin::ThemesController < Admin::AdminController
end
def index
- @themes = Theme.strict_loading.include_relations.order(:name)
+ @themes = Theme.with_experimental_system_themes.strict_loading.include_relations.order(:name)
@color_schemes =
ColorScheme
.strict_loading
.all
.without_theme_owned_palettes
+ .with_experimental_system_theme_palettes
.includes(:theme, color_scheme_colors: :color_scheme)
.to_a
diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb
index 3f4a384c61e..d01282deb3b 100644
--- a/app/models/color_scheme.rb
+++ b/app/models/color_scheme.rb
@@ -318,6 +318,14 @@ class ColorScheme < ActiveRecord::Base
scope :without_theme_owned_palettes,
-> { where("color_schemes.id NOT IN (SELECT color_scheme_id FROM theme_color_schemes)") }
+ scope :with_experimental_system_theme_palettes,
+ -> do
+ joins("LEFT JOIN themes on themes.id = color_schemes.theme_id").where(
+ "themes.id is NULL OR themes.id > 0 OR themes.id IN (?)",
+ Theme.experimental_system_theme_ids,
+ )
+ end
+
validates_associated :color_scheme_colors
BASE_COLORS_FILE = "#{Rails.root}/app/assets/stylesheets/common/foundation/colors.scss"
diff --git a/app/models/theme.rb b/app/models/theme.rb
index 4ce9670b1d5..557b4c4dc7e 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -128,6 +128,8 @@ class Theme < ActiveRecord::Base
scope :not_system, -> { where("id > 0") }
scope :system, -> { where("id < 0") }
+ scope :with_experimental_system_themes,
+ -> { where("id > 0 OR id IN (?)", Theme.experimental_system_theme_ids) }
delegate :remote_url, to: :remote_theme, private: true, allow_nil: true
@@ -346,6 +348,12 @@ class Theme < ActiveRecord::Base
end
end
+ def self.experimental_system_theme_ids
+ Theme::CORE_THEMES
+ .select { |k, v| SiteSetting.experimental_system_themes_map.include?(k) }
+ .values
+ end
+
def set_default!
if component
raise Discourse::InvalidParameters.new(I18n.t("themes.errors.component_no_default"))
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 3841b2ce558..18f51a8fb1e 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -4677,6 +4677,7 @@ en:
solarized_dark_theme_name: "Solarized Dark"
wcag_dark: "WCAG Dark"
wcag_dark_theme_name: "WCAG Dark"
+ default_theme_name: "Default"
light_theme_name: "Light"
dark_theme_name: "Dark"
neutral_theme_name: "Neutral"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index d7d667c4288..707faf24562 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4071,3 +4071,11 @@ experimental:
client: true
type: group_list
default: ""
+ experimental_system_themes:
+ type: list
+ default: "horizon"
+ hidden: true
+ allow_any: false
+ choices:
+ - "foundation"
+ - "horizon"
diff --git a/db/fixtures/600_themes.rb b/db/fixtures/600_themes.rb
index 1994be3ccdc..aad0ec1e7f6 100644
--- a/db/fixtures/600_themes.rb
+++ b/db/fixtures/600_themes.rb
@@ -1,11 +1,7 @@
# frozen_string_literal: true
-theme_exists = Theme.exists?
-
-SystemThemesManager.sync!
-
# we can not guess what to do if customization already started, so skip it
-if !theme_exists
+if !Theme.exists?
STDERR.puts "> Seeding theme and color schemes"
color_schemes = [
@@ -28,7 +24,9 @@ if !theme_exists
)
end
- Theme.foundation_theme.set_default!
+ name = I18n.t("color_schemes.default_theme_name")
+ default_theme = Theme.create!(name: name, user_id: Discourse::SYSTEM_USER_ID)
+ default_theme.set_default!
if SiteSetting.default_dark_mode_color_scheme_id ==
SiteSetting.defaults[:default_dark_mode_color_scheme_id]
@@ -37,3 +35,5 @@ if !theme_exists
SiteSetting.default_dark_mode_color_scheme_id = dark_scheme_id if dark_scheme_id.present?
end
end
+
+SystemThemesManager.sync!
diff --git a/db/migrate/20250714030525_remove_experimental_system_themes_site_setting.rb b/db/migrate/20250714030525_remove_experimental_system_themes_site_setting.rb
deleted file mode 100644
index e8ff544bf64..00000000000
--- a/db/migrate/20250714030525_remove_experimental_system_themes_site_setting.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: true
-class RemoveExperimentalSystemThemesSiteSetting < ActiveRecord::Migration[7.2]
- def up
- execute "DELETE FROM site_settings WHERE name = 'experimental_system_themes'"
- end
-
- def down
- raise ActiveRecord::IrreversibleMigration
- end
-end
diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb
index a45dee0c66c..a0e6c81fc93 100644
--- a/spec/models/theme_spec.rb
+++ b/spec/models/theme_spec.rb
@@ -234,7 +234,7 @@ HTML
f =
ThemeField.create!(
target_id: Theme.targets[:mobile],
- theme_id: -1,
+ theme_id: 1,
name: "after_header",
value: html,
)
diff --git a/spec/requests/admin/color_schemes_controller_spec.rb b/spec/requests/admin/color_schemes_controller_spec.rb
index 3bcef138cd1..5a474d4d977 100644
--- a/spec/requests/admin/color_schemes_controller_spec.rb
+++ b/spec/requests/admin/color_schemes_controller_spec.rb
@@ -32,6 +32,20 @@ RSpec.describe Admin::ColorSchemesController do
expect(scheme_colors[0]["hex"]).to eq(base_scheme_colors[0].hex)
end
+ it "filters colors belonging to experimental system themes" do
+ SiteSetting.experimental_system_themes = ""
+ get "/admin/color_schemes.json"
+ expect(response.status).to eq(200)
+ scheme_names = response.parsed_body.map { |scheme| scheme["name"] }
+ expect(scheme_names).not_to include("Horizon")
+
+ SiteSetting.experimental_system_themes = "horizon"
+ get "/admin/color_schemes.json"
+ expect(response.status).to eq(200)
+ scheme_names = response.parsed_body.map { |scheme| scheme["name"] }
+ expect(scheme_names).to include("Horizon")
+ end
+
it "serializes default colors even when not present in database" do
scheme = ColorScheme.create_from_base({ name: "my color scheme" })
scheme.colors.find_by(name: "primary").destroy!
diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb
index 5836b44a805..ef0ed36b55c 100644
--- a/spec/requests/admin/themes_controller_spec.rb
+++ b/spec/requests/admin/themes_controller_spec.rb
@@ -510,6 +510,26 @@ RSpec.describe Admin::ThemesController do
expect(theme_json["remote_theme"]["remote_version"]).to eq("7")
end
+ it "filters experimental system themes" do
+ SiteSetting.experimental_system_themes = ""
+ get "/admin/themes.json"
+ expect(response.status).to eq(200)
+ theme_names = response.parsed_body["themes"].map { |theme| theme[:name] }
+ color_scheme_names =
+ response.parsed_body["extras"]["color_schemes"].map { |scheme| scheme[:name] }
+ expect(theme_names).not_to include("Horizon")
+ expect(color_scheme_names).not_to include("Horizon")
+
+ SiteSetting.experimental_system_themes = "horizon"
+ get "/admin/themes.json"
+ expect(response.status).to eq(200)
+ theme_names = response.parsed_body["themes"].map { |t| t[:name] }
+ color_scheme_names =
+ response.parsed_body["extras"]["color_schemes"].map { |scheme| scheme[:name] }
+ expect(theme_names).to include("Horizon")
+ expect(color_scheme_names).to include("Horizon")
+ end
+
it "does not result in N+1 queries" do
# warmup
get "/admin/themes.json"
diff --git a/spec/system/admin_customize_themes_config_area_spec.rb b/spec/system/admin_customize_themes_config_area_spec.rb
index 152163cfe9e..bd771acfe2d 100644
--- a/spec/system/admin_customize_themes_config_area_spec.rb
+++ b/spec/system/admin_customize_themes_config_area_spec.rb
@@ -3,8 +3,8 @@
describe "Admin Customize Themes Config Area Page", type: :system do
fab!(:admin)
fab!(:theme) { Fabricate(:theme, name: "First theme") }
+ fab!(:default_theme) { Theme.where(component: false, name: "Default").first }
fab!(:foundation_theme) { Theme.foundation_theme }
- fab!(:horizon_theme) { Theme.horizon_theme }
fab!(:theme_child_theme) do
Fabricate(:theme, name: "Child theme", component: true, enabled: true, parent_themes: [theme])
end
@@ -14,7 +14,10 @@ describe "Admin Customize Themes Config Area Page", type: :system do
let(:install_modal) { PageObjects::Modals::InstallTheme.new }
let(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }
- before { sign_in(admin) }
+ before do
+ SiteSetting.experimental_system_themes = "foundation|horizon"
+ sign_in(admin)
+ end
it "has an install button in the subheader" do
config_area.visit
@@ -39,11 +42,14 @@ describe "Admin Customize Themes Config Area Page", type: :system do
it "allows to mark theme as active" do
config_area.visit
- expect(config_area).to have_badge(foundation_theme, "--active")
+ expect(config_area).to have_badge(default_theme, "--active")
expect(config_area).to have_no_badge(theme_2, "--active")
config_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(config_area).to have_themes(
+ ["Second theme", "Horizon", "Foundation", "Default", "First theme"],
+ )
end
it "allows to make theme selectable by users" do
@@ -75,4 +81,20 @@ describe "Admin Customize Themes Config Area Page", type: :system do
I18n.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"],
+ )
+ end
end