From 6affbabfd3a09c09b8800a8b0f81f2a07498c2fb Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Mon, 3 Oct 2022 12:19:41 -0600 Subject: [PATCH] FIX: New general category changes preventing topic create (#18459) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FIX: New general category changes preventing topic create Follow up to: #18383 The logic in the previous commit was checking for null, but we are seeding the SiteSetting.general_category_id with an id of -1 so we need to check for a positive value as well as checking for null. See: https://meta.discourse.org/t/240661 * Add js test for presence of category… dropdown option --- .../discourse/app/models/composer.js | 3 ++- .../select-kit/category-chooser-test.js | 17 +++++++++++++++++ .../addon/components/category-chooser.js | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) 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` + + `); + + 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"))); } }