A platform for community discussion. Free, open, simple.
FEATURE: Accept tags param when opening a /new-message (#36421)
Natalie Tay244d78fbb729
diff --git a/frontend/discourse/app/routes/new-message.js b/frontend/discourse/app/routes/new-message.jsindex e5cf62f2179..16cdc9c7ef7 100644--- a/frontend/discourse/app/routes/new-message.js+++ b/frontend/discourse/app/routes/new-message.js@@ -32,8 +32,8 @@ export default class extends DiscourseRoute {.then(() => this.#openComposerWithPrefilledValues(params));}- #openComposer({ title, body }, recipients = "") {- next(() => this.composer.openNewMessage({ recipients, title, body }));+ #openComposer({ title, body, tags }, recipients = "") {+ next(() => this.composer.openNewMessage({ recipients, title, body, tags }));}#openComposerWithPrefilledValues(params) {diff --git a/frontend/discourse/app/services/composer.js b/frontend/discourse/app/services/composer.jsindex d16c9b25ecf..de481904df3 100644--- a/frontend/discourse/app/services/composer.js+++ b/frontend/discourse/app/services/composer.js@@ -1489,12 +1489,14 @@ export default class ComposerService extends Service {}@action- async openNewMessage({ title, body, recipients, hasGroups }) {+ async openNewMessage({ title, body, recipients, hasGroups, tags }) {+ tags = await this.filterTags(tags);return this.open({action: Composer.PRIVATE_MESSAGE,recipients,topicTitle: title,topicBody: body,+ topicTags: tags,archetypeId: "private_message",draftKey: this.privateMessageDraftKey,hasGroups,@@ -1565,7 +1567,11 @@ export default class ComposerService extends Service {this.model.set("title", opts.topicTitle);}- if (opts.topicTags && this.site.can_tag_topics) {+ const isPrivateMessage = opts.action === Composer.PRIVATE_MESSAGE;+ const canTag =+ this.site.can_tag_topics && (!isPrivateMessage || this.site.can_tag_pms);++ if (opts.topicTags && canTag) {let tags = escapeExpression(opts.topicTags).split(",").slice(0, this.siteSettings.max_tags_per_topic);diff --git a/frontend/discourse/tests/acceptance/new-message-test.js b/frontend/discourse/tests/acceptance/new-message-test.jsindex 448839324ef..21da285960a 100644--- a/frontend/discourse/tests/acceptance/new-message-test.js+++ b/frontend/discourse/tests/acceptance/new-message-test.js@@ -37,3 +37,60 @@ acceptance("New Message - Authenticated", function (needs) {);});});++acceptance("New Message - Authenticated with Tags Enabled", function (needs) {+ needs.user();+ needs.site({ can_tag_topics: true, can_tag_pms: true });++ test("accessing new-message route with tags parameter when can_tag_pms is enabled", async function (assert) {+ await visit(+ "/new-message?username=tomtom&title=Help&body=Thisbody&tags=tag1,tag2"+ );++ assert.dom(".composer-fields").exists("opens the composer");+ assert.dom("#reply-title").hasValue("Help", "pre-fills message title");+ assert+ .dom(".d-editor-input")+ .hasValue("Thisbody", "pre-fills message body");++ const privateMessageUsers = selectKit("#private-message-users");+ assert.strictEqual(+ privateMessageUsers.header().value(),+ "tomtom",+ "it selects correct username"+ );++ const tags = selectKit(".mini-tag-chooser");+ assert.strictEqual(tags.header().value(), "tag1,tag2", "it pre-fills tags");+ });+});++acceptance("New Message - Authenticated with Tags Disabled", function (needs) {+ needs.user();+ needs.site({ can_tag_topics: true, can_tag_pms: false });++ test("accessing new-message route with tags parameter when can_tag_pms is disabled", async function (assert) {+ await visit(+ "/new-message?username=tomtom&title=Help&body=Thisbody&tags=tag1,tag2"+ );++ assert.dom(".composer-fields").exists("opens the composer");+ assert.dom("#reply-title").hasValue("Help", "pre-fills message title");+ assert+ .dom(".d-editor-input")+ .hasValue("Thisbody", "pre-fills message body");++ const privateMessageUsers = selectKit("#private-message-users");+ assert.strictEqual(+ privateMessageUsers.header().value(),+ "tomtom",+ "it selects correct username"+ );++ assert+ .dom(".mini-tag-chooser")+ .doesNotExist(+ "tags selector is not visible when can_tag_pms is disabled"+ );+ });+});