A platform for community discussion. Free, open, simple.
FIX: Hide Solved empty_box_on_unsolved on Horizon (#41276)
Martin Brennand77cb821d635
diff --git a/app/models/theme.rb b/app/models/theme.rbindex ff53ec09a05..eaf652ec394 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -641,7 +641,7 @@ class Theme < ActiveRecord::Base# def foundation_theme# def horizon_theme- CORE_THEMES.each { |name, id| define_singleton_method("#{name}_theme") { Theme.find(id) } }+ CORE_THEMES.each { |name, id| define_singleton_method("#{name}_theme") { Theme.find_by(id: id) } }def resolve_baked_field(target, name)list_baked_fields(target, name).map { |f| f.value_baked || f.value }.join("\n")enddiff --git a/app/services/themes/action/horizon_high_context_topic_cards_toggled.rb b/app/services/themes/action/horizon_high_context_topic_cards_toggled.rbindex e50b7967734..57b3cd7bd2a 100644--- a/app/services/themes/action/horizon_high_context_topic_cards_toggled.rb+++ b/app/services/themes/action/horizon_high_context_topic_cards_toggled.rb@@ -4,7 +4,7 @@ class Themes::Action::HorizonHighContextTopicCardsToggled < Service::ActionBaseoption :enableddef call- theme = Theme.find_by(id: Theme::CORE_THEMES["horizon"])+ theme = Theme.horizon_themereturn if theme.blank?return if theme.settings.blank?@@ -21,11 +21,11 @@ class Themes::Action::HorizonHighContextTopicCardsToggled < Service::ActionBase# site that got the legacy migration. If no setting exists,# it's a new site which has the theme setting for high-context topic cards# enabled by default.- ThemeSetting.exists?(theme_id: Theme::CORE_THEMES["horizon"], name: :topic_card_high_context)+ ThemeSetting.exists?(theme_id: Theme.horizon_theme.id, name: :topic_card_high_context)enddef self.horizon_theme_available?- horizon_theme = Theme.find_by(id: Theme::CORE_THEMES["horizon"])+ horizon_theme = Theme.horizon_themereturn false if horizon_theme.blank? || !horizon_theme.enabled?return false if !horizon_theme.user_selectable? && !horizon_theme.default?horizon_theme.default? || horizon_theme.user_selectable?diff --git a/plugins/discourse-solved/app/services/discourse_solved/categories/types/support.rb b/plugins/discourse-solved/app/services/discourse_solved/categories/types/support.rbindex 9a2d611545c..3b6bd8d308b 100644--- a/plugins/discourse-solved/app/services/discourse_solved/categories/types/support.rb+++ b/plugins/discourse-solved/app/services/discourse_solved/categories/types/support.rb@@ -106,16 +106,24 @@ module DiscourseSolvedlabel:I18n.t("discourse_solved.category_type.notify_on_staff_accept_solved.label"),},- DiscourseSolved::EMPTY_BOX_ON_UNSOLVED_CUSTOM_FIELD => {- default: true,- type: :bool,- label: I18n.t("discourse_solved.category_type.empty_box_on_unsolved.label"),- },},site_texts: {},}+ # The empty-box-on-unsolved styling isn't used by the Horizon theme,+ # so hide the toggle (and the field) when Horizon is the site's+ # default theme.+ unless default_theme_horizon?+ schema[:category_custom_fields][+ DiscourseSolved::EMPTY_BOX_ON_UNSOLVED_CUSTOM_FIELD+ ] = {+ default: true,+ type: :bool,+ label: I18n.t("discourse_solved.category_type.empty_box_on_unsolved.label"),+ }+ end+if SiteSetting.enable_solved_shared_issuesschema[:category_custom_fields][DiscourseSolved::SHARED_ISSUES_ENABLED_CUSTOM_FIELD@@ -141,6 +149,12 @@ module DiscourseSolveddef icon"person_raising_hand"end++ private++ def default_theme_horizon?+ SiteSetting.default_theme_id == Theme.horizon_theme.id+ endendendenddiff --git a/plugins/discourse-solved/spec/models/discourse_solved/categories_types_support_spec.rb b/plugins/discourse-solved/spec/models/discourse_solved/categories_types_support_spec.rbindex bc7f63fe930..cbd67be3acf 100644--- a/plugins/discourse-solved/spec/models/discourse_solved/categories_types_support_spec.rb+++ b/plugins/discourse-solved/spec/models/discourse_solved/categories_types_support_spec.rb@@ -157,6 +157,28 @@ RSpec.describe DiscourseSolved::Categories::Types::Support do)endend++ context "when the Horizon theme is the site's default theme" do+ before { SiteSetting.default_theme_id = Theme.horizon_theme.id }++ it "omits the empty box on unsolved toggle from the category custom fields" do+ keys = described_class.configuration_schema[:category_custom_fields].keys+ expect(keys).not_to include(DiscourseSolved::EMPTY_BOX_ON_UNSOLVED_CUSTOM_FIELD)+ end++ it "still passes schema validation" do+ expect { described_class.validate_schema! }.not_to raise_error+ end+ end++ context "when the Horizon theme is not the site's default theme" do+ before { SiteSetting.default_theme_id = Theme.foundation_theme.id }++ it "declares the empty box on unsolved toggle as a category custom field" do+ keys = described_class.configuration_schema[:category_custom_fields].keys+ expect(keys).to include(DiscourseSolved::EMPTY_BOX_ON_UNSOLVED_CUSTOM_FIELD)+ end+ endenddescribe ".unconfigure_category" dodiff --git a/plugins/discourse-solved/spec/system/support_category_type_setup_spec.rb b/plugins/discourse-solved/spec/system/support_category_type_setup_spec.rbindex 335c5c796ec..480e58f862d 100644--- a/plugins/discourse-solved/spec/system/support_category_type_setup_spec.rb+++ b/plugins/discourse-solved/spec/system/support_category_type_setup_spec.rb@@ -165,6 +165,16 @@ RSpec.describe "Support Category Type Setup" doexpect(SiteSetting.show_who_marked_solved).to eq(true)end+ it "hides the empty box on unsolved toggle when the Horizon theme is the default" do+ Theme.horizon_theme.update_columns(enabled: true, user_selectable: true)+ SiteSetting.default_theme_id = Theme.horizon_theme.id++ visit("/c/#{category.slug}/edit/support")++ expect(form).to have_field_with_name("custom_fields.notify_on_staff_accept_solved")+ expect(form).to have_no_field_with_name("custom_fields.empty_box_on_unsolved")+ end+it "edits the shared issue label as a translation override when enabled" doSiteSetting.enable_solved_shared_issues = truevisit("/c/#{category.slug}/edit/support")