FIX: Ensure allowed_tags and allowed_tag_groups can be removed (#16454)

This commit is contained in:
David Taylor 2022-04-12 11:14:29 +01:00 committed by GitHub
parent e7f3702d9b
commit 9c33f6de05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 8 deletions

View File

@ -218,14 +218,8 @@ const Category = RestModel.extend({
all_topics_wiki: this.all_topics_wiki,
allow_unlimited_owner_edits_on_first_post: this
.allow_unlimited_owner_edits_on_first_post,
allowed_tags:
this.allowed_tags && this.allowed_tags.length > 0
? this.allowed_tags
: null,
allowed_tag_groups:
this.allowed_tag_groups && this.allowed_tag_groups.length > 0
? this.allowed_tag_groups
: null,
allowed_tags: this.allowed_tags,
allowed_tag_groups: this.allowed_tag_groups,
allow_global_tags: this.allow_global_tags,
required_tag_groups: this.required_tag_groups,
sort_order: this.sort_order,

View File

@ -10,6 +10,7 @@ import DiscourseURL from "discourse/lib/url";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import sinon from "sinon";
import { test } from "qunit";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Category Edit", function (needs) {
needs.user();
@ -95,6 +96,48 @@ acceptance("Category Edit", function (needs) {
await click("#save-category");
assert.strictEqual(count(".required-tag-group-row"), 1);
await click(".delete-required-tag-group");
assert.strictEqual(count(".required-tag-group-row"), 0);
await click("#save-category");
assert.strictEqual(count(".required-tag-group-row"), 0);
});
test("Editing allowed tags and tag groups", async function (assert) {
await visit("/c/bug/edit/tags");
const allowedTagChooser = selectKit("#category-allowed-tags");
await allowedTagChooser.expand();
await allowedTagChooser.selectRowByValue("monkey");
const allowedTagGroupChooser = selectKit("#category-allowed-tag-groups");
await allowedTagGroupChooser.expand();
await allowedTagGroupChooser.selectRowByValue("TagGroup1");
await click("#save-category");
const payload = JSON.parse(
pretender.handledRequests[pretender.handledRequests.length - 1]
.requestBody
);
assert.deepEqual(payload.allowed_tags, ["monkey"]);
assert.deepEqual(payload.allowed_tag_groups, ["TagGroup1"]);
await allowedTagChooser.expand();
await allowedTagChooser.deselectItemByValue("monkey");
await allowedTagGroupChooser.expand();
await allowedTagGroupChooser.deselectItemByValue("TagGroup1");
await click("#save-category");
const removePayload = JSON.parse(
pretender.handledRequests[pretender.handledRequests.length - 1]
.requestBody
);
assert.deepEqual(removePayload.allowed_tags, []);
assert.deepEqual(removePayload.allowed_tag_groups, []);
});
test("Index Route", async function (assert) {