Skip to content

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

FIX: New general category changes preventing topic create (#18459)

Blake Erickson6affbabfd3a0
diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js
index bf548f633c2..466491ea4b2 100644
--- a/app/assets/javascripts/discourse/app/models/composer.js
+++ b/app/assets/javascripts/discourse/app/models/composer.js
@@ -145,7 +145,8 @@ const Composer = RestModel.extend({
if (isEmpty(categoryId)) {
// Set General as the default category
const generalCategoryId = this.siteSettings.general_category_id;
- categoryId = generalCategoryId ? generalCategoryId : null;
+ categoryId =
+ generalCategoryId && generalCategoryId > 0 ? generalCategoryId : null;
}
this._categoryId = categoryId;
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 5446f009a82..c99ad0e64bb 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
@@ -143,6 +143,23 @@ module(
assert.strictEqual(this.subject.header().label(), "");
});
+ test("with allowUncategorized=null and generalCategoryId present, but not set", async function (assert) {
+ this.siteSettings.allow_uncategorized_topics = false;
+ this.siteSettings.general_category_id = -1;
+
+ await render(hbs`
+ <CategoryChooser
+ @value={{this.value}}
+ @options={{hash
+ allowUncategorized=null
+ }}
+ />
+ `);
+
+ assert.strictEqual(this.subject.header().value(), null);
+ assert.strictEqual(this.subject.header().label(), "category…");
+ });
+
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 2345fb2f61b..7193d6457f2 100644
--- a/app/assets/javascripts/select-kit/addon/components/category-chooser.js
+++ b/app/assets/javascripts/select-kit/addon/components/category-chooser.js
@@ -45,7 +45,7 @@ export default ComboBoxComponent.extend({
return Category.findUncategorized();
} else {
const generalCategoryId = this.siteSettings.general_category_id;
- if (!generalCategoryId) {
+ if (!generalCategoryId || generalCategoryId < 0) {
return this.defaultItem(null, htmlSafe(I18n.t("category.choose")));
}
}