A platform for community discussion. Free, open, simple.
FEATURE: Gate Support category type creation behind upcoming change (#38571)
Martin Brennan1012851c14ef
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rbindex e73bcbc7d6a..66a5702dc0b 100644--- a/app/controllers/categories_controller.rb+++ b/app/controllers/categories_controller.rb@@ -137,7 +137,10 @@ class CategoriesController < ApplicationControllerCategories::TypeRegistry.countsend- render json: { types: Categories::TypeRegistry.list, counts: counts_by_type }+ render json: {+ types: Categories::TypeRegistry.list(only_visible: true),+ counts: counts_by_type,+ }enddef showdiff --git a/app/services/categories/type_registry.rb b/app/services/categories/type_registry.rbindex d6dbb133a8e..736921d1ab4 100644--- a/app/services/categories/type_registry.rb+++ b/app/services/categories/type_registry.rb@@ -31,8 +31,8 @@ module Categoriestypesend- def list- types.values.map(&:metadata)+ def list(only_visible: false)+ types.values.select { |type| only_visible ? type.visible? : true }.map(&:metadata)enddef valid?(id)diff --git a/app/services/categories/types/base.rb b/app/services/categories/types/base.rbindex 90f062d1705..4c7f173ce86 100644--- a/app/services/categories/types/base.rb+++ b/app/services/categories/types/base.rb@@ -195,6 +195,15 @@ module Categoriestrueend+ # One level above available? to allow for more granular control over visibility.+ # For example, a category type may not be visible at all if a plugin isn't installed+ # or if a certain site setting is not enabled, whereas available? is more+ # for gating access on other conditions, and will still show the category type+ # in the UI.+ def visible?+ true+ end+# Also used as an extension point to add additional keys/values to# the metadata hash returned by +metadata+, mostly for Discourse hosting.def additional_metadatadiff --git a/frontend/discourse/admin/routes/new-category/setup.js b/frontend/discourse/admin/routes/new-category/setup.jsindex 8664016d22c..66d0b9c9c45 100644--- a/frontend/discourse/admin/routes/new-category/setup.js+++ b/frontend/discourse/admin/routes/new-category/setup.js@@ -17,6 +17,20 @@ export default class NewCategorySetup extends DiscourseRoute {return await ajax("/categories/types");}+ afterModel(model) {+ if (model.types.length === 1) {+ const type = model.types[0];+ this.categoryTypeChooser.choose(+ type.id,+ type.name,+ type.configuration_schema,+ type.title,+ model.counts[type.id]+ );+ this.router.transitionTo("newCategory.tabs", "general");+ }+ }+titleToken() {return i18n("category.create");}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 876e65947ba..8f692c08d82 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@@ -7,6 +7,10 @@ module DiscourseSolvedtype_id :supportclass << self+ def visible?+ SiteSetting.enable_support_category_type_setup+ end+def enable_pluginSiteSetting.solved_enabled = trueenddiff --git a/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjs b/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjsindex e2fbdad3943..666bb27776d 100644--- a/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjs+++ b/plugins/discourse-solved/assets/javascripts/discourse/connectors/category-custom-settings/solved-settings-upsert.gjs@@ -11,7 +11,8 @@ export default class SolvedSettingsUpsert extends Component {// in Categories::Types::Support.return (context.siteSettings.enable_simplified_category_creation &&- !args.category?.isType("support")+ (!args.category?.isType("support") ||+ !context.siteSettings.enable_support_category_type_setup));}diff --git a/plugins/discourse-solved/assets/javascripts/discourse/initializers/solved-category-type-tab.js b/plugins/discourse-solved/assets/javascripts/discourse/initializers/solved-category-type-tab.jsindex a300f192ad8..05283a5ed73 100644--- a/plugins/discourse-solved/assets/javascripts/discourse/initializers/solved-category-type-tab.js+++ b/plugins/discourse-solved/assets/javascripts/discourse/initializers/solved-category-type-tab.js@@ -5,14 +5,17 @@ import UpsertCategorySupport from "../components/upsert-category-support";export default {name: "solved-category-type-tab",- initialize() {+ initialize(container) {+ const siteSettings = container.lookup("service:site-settings");withPluginApi((api) => {api.registerEditCategoryTab({id: "support",name: i18n("solved.category_type_support.title"),primary: true,component: UpsertCategorySupport,- condition: ({ category }) => category.isType("support"),+ condition: ({ category }) =>+ category.isType("support") &&+ siteSettings.enable_support_category_type_setup,});});},diff --git a/plugins/discourse-solved/config/locales/server.en.yml b/plugins/discourse-solved/config/locales/server.en.ymlindex 9ebe0fcef2b..3ed6e89b56d 100644--- a/plugins/discourse-solved/config/locales/server.en.yml+++ b/plugins/discourse-solved/config/locales/server.en.yml@@ -38,6 +38,7 @@ en:solved_add_schema_markup: "Add QAPage schema markup to HTML."enable_solved_tags: "Tags that will allow users to select solutions."prioritize_solved_topics_in_search: "Prioritize solved topics in search results."+ enable_support_category_type_setup: "Enables the Support category type option during category creation setup. Note that 'enable simplified category creation' must be enabled for this to take effect."show_who_marked_solved: "Show who marked the topic as solved. This is indicated in the topic's first post, and the answer post in a tooltip."keywords:diff --git a/plugins/discourse-solved/config/settings.yml b/plugins/discourse-solved/config/settings.ymlindex cdd44f7546d..39e15d9045d 100644--- a/plugins/discourse-solved/config/settings.yml+++ b/plugins/discourse-solved/config/settings.yml@@ -58,4 +58,12 @@ discourse_solved:type: tag_listdefault: ""client: true+ enable_support_category_type_setup:+ default: false+ hidden: true+ client: true+ upcoming_change:+ status: "experimental"+ impact: "feature,staff"+ learn_more_url: "https://meta.discourse.org/t/-/398338"diff --git a/plugins/discourse-solved/public/images/upcoming_changes/enable_support_category_type_setup.png b/plugins/discourse-solved/public/images/upcoming_changes/enable_support_category_type_setup.pngnew file mode 100644index 00000000000..6fc12d3b90eBinary files /dev/null and b/plugins/discourse-solved/public/images/upcoming_changes/enable_support_category_type_setup.png differdiff --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 a08c9d6ce17..ea0761d58f9 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@@ -7,9 +7,11 @@ RSpec.describe "Support Category Type Setup", type: :system dolet(:form) { PageObjects::Components::FormKit.new(".form-kit") }let(:category_type_card) { PageObjects::Components::CategoryTypeCard.new }let(:banner) { PageObjects::Components::AdminChangesBanner.new }+ let(:toast) { PageObjects::Components::Toasts.new }before doSiteSetting.enable_simplified_category_creation = true+ SiteSetting.enable_support_category_type_setup = truesign_in(admin)end@@ -33,6 +35,7 @@ RSpec.describe "Support Category Type Setup", type: :system dobanner.click_saveexpect(page).to have_content(I18n.t("js.category.edit_dialog_title", categoryName: "Support"))+ expect(page).to have_css(".d-nav-submenu__tabs .edit-category-support")expect(SiteSetting.solved_enabled).to eq(true)expect(SiteSetting.show_filter_by_solved_status).to eq(true)category = Category.find_by(name: "Support")@@ -42,6 +45,26 @@ RSpec.describe "Support Category Type Setup", type: :system doexpect(category.custom_fields["empty_box_on_unsolved"]).to eq("true")end+ context "when the support category type setup is disabled" do+ before { SiteSetting.enable_support_category_type_setup = false }++ it "does not show the support category type" do+ visit("/new-category/setup")+ expect(page).not_to have_content(I18n.t("js.category.create_with_type", typeName: "support"))+ expect(page).to have_content(I18n.t("js.category.create_with_type", typeName: "discussion"))+ end++ it "does not show the tab for the support category type when editing an existing category" do+ support_category = Fabricate(:category, name: "Support")+ DiscourseSolved::Categories::Types::Support.configure_category(+ support_category,+ guardian: admin.guardian,+ )+ visit("/c/#{support_category.slug}/edit/support")+ expect(page).to have_no_css(".d-nav-submenu__tabs .edit-category-support")+ end+ end+context "when there is a support category already configured" dofab!(:category)@@ -64,6 +87,40 @@ RSpec.describe "Support Category Type Setup", type: :system do],).to eq(nil)end++ it "can edit the settings of the support category in a tab" do+ visit("/c/#{category.slug}/edit/support")+ page.find(".d-nav-submenu__tabs .edit-category-support").click++ expect(form.field("custom_fields.enable_accepted_answers").value).to be_truthy+ expect(+ form+ .field("custom_fields.solved_topics_auto_close_hours")+ .component+ .find("input.relative-time-duration")+ .value,+ ).to eq("2")+ expect(form.field("custom_fields.notify_on_staff_accept_solved").value).to be_truthy+ expect(form.field("custom_fields.empty_box_on_unsolved").value).to be_truthy++ form.field("custom_fields.notify_on_staff_accept_solved").toggle+ form.field("custom_fields.empty_box_on_unsolved").toggle+ form+ .field("custom_fields.solved_topics_auto_close_hours")+ .component+ .find("input.relative-time-duration")+ .fill_in(with: "3")+ form.field("category_type_site_settings.show_who_marked_solved").toggle++ banner.click_save+ expect(toast).to have_success(I18n.t("js.saved"))+ category.reload++ expect(category.custom_fields["notify_on_staff_accept_solved"]).to eq("false")+ expect(category.custom_fields["empty_box_on_unsolved"]).to eq("false")+ expect(category.custom_fields["solved_topics_auto_close_hours"]).to eq("72")+ expect(SiteSetting.show_who_marked_solved).to eq(true)+ endendcontext "when visiting the Support tab for a non-support category" dodiff --git a/spec/services/categories/type_registry_spec.rb b/spec/services/categories/type_registry_spec.rbindex 04bb04c0f2f..c530dd854de 100644--- a/spec/services/categories/type_registry_spec.rb+++ b/spec/services/categories/type_registry_spec.rb@@ -42,6 +42,11 @@ RSpec.describe Categories::TypeRegistry doexpect(discussion).to include(icon: "memo", available: true)end++ it "returns only visible types when only_visible is true" do+ Categories::Types::Discussion.stubs(:visible?).returns(false)+ expect(described_class.list(only_visible: true)).to be_empty+ endenddescribe ".counts" dodiff --git a/spec/system/simplified_category_creation_spec.rb b/spec/system/simplified_category_creation_spec.rbindex cc0a52aeb5a..c6413e5daa5 100644--- a/spec/system/simplified_category_creation_spec.rb+++ b/spec/system/simplified_category_creation_spec.rb@@ -15,10 +15,47 @@ describe "Simplified Category Creation" dosign_in(admin)end+ describe "Selecting category type when setting up a new category" do+ it "automatically skips category type selection when only one type (discussion) is available" do+ visit("/new-category/setup")+ expect(page).to have_content(I18n.t("js.category.create_with_type", typeName: "discussion"))+ expect(page).to have_current_path("/new-category/general")+ end++ context "when multiple types are available" do+ class MockCategoryType < ::Categories::Types::Base+ type_id :mock_type++ class << self+ def category_matches?(category)+ true+ end++ def find_matches+ Category.none+ end+ end+ end++ before { Categories::TypeRegistry.register(MockCategoryType) }+ after { Categories::TypeRegistry.reset! }++ it "shows the category type selection cards" do+ visit("/new-category/setup")++ expect(category_type_card).to have_type_card("mock_type")+ expect(category_type_card).to have_type_card("discussion")++ category_type_card.find_type_card("discussion").click+ expect(page).to have_content(I18n.t("js.category.create_with_type", typeName: "discussion"))+ expect(page).to have_current_path("/new-category/general")+ end+ end+ end+describe "General Tab" doit "creates a basic category with name and color" docategory_page.visit_new_category- category_type_card.find_type_card("discussion").clickform.field("name").fill_in("Test Category")form.field("color").fill_in("FF5733")@@ -84,7 +121,6 @@ describe "Simplified Category Creation" doit "shows error when icon is missing" docategory_page.visit_new_category- category_type_card.find_type_card("discussion").clickform.field("name").fill_in("Test Category")@@ -111,7 +147,6 @@ describe "Simplified Category Creation" dogroup2 = Fabricate(:group)category_page.visit_new_category- category_type_card.find_type_card("discussion").clickform.field("name").fill_in("Permission Test")form.choose_conditional("group_restricted")@@ -142,7 +177,6 @@ describe "Simplified Category Creation" doFabricate(:category, name: "Restricted Parent", permissions: { group.name => :full })category_page.visit_new_category- category_type_card.find_type_card("discussion").clickparent_chooser = PageObjects::Components::SelectKit.new(".category-chooser")parent_chooser.expand@@ -156,7 +190,6 @@ describe "Simplified Category Creation" doFabricate(:category, name: "Restricted Parent", permissions: { group.name => :full })category_page.visit_new_category- category_type_card.find_type_card("discussion").clickparent_chooser = PageObjects::Components::SelectKit.new(".category-chooser")parent_chooser.expand@@ -188,7 +221,6 @@ describe "Simplified Category Creation" doexpect(page).to have_css(".group-chooser")category_page.visit_new_category- category_type_card.find_type_card("discussion").clickexpect(page).to have_no_css(".group-chooser")end