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

* FIX: Hide delete button if user cannot delete and/or flag a post

* Move canFlag conditional
This commit is contained in:
jbrw 2020-10-27 13:02:31 -04:00 committed by GitHub
parent 1698b34d2b
commit 35cfca1f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -258,6 +258,7 @@ export default function transformPost(
postAtts.showFlagDelete =
!postAtts.canDelete &&
postAtts.yours &&
postAtts.canFlag &&
currentUser &&
!currentUser.staff;
} else {

View File

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