diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.js index 7a7054bece0..44ff23abe0d 100644 --- a/app/assets/javascripts/discourse/app/models/composer.js +++ b/app/assets/javascripts/discourse/app/models/composer.js @@ -445,7 +445,8 @@ const Composer = RestModel.extend({ return ( canCategorize && !categoryId && - !this.siteSettings.allow_uncategorized_topics + !this.siteSettings.allow_uncategorized_topics && + !!this._hasTopicTemplates ); }, @@ -753,6 +754,10 @@ const Composer = RestModel.extend({ } } + this._hasTopicTemplates = this.site.categories.some( + (c) => c.topic_template + ); + if (opts.postId) { promise = promise.then(() => this.store.find("post", opts.postId).then((post) => { diff --git a/test/javascripts/acceptance/composer-uncategorized-test.js b/test/javascripts/acceptance/composer-uncategorized-test.js index 594cd9c88a3..26ff2f1148c 100644 --- a/test/javascripts/acceptance/composer-uncategorized-test.js +++ b/test/javascripts/acceptance/composer-uncategorized-test.js @@ -1,13 +1,16 @@ import selectKit from "helpers/select-kit-helper"; import { acceptance, updateCurrentUser } from "helpers/qunit-helpers"; -acceptance("Composer and uncategorized is not allowed", { - loggedIn: true, - settings: { - enable_whispers: true, - allow_uncategorized_topics: false, - }, -}); +acceptance( + "Composer disabled, uncategorized not allowed when any topic_template present", + { + loggedIn: true, + settings: { + enable_whispers: true, + allow_uncategorized_topics: false, + }, + } +); QUnit.test("Disable body until category is selected", async (assert) => { updateCurrentUser({ moderator: false, admin: false, trust_level: 1 }); @@ -47,3 +50,69 @@ QUnit.test("Disable body until category is selected", async (assert) => { "textarea is still enabled" ); }); + +acceptance( + "Composer enabled, uncategorized not allowed when topic_template not present", + { + loggedIn: true, + settings: { + allow_uncategorized_topics: false, + }, + site: { + categories: [ + { + id: 1, + name: "test won", + slug: "test-won", + topic_template: null, + }, + { + id: 2, + name: "test too", + slug: "test-too", + topic_template: "", + }, + { + id: 3, + name: "test free", + slug: "test-free", + topic_template: null, + }, + ], + }, + } +); + +QUnit.test( + "Enable composer/body if no topic templates present", + async (assert) => { + updateCurrentUser({ moderator: false, admin: false, trust_level: 1 }); + + await visit("/"); + await click("#create-topic"); + assert.ok(exists(".d-editor-input"), "the composer input is visible"); + assert.ok( + exists(".category-input .popup-tip.bad.hide"), + "category errors are hidden by default" + ); + assert.ok( + find(".d-editor-textarea-wrapper.disabled").length === 0, + "textarea is enabled" + ); + + await click("#reply-control button.create"); + assert.ok( + exists(".category-input .popup-tip.bad"), + "it shows the choose a category error" + ); + + const categoryChooser = selectKit(".category-chooser"); + await categoryChooser.expand(); + await categoryChooser.selectRowByValue(1); + + assert.ok( + !exists(".category-input .popup-tip.bad"), + "category error removed after selecting category" + ); + } +); diff --git a/test/javascripts/fixtures/site-fixtures.js b/test/javascripts/fixtures/site-fixtures.js index 48e2e18dc93..bdb8504b8f3 100644 --- a/test/javascripts/fixtures/site-fixtures.js +++ b/test/javascripts/fixtures/site-fixtures.js @@ -66,7 +66,8 @@ export default { notification_level: null, background_url: null, show_subcategory_list: false, - default_view: "latest" + default_view: "latest", + topic_template: "my topic template" }, { id: 10,