Skip to content

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

FEATURE: Make General the default category (#18383)

Blake Erickson3b869743674e
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index 2c365f47f25..bf548f633c2 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -143,7 +143,9 @@ const Composer = RestModel.extend({
const oldCategoryId = this._categoryId;
if (isEmpty(categoryId)) {
- categoryId = null;
+ // Set General as the default category
+ const generalCategoryId = this.siteSettings.general_category_id;
+ categoryId = generalCategoryId ? generalCategoryId : null;
}
this._categoryId = categoryId;
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
index 88c616e3fd3..6fa0cec03e2 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
@@ -39,8 +39,27 @@ acceptance("Composer", function (needs) {
});
needs.settings({
enable_whispers: true,
+ general_category_id: 1,
+ });
+ needs.site({
+ can_tag_topics: true,
+ categories: [
+ {
+ id: 1,
+ name: "General",
+ slug: "general",
+ permission: 1,
+ topic_template: null,
+ },
+ {
+ id: 2,
+ name: "test too",
+ slug: "test-too",
+ permission: 1,
+ topic_template: "",
+ },
+ ],
});
- needs.site({ can_tag_topics: true });
needs.pretender((server, helper) => {
server.post("/uploads/lookup-urls", () => {
return helper.response([]);
@@ -69,6 +88,8 @@ acceptance("Composer", function (needs) {
test("Composer is opened", async function (assert) {
await visit("/");
await click("#create-topic");
+ // Check that General category is selected
+ assert.strictEqual(selectKit(".category-chooser").header().value(), "1");
assert.strictEqual(
document.documentElement.style.getPropertyValue("--composer-height"),
diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js
index 426b914d6f3..5446f009a82 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js
@@ -126,6 +126,23 @@ module(
assert.strictEqual(this.subject.header().label(), "category…");
});
+ test("with allowUncategorized=null and generalCategoryId present", async function (assert) {
+ this.siteSettings.allow_uncategorized_topics = false;
+ this.siteSettings.general_category_id = 4;
+
+ await render(hbs`
+ <CategoryChooser
+ @value={{this.value}}
+ @options={{hash
+ allowUncategorized=null
+ }}
+ />
+ `);
+
+ assert.strictEqual(this.subject.header().value(), null);
+ assert.strictEqual(this.subject.header().label(), "");
+ });
+
test("with allowUncategorized=null none=true", async function (assert) {
this.siteSettings.allow_uncategorized_topics = false;
diff --git a/app/assets/javascripts/select-kit/addon/components/category-chooser.js b/app/assets/javascripts/select-kit/addon/components/category-chooser.js
index f2e420a0b47..2345fb2f61b 100644
--- a/app/assets/javascripts/select-kit/addon/components/category-chooser.js
+++ b/app/assets/javascripts/select-kit/addon/components/category-chooser.js
@@ -44,7 +44,10 @@ export default ComboBoxComponent.extend({
) {
return Category.findUncategorized();
} else {
- return this.defaultItem(null, htmlSafe(I18n.t("category.choose")));
+ const generalCategoryId = this.siteSettings.general_category_id;
+ if (!generalCategoryId) {
+ return this.defaultItem(null, htmlSafe(I18n.t("category.choose")));
+ }
}
},
diff --git a/config/environments/test.rb b/config/environments/test.rb
index ce5485047f3..7a25d5b45c4 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -68,6 +68,11 @@ Discourse::Application.configure do
s.set_regardless_of_locale(:download_remote_images_to_local, false)
s.set_regardless_of_locale(:unique_posts_mins, 0)
s.set_regardless_of_locale(:max_consecutive_replies, 0)
+
+ # Most existing tests were written assuming allow_uncategorized_topics
+ # was enabled, so we should set it to true.
+ s.set_regardless_of_locale(:allow_uncategorized_topics, true)
+
# disable plugins
if ENV['LOAD_PLUGINS'] == '1'
s.set_regardless_of_locale(:discourse_narrative_bot_enabled, false)
diff --git a/config/site_settings.yml b/config/site_settings.yml
index ebf5c76a6bc..8243bd1a7bd 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -806,7 +806,7 @@ posting:
max_emojis_in_title: 1
allow_uncategorized_topics:
client: true
- default: true
+ default: false
refresh: true
allow_duplicate_topic_titles: false
allow_duplicate_topic_titles_category: false
@@ -2304,6 +2304,7 @@ uncategorized:
general_category_id:
default: -1
hidden: true
+ client: true
meta_category_id:
default: -1
hidden: true
diff --git a/db/migrate/20220927171707_disable_allow_uncategorized_new_sites.rb b/db/migrate/20220927171707_disable_allow_uncategorized_new_sites.rb
new file mode 100644
index 00000000000..979b8a6b563
--- /dev/null
+++ b/db/migrate/20220927171707_disable_allow_uncategorized_new_sites.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class DisableAllowUncategorizedNewSites < ActiveRecord::Migration[7.0]
+ def up
+ result = execute <<~SQL
+ SELECT created_at
+ FROM schema_migration_details
+ ORDER BY created_at
+ LIMIT 1
+ SQL
+
+ # keep allow uncategorized for existing sites
+ if result.first['created_at'].to_datetime < 1.hour.ago
+ execute <<~SQL
+ INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
+ VALUES('allow_uncategorized_topics', 5, 't', NOW(), NOW())
+ ON CONFLICT (name) DO NOTHING
+ SQL
+ end
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/spec/models/topic_converter_spec.rb b/spec/models/topic_converter_spec.rb
index d66b1cd045a..7598b144328 100644
--- a/spec/models/topic_converter_spec.rb
+++ b/spec/models/topic_converter_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe TopicConverter do
fab!(:author) { Fabricate(:user) }
fab!(:category) { Fabricate(:category, topic_count: 1) }
fab!(:private_message) { Fabricate(:private_message_topic, user: author) } # creates a topic without a first post
- let(:first_post) { create_post(user: author, topic: private_message) }
+ let(:first_post) { create_post(user: author, topic: private_message, allow_uncategorized_topics: false) }
let(:other_user) { private_message.topic_allowed_users.find { |u| u.user != author }.user }
let(:uncategorized_category) do
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index c92b928185d..9ef8c27d4d1 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -45,6 +45,12 @@ module Helpers
end
def create_post(args = {})
+ # Pretty much all the tests with `create_post` will fail without this
+ # since allow_uncategorized_topics is now false by default
+ unless args[:allow_uncategorized_topics] == false
+ SiteSetting.allow_uncategorized_topics = true
+ end
+
args[:title] ||= "This is my title #{Helpers.next_seq}"
args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}"
args[:topic_id] = args[:topic].id if args[:topic]