Skip to content

A platform for community discussion. Free, open, simple.

FIX: Hide delete button if user cannot delete and/or flag a post (#11045)

jbrw35cfca1f3fc5
diff --git a/app/assets/javascripts/discourse/app/lib/transform-post.js b/app/assets/javascripts/discourse/app/lib/transform-post.js
index d6a03a9d169..58295dbeda0 100644
--- a/app/assets/javascripts/discourse/app/lib/transform-post.js
+++ b/app/assets/javascripts/discourse/app/lib/transform-post.js
@@ -258,6 +258,7 @@ export default function transformPost(
postAtts.showFlagDelete =
!postAtts.canDelete &&
postAtts.yours &&
+ postAtts.canFlag &&
currentUser &&
!currentUser.staff;
} else {
diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/post-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/post-test.js
index f24012e1750..41697e40120 100644
--- a/app/assets/javascripts/discourse/tests/integration/widgets/post-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/widgets/post-test.js
@@ -309,10 +309,14 @@ widgetTest(
this.set("args", {
canDeleteTopic: false,
showFlagDelete: true,
+ canFlag: true,
});
},
- test(assert) {
+ async test(assert) {
+ await click(".show-more-actions");
+
+ assert.equal(find("button.create-flag").length, 1, `button is displayed`);
assert.equal(find("button.delete").length, 1, `button is displayed`);
assert.equal(
find("button.delete").attr("title"),
@@ -350,10 +354,11 @@ widgetTest("delete post button", {
template:
'{{mount-widget widget="post" args=args deletePost=(action "deletePost")}}',
beforeEach() {
- this.set("args", { canDelete: true });
+ this.set("args", { canDelete: true, canFlag: true });
this.on("deletePost", () => (this.deletePostCalled = true));
},
async test(assert) {
+ await click(".show-more-actions");
await click("button.delete");
assert.ok(this.deletePostCalled, "it triggered the delete action");
},
@@ -369,6 +374,29 @@ widgetTest(`delete post button - can't delete`, {
},
});
+widgetTest(`delete post button - can't delete, can't flag`, {
+ template: '{{mount-widget widget="post" args=args}}',
+ beforeEach() {
+ this.set("args", {
+ canDeleteTopic: false,
+ showFlagDelete: false,
+ canFlag: false,
+ });
+ },
+ test(assert) {
+ assert.equal(
+ find("button.delete").length,
+ 0,
+ `delete button is not displayed`
+ );
+ assert.equal(
+ find("button.create-flag").length,
+ 0,
+ `flag button is not displayed`
+ );
+ },
+});
+
widgetTest("recover post button", {
template:
'{{mount-widget widget="post" args=args recoverPost=(action "recoverPost")}}',