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.
This commit is contained in:
Penar Musaraj 2022-07-26 15:45:34 -04:00 committed by GitHub
parent b5c1132546
commit 7592754c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View File

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

View File

@ -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",