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

* 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
This commit is contained in:
Blake Erickson 2022-10-03 12:19:41 -06:00 committed by GitHub
parent a5fbdba9d4
commit 6affbabfd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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")));
}
}