From 7592754c90223c39356ac348202a04c71366b999 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Tue, 26 Jul 2022 15:45:34 -0400 Subject: [PATCH] FIX: Allow users to quote in closed topics (#17645) Previously, non-staff users could only quote if they had an open composer. This change shows the quote control when selecting text in closed topics at all times and if the composer isn't already open, it will default to creating a linked topic. --- .../discourse/app/components/quote-button.js | 12 ++++---- .../acceptance/topic-quote-button-test.js | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js index 40d13d7af32..a5066f754a1 100644 --- a/app/assets/javascripts/discourse/app/components/quote-button.js +++ b/app/assets/javascripts/discourse/app/components/quote-button.js @@ -417,12 +417,14 @@ export default Component.extend(KeyEnterEscape, { return getAbsoluteURL(postUrl(topic.slug, topic.id, postNumber)); }, - @discourseComputed("topic.details.can_create_post", "composerVisible") - embedQuoteButton(canCreatePost, composerOpened) { + @discourseComputed( + "topic.details.can_create_post", + "topic.details.can_reply_as_new_topic" + ) + embedQuoteButton(canCreatePost, canReplyAsNewTopic) { return ( - (canCreatePost || composerOpened) && - this.currentUser && - this.currentUser.get("enable_quoting") + (canCreatePost || canReplyAsNewTopic) && + this.currentUser?.get("enable_quoting") ); }, diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js index 6fb32201ff7..2859e2c9110 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-quote-button-test.js @@ -8,6 +8,8 @@ import { } from "discourse/tests/helpers/qunit-helpers"; import I18n from "I18n"; import { click, triggerKeyEvent, visit } from "@ember/test-helpers"; +import { cloneJSON } from "discourse-common/lib/object"; +import topicFixtures from "discourse/tests/fixtures/topic"; import { test } from "qunit"; // This tests are flaky on Firefox. Fails with `calling set on destroyed object` @@ -64,6 +66,32 @@ acceptance("Topic - Quote button - logged in", function (needs) { ); }); +acceptance("Closed Topic - Quote button - logged in", function (needs) { + needs.user(); + + needs.pretender((server, helper) => { + const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]); + topicResponse.closed = true; + topicResponse.details.can_create_post = false; + + server.get("/t/280.json", () => helper.response(topicResponse)); + }); + + chromeTest("Shows quote button in closed topics", async function (assert) { + await visit("/t/internationalization-localization/280"); + await selectText("#post_1 .cooked p:first-child"); + assert.ok(exists(".insert-quote"), "it shows the quote button"); + + await click(".insert-quote"); + assert.ok( + query(".d-editor-input") + .value.trim() + .startsWith("Continuing the discussion from"), + "quote action defaults to reply as new topic (since topic is closed)" + ); + }); +}); + acceptance("Topic - Quote button - anonymous", function (needs) { needs.settings({ share_quote_visibility: "anonymous",