A platform for community discussion. Free, open, simple.
DEV: Make enable_simplified_category_creation Permanent (#39739)
Martin Brennanaa2e0deaa6d5
diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 8534121dbbe..0425279aaf7 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -4420,7 +4420,7 @@ experimental:hidden: trueclient: trueupcoming_change:- status: "stable"+ status: "permanent"impact: "feature,staff"learn_more_url: "https://meta.discourse.org/t/-/394971"enable_new_defaults_for_trust_level_3_requirements:diff --git a/plugins/discourse-calendar/spec/system/category_event_sorting_settings_spec.rb b/plugins/discourse-calendar/spec/system/category_event_sorting_settings_spec.rbindex 40fa041f9c3..7e8cdaa3668 100644--- a/plugins/discourse-calendar/spec/system/category_event_sorting_settings_spec.rb+++ b/plugins/discourse-calendar/spec/system/category_event_sorting_settings_spec.rb@@ -16,37 +16,16 @@ RSpec.describe "Event Sorting Category Settings" dosign_in(admin)end- context "when simplified category creation is enabled" do- before { SiteSetting.enable_simplified_category_creation = true }+ it "can toggle event sorting custom fields via FormKit" do+ category_page.visit_settings(category)- it "can toggle event sorting custom fields via FormKit" do- category_page.visit_settings(category)+ form.field("custom_fields.sort_topics_by_event_start_date").toggle+ form.field("custom_fields.disable_topic_resorting").toggle+ banner.click_save- form.field("custom_fields.sort_topics_by_event_start_date").toggle- form.field("custom_fields.disable_topic_resorting").toggle- banner.click_save-- expect(toasts).to have_success(I18n.t("js.saved"))- category.reload- expect(category.custom_fields["sort_topics_by_event_start_date"]).to eq(true)- expect(category.custom_fields["disable_topic_resorting"]).to eq(true)- end- end-- context "when simplified category creation is disabled" do- before { SiteSetting.enable_simplified_category_creation = false }-- it "can toggle event sorting custom fields via legacy form" do- category_page.visit_settings(category)-- find("#sort-topics-by-event-start-date").click- find("#disable-topic-resorting").click- category_page.save_settings-- expect(toasts).to have_success(I18n.t("js.saved"))- category.reload- expect(category.custom_fields["sort_topics_by_event_start_date"]).to eq(true)- expect(category.custom_fields["disable_topic_resorting"]).to eq(true)- end+ expect(toasts).to have_success(I18n.t("js.saved"))+ category.reload+ expect(category.custom_fields["sort_topics_by_event_start_date"]).to eq(true)+ expect(category.custom_fields["disable_topic_resorting"]).to eq(true)endenddiff --git a/plugins/discourse-post-voting/spec/system/category_settings_spec.rb b/plugins/discourse-post-voting/spec/system/category_settings_spec.rbindex 744523fa54b..09ed8e09bb3 100644--- a/plugins/discourse-post-voting/spec/system/category_settings_spec.rb+++ b/plugins/discourse-post-voting/spec/system/category_settings_spec.rb@@ -11,37 +11,16 @@ RSpec.describe "Post Voting Category Settings" dobefore { sign_in(admin) }- context "when simplified category creation is enabled" do- before { SiteSetting.enable_simplified_category_creation = true }+ it "can toggle post voting custom fields via FormKit" do+ category_page.visit_settings(category)- it "can toggle post voting custom fields via FormKit" do- category_page.visit_settings(category)+ form.field("custom_fields.create_as_post_voting_default").toggle+ form.field("custom_fields.only_post_voting_in_this_category").toggle+ banner.click_save- form.field("custom_fields.create_as_post_voting_default").toggle- form.field("custom_fields.only_post_voting_in_this_category").toggle- banner.click_save-- expect(toasts).to have_success(I18n.t("js.saved"))- category.reload- expect(category.custom_fields["create_as_post_voting_default"]).to eq(true)- expect(category.custom_fields["only_post_voting_in_this_category"]).to eq(true)- end- end-- context "when simplified category creation is disabled" do- before { SiteSetting.enable_simplified_category_creation = false }-- it "can toggle post voting custom fields via legacy form" do- category_page.visit_settings(category)-- find("#create-as-post-voting-default").click- find("#only-post-voting-in-this-category").click- category_page.save_settings-- expect(toasts).to have_success(I18n.t("js.saved"))- category.reload- expect(category.custom_fields["create_as_post_voting_default"]).to eq(true)- expect(category.custom_fields["only_post_voting_in_this_category"]).to eq(true)- end+ expect(toasts).to have_success(I18n.t("js.saved"))+ category.reload+ expect(category.custom_fields["create_as_post_voting_default"]).to eq(true)+ expect(category.custom_fields["only_post_voting_in_this_category"]).to eq(true)endenddiff --git a/spec/jobs/check_new_features_spec.rb b/spec/jobs/check_new_features_spec.rbindex c4d410e6fd9..7980392a002 100644--- a/spec/jobs/check_new_features_spec.rb+++ b/spec/jobs/check_new_features_spec.rb@@ -25,6 +25,26 @@ RSpec.describe Jobs::CheckNewFeatures do)end+ let(:permanent_upcoming_changes) do+ [+ {+ setting: :enable_upload_debug_mode,+ humanized_name: SiteSetting.humanized_names(:enable_upload_debug_mode),+ description: SiteSetting.description(:enable_upload_debug_mode),+ upcoming_change: {+ learn_more_url: "https://meta.discourse.org/t/-/1234",+ image: {+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",+ },+ },+ },+ ]+ end++ def stub_permanent_upcoming_changes!(changes)+ UpcomingChanges.stubs(:permanent_upcoming_changes).returns(changes)+ end+fab!(:admin1, :admin)fab!(:admin2, :admin)@@ -44,6 +64,7 @@ RSpec.describe Jobs::CheckNewFeatures doDiscourseUpdates.stubs(:current_version).returns("2.8.1.beta13")freeze_timestub_new_features_endpoint(feature1, feature2, pending_feature)+ UpcomingChanges.stubs(:permanent_upcoming_changes).returns([])endafter { DiscourseUpdates.clean_state }@@ -84,6 +105,7 @@ RSpec.describe Jobs::CheckNewFeatures docontext "when a permanent upcoming change is merged into an empty new-features feed" dobefore do+ stub_permanent_upcoming_changes!(permanent_upcoming_changes)UpcomingChanges.stubs(:image_exists?).returns(true)UpcomingChanges.stubs(:image_data).returns({@@ -100,17 +122,6 @@ RSpec.describe Jobs::CheckNewFeatures doNotification.destroy_allstatus_changed_at = 1.day.ago- mock_upcoming_change_metadata(- {- enable_upload_debug_mode: {- impact: "other,developers",- status: :permanent,- impact_type: "other",- impact_role: "developers",- learn_more_url: "https://meta.discourse.org/t/-/1234",- },- },- )event =UpcomingChangeEvent.create!(event_type: :status_changed,@@ -121,6 +132,7 @@ RSpec.describe Jobs::CheckNewFeatures do},created_at: status_changed_at,)+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)described_class.new.execute({})@@ -157,6 +169,7 @@ RSpec.describe Jobs::CheckNewFeatures doendbefore do+ stub_permanent_upcoming_changes!(permanent_upcoming_changes)UpcomingChanges.stubs(:image_exists?).returns(true)UpcomingChanges.stubs(:image_data).returns({@@ -173,17 +186,6 @@ RSpec.describe Jobs::CheckNewFeatures doNotification.destroy_alluc_became_permanent_at = 2.days.ago- mock_upcoming_change_metadata(- {- enable_upload_debug_mode: {- impact: "other,developers",- status: :permanent,- impact_type: "other",- impact_role: "developers",- learn_more_url: "https://meta.discourse.org/t/-/1234",- },- },- )UpcomingChangeEvent.create!(event_type: :status_changed,upcoming_change_name: "enable_upload_debug_mode",@@ -193,6 +195,7 @@ RSpec.describe Jobs::CheckNewFeatures do},created_at: uc_became_permanent_at,)+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)DiscourseUpdates.update_new_features([feature_stale].to_json)@@ -222,17 +225,6 @@ RSpec.describe Jobs::CheckNewFeatures doNotification.destroy_alluc_became_permanent_at = 2.days.ago- mock_upcoming_change_metadata(- {- enable_upload_debug_mode: {- impact: "other,developers",- status: :permanent,- impact_type: "other",- impact_role: "developers",- learn_more_url: "https://meta.discourse.org/t/-/1234",- },- },- )UpcomingChangeEvent.create!(event_type: :status_changed,upcoming_change_name: "enable_upload_debug_mode",@@ -242,6 +234,7 @@ RSpec.describe Jobs::CheckNewFeatures do},created_at: uc_became_permanent_at,)+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)DiscourseUpdates.update_new_features([feature_stale].to_json)stub_new_features_endpoint(feature_newer_than_uc, feature_stale)diff --git a/spec/lib/discourse_updates_spec.rb b/spec/lib/discourse_updates_spec.rbindex 37493f34c80..5baf17c2234 100644--- a/spec/lib/discourse_updates_spec.rb+++ b/spec/lib/discourse_updates_spec.rb@@ -1,6 +1,21 @@# frozen_string_literal: trueRSpec.describe DiscourseUpdates do+ # DiscourseUpdates merges against UpcomingChanges.permanent_upcoming_changes; stub it+ # so these examples do not depend on which settings are marked permanent in+ # site_settings.yml.+ def stub_permanent_upcoming_changes!(changes)+ UpcomingChanges.stubs(:permanent_upcoming_changes).returns(changes)+ end++ def stub_merge_uc_example_status!(uc_status)+ if uc_status == :permanent+ stub_permanent_upcoming_changes!(permanent_upcoming_changes)+ else+ stub_permanent_upcoming_changes!([])+ end+ end+def stub_data(latest, missing, critical, updated_at)DiscourseUpdates.latest_version = latestDiscourseUpdates.missing_versions_count = missing@@ -10,6 +25,22 @@ RSpec.describe DiscourseUpdates dosubject(:version) { DiscourseUpdates.check_version }+ let(:permanent_upcoming_changes) do+ [+ {+ setting: :enable_upload_debug_mode,+ humanized_name: "Enable upload debug mode",+ description: "Debug uploads.",+ upcoming_change: {+ learn_more_url: "https://meta.discourse.org/t/-/1234",+ image: {+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",+ },+ },+ },+ ]+ end+context "when version check was done at the current installed version" dobefore { DiscourseUpdates.last_installed_version = Discourse::VERSION::STRING }@@ -156,6 +187,8 @@ RSpec.describe DiscourseUpdates doendbefore(:each) do+ stub_permanent_upcoming_changes!([])+Discourse.redis.del "new_features_last_seen_user_#{admin.id}"Discourse.redis.del "new_features_last_seen_user_#{admin2.id}"Discourse.redis.set("new_features", MultiJson.dump(sample_features))@@ -340,17 +373,7 @@ RSpec.describe DiscourseUpdates doDiscourse.redis.del("new_features_last_seen_user_#{admin.id}")Discourse.redis.set("new_features", MultiJson.dump([]))- mock_upcoming_change_metadata(- {- enable_upload_debug_mode: {- impact: "other,developers",- status: :permanent,- impact_type: "other",- impact_role: "developers",- learn_more_url: "https://meta.discourse.org/t/-/1234",- },- },- )+ stub_permanent_upcoming_changes!(permanent_upcoming_changes)UpcomingChanges.stubs(:image_exists?).returns(true)UpcomingChanges.stubs(:image_data).returns(@@ -381,7 +404,11 @@ RSpec.describe DiscourseUpdates do]end- before { Discourse.redis.set("new_features", MultiJson.dump(sample_features)) }+ before do+ stub_permanent_upcoming_changes!([])+ Discourse.redis.set("new_features", MultiJson.dump(sample_features))+ end+after { DiscourseUpdates.clean_state }it "returns the max created_at from merged features" do@@ -429,7 +456,11 @@ RSpec.describe DiscourseUpdates do[{ "emoji" => "🤾", "title" => "A Feature", "created_at" => feature_date }]end- before { Discourse.redis.set("new_features", MultiJson.dump(sample_features)) }+ before do+ stub_permanent_upcoming_changes!([])+ Discourse.redis.set("new_features", MultiJson.dump(sample_features))+ end+after { DiscourseUpdates.clean_state }it "uses the cached timestamp instead of recomputing on repeated calls" do@@ -448,27 +479,6 @@ RSpec.describe DiscourseUpdates doenddescribe ".merge_new_features_with_upcoming_changes" do- def mock_merge_uc_metadata(uc_status)- mock_upcoming_change_metadata(- {- floating_dismiss_topics_on_mobile: {- impact: "feature,all_members",- status: :beta,- impact_type: "feature",- impact_role: "all_members",- learn_more_url: "https://meta.discourse.org/t/-/387322",- },- enable_upload_debug_mode: {- impact: "other,developers",- status: uc_status,- impact_type: "other",- impact_role: "developers",- learn_more_url: "https://meta.discourse.org/t/-/1234",- },- },- )- end-def feature_for_uc_setting(features)features.find { |f| f[:upcoming_change_setting_name].to_s == "enable_upload_debug_mode" }end@@ -486,17 +496,10 @@ RSpec.describe DiscourseUpdates doendcontext "when there are no permanent upcoming changes" do- before { mock_merge_uc_metadata(:beta) }+ before { stub_merge_uc_example_status!(:beta) }it "returns the same new_features array without modification" do- features = [- {- title: "Feed item",- description: "From meta",- created_at: 1.hour.ago.to_s,- upcoming_change_setting_name: "other_setting",- },- ]+ features = [{ title: "Feed item", description: "From meta", created_at: 1.hour.ago.to_s }]result = described_class.merge_new_features_with_upcoming_changes(features)expect(result).to eq(features)@@ -504,6 +507,8 @@ RSpec.describe DiscourseUpdates doendcontext "when the feed already includes a feature for an upcoming change" do+ before { stub_merge_uc_example_status!(:permanent) }+let(:upcoming_change_setting_name) { "enable_upload_debug_mode" }let(:feed_feature) do{@@ -519,13 +524,13 @@ RSpec.describe DiscourseUpdates doendcontext "when the upcoming change is permanent" do- before { mock_merge_uc_metadata(:permanent) }-it "keeps the feed row and does not inject a duplicate from the UC" donew_features = [feed_feature.deep_dup]result = described_class.merge_new_features_with_upcoming_changes(new_features)- expect(result.length).to eq(1)+ expect(result.map { |r| r[:upcoming_change_setting_name] }).to include(+ "enable_upload_debug_mode",+ )row = feature_for_uc_setting(result)expect(row[:title]).to eq("Official feed title")expect(row[:description]).to eq("Marketing copy from the new features feed")@@ -536,42 +541,28 @@ RSpec.describe DiscourseUpdates doendcontext "when the upcoming change is not permanent" do- before { mock_merge_uc_metadata(:beta) }+ before { stub_merge_uc_example_status!(:beta) }it "excludes the item from the new features feed" donew_features = [feed_feature.deep_dup]result = described_class.merge_new_features_with_upcoming_changes(new_features)- expect(result.length).to eq(0)+ expect(result.map { |r| r[:upcoming_change_setting_name] }).not_to include(+ :enable_upload_debug_mode,+ )endendcontext "when this site does not have any permanent upcoming changes" do- before { mock_merge_uc_metadata(:beta) }+ before { stub_merge_uc_example_status!(:beta) }it "excludes the feed item with the upcoming_change_setting_name" donew_features = [feed_feature.deep_dup]result = described_class.merge_new_features_with_upcoming_changes(new_features)- expect(result.length).to eq(0)+ expect(result.map { |r| r[:upcoming_change_setting_name] }).not_to include(+ :enable_upload_debug_mode,+ )endend- end-- context "when a permanent UC is not in the feed" do- before { mock_merge_uc_metadata(:permanent) }-- it "injects a feature using UC name, description, learn URL, and screenshot" do- result = described_class.merge_new_features_with_upcoming_changes([])-- expect(result.length).to eq(1)- feature = feature_for_uc_setting(result)- expect(feature[:title]).to eq(SiteSetting.humanized_names(:enable_upload_debug_mode))- expect(feature[:description]).to eq(SiteSetting.description(:enable_upload_debug_mode))- expect(feature[:link]).to eq("https://meta.discourse.org/t/-/1234")- expect(feature[:screenshot_url]).to eq(- UpcomingChanges.image_data(:enable_upload_debug_mode)[:url],- )- expect(feature[:upcoming_change_setting_name]).to eq(:enable_upload_debug_mode)- endit "uses the status_changed event time when the UC became permanent" dofreeze_timediff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rbindex b05e4796dc7..7d0761e939f 100644--- a/spec/requests/admin/dashboard_controller_spec.rb+++ b/spec/requests/admin/dashboard_controller_spec.rb@@ -159,6 +159,8 @@ RSpec.describe Admin::DashboardController dodescribe "#new_features" doafter { DiscourseUpdates.clean_state }+ before { UpcomingChanges.stubs(:permanent_upcoming_changes).returns([]) }+context "when logged in as an admin" dobefore { sign_in(admin) }@@ -281,16 +283,22 @@ RSpec.describe Admin::DashboardController docontext "when a permanent upcoming change exists and the feed is empty" dobefore do- mock_upcoming_change_metadata(- {- enable_upload_debug_mode: {- impact: "other,developers",- status: :permanent,- impact_type: "other",- impact_role: "developers",- learn_more_url: "https://meta.discourse.org/t/-/1234",+ UpcomingChanges.unstub(:permanent_upcoming_changes)+ UpcomingChanges.stubs(:permanent_upcoming_changes).returns(+ [+ {+ setting: :enable_upload_debug_mode,+ humanized_name: SiteSetting.humanized_names(:enable_upload_debug_mode),+ description: SiteSetting.description(:enable_upload_debug_mode),+ upcoming_change: {+ learn_more_url: "https://meta.discourse.org/t/-/1234",+ image: {+ url:+ "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",+ },+ },},- },+ ],)UpcomingChanges.stubs(:image_exists?).returns(true)UpcomingChanges.stubs(:image_data).returns(diff --git a/spec/serializers/category_serializer_spec.rb b/spec/serializers/category_serializer_spec.rbindex d9d27362fe2..f2dc074ed6e 100644--- a/spec/serializers/category_serializer_spec.rb+++ b/spec/serializers/category_serializer_spec.rb@@ -278,19 +278,12 @@ RSpec.describe CategorySerializer doenddescribe "#category_types" do- it "returns the category types when simplified category creation is enabled" do- SiteSetting.enable_simplified_category_creation = true+ it "returns the category types" dojson = described_class.new(category, scope: admin.guardian, root: false).as_jsonexpect(json[:category_types]).to eq({ discussion: Categories::TypeRegistry.all[:discussion].metadata },)end-- it "returns an empty array when simplified category creation is disabled" do- SiteSetting.enable_simplified_category_creation = false- json = described_class.new(category, scope: admin.guardian, root: false).as_json- expect(json[:category_types]).to eq({})- endenddescribe "#available_category_types" do@@ -312,29 +305,15 @@ RSpec.describe CategorySerializer doendend- context "when simplified category creation is enabled" do- before do- SiteSetting.enable_simplified_category_creation = true- Categories::TypeRegistry.register(MockCategoryType)- end+ before { Categories::TypeRegistry.register(MockCategoryType) }- after { Categories::TypeRegistry.reset! }+ after { Categories::TypeRegistry.reset! }- it "returns the available visible category types" do- json = described_class.new(category, scope: admin.guardian, root: false).as_json- expect(json[:available_category_types]).to eq(- [Categories::TypeRegistry.all[:discussion].metadata],- )- end- end-- context "when simplified category creation is disabled" do- before { SiteSetting.enable_simplified_category_creation = false }-- it "returns an empty array" do- json = described_class.new(category, scope: admin.guardian, root: false).as_json- expect(json[:available_category_types]).to eq([])- end+ it "returns the available visible category types" do+ json = described_class.new(category, scope: admin.guardian, root: false).as_json+ expect(json[:available_category_types]).to eq(+ [Categories::TypeRegistry.all[:discussion].metadata],+ )endendenddiff --git a/spec/system/admin_whats_new_spec.rb b/spec/system/admin_whats_new_spec.rbindex 5c62021d172..ac6158bfe35 100644--- a/spec/system/admin_whats_new_spec.rb+++ b/spec/system/admin_whats_new_spec.rb@@ -11,6 +11,7 @@ describe "Admin What's New Page" doenddef set_new_features_response_json(payload)+ UpcomingChanges.stubs(:permanent_upcoming_changes).returns([])Discourse.redis.set("new_features", MultiJson.dump(payload))enddiff --git a/spec/system/nested_category_default_spec.rb b/spec/system/nested_category_default_spec.rbindex 860a6c8f48f..92a6dd747e6 100644--- a/spec/system/nested_category_default_spec.rb+++ b/spec/system/nested_category_default_spec.rb@@ -19,7 +19,6 @@ RSpec.describe "Nested view category default" dobefore doSiteSetting.nested_replies_enabled = true- SiteSetting.enable_simplified_category_creation = falsenested_category.category_setting.update!(nested_replies_default: true)Fabricate(:nested_topic, topic: topic)end@@ -32,16 +31,9 @@ RSpec.describe "Nested view category default" docategory_page.visit_settings(unchecked_category)- expect(page).to have_css(- ".enable-nested-replies-default input[type='checkbox']:not(:checked)",- visible: :all,- )-- find(".enable-nested-replies-default label.checkbox-label").click+ form.field("category_setting.nested_replies_default").togglecategory_page.save_settings- expect(page).to have_current_path(%r{/c/#{unchecked_category.slug}})-unchecked_category.reloadexpect(unchecked_category.nested_replies_default).to eq(true)end@@ -49,32 +41,7 @@ RSpec.describe "Nested view category default" doit "shows checkbox as checked when category has nested default enabled" docategory_page.visit_settings(nested_category)- expect(page).to have_css(- ".enable-nested-replies-default input[type='checkbox']:checked",- visible: :all,- )- end-- context "with simplified category creation" do- before { SiteSetting.enable_simplified_category_creation = true }-- it "allows admin to enable nested view default for a category" do- unchecked_category = Fabricate(:category, name: "Unchecked Category")-- category_page.visit_settings(unchecked_category)-- form.field("category_setting.nested_replies_default").toggle- category_page.save_settings-- unchecked_category.reload- expect(unchecked_category.nested_replies_default).to eq(true)- end-- it "shows checkbox as checked when category has nested default enabled" do- category_page.visit_settings(nested_category)-- expect(form.field("category_setting.nested_replies_default")).to be_checked- end+ expect(form.field("category_setting.nested_replies_default")).to be_checkedendend