FIX: Show perma-delete in menu without refresh (#14740)

It needed a page refresh because the post was not updated on the client
side.
This commit is contained in:
Bianca Nenciu 2021-11-09 11:50:45 +02:00 committed by GitHub
parent 911f9b180a
commit 42f65b4c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 4 deletions

View File

@ -53,7 +53,7 @@ export function transformBasicPost(post) {
created_at: post.created_at,
updated_at: post.updated_at,
canDelete: post.can_delete,
canPermanentlyDelete: post.can_permanently_delete,
canPermanentlyDelete: false,
showFlagDelete: false,
canRecover: post.can_recover,
canEdit: post.can_edit,
@ -264,7 +264,8 @@ export default function transformPost(
postAtts.canRecoverTopic = postAtts.isDeleted && details.can_recover;
postAtts.canDeleteTopic = !postAtts.isDeleted && details.can_delete;
postAtts.expandablePost = topic.expandable_first_post;
postAtts.canPermanentlyDeleteTopic = details.can_permanently_delete;
postAtts.canPermanentlyDelete =
postAtts.isDeleted && details.can_permanently_delete;
// Show a "Flag to delete" message if not staff and you can't
// otherwise delete it.
@ -281,6 +282,8 @@ export default function transformPost(
!post.deleted_at &&
currentUser &&
(currentUser.staff || !post.user_deleted);
postAtts.canPermanentlyDelete =
postAtts.isDeleted && post.can_permanently_delete;
}
_additionalAttributes.forEach((a) => (postAtts[a] = post[a]));

View File

@ -208,6 +208,8 @@ const Post = RestModel.extend({
deleted_at: new Date(),
deleted_by: deletedBy,
can_delete: false,
can_permanently_delete:
this.siteSettings.can_permanently_delete && deletedBy.admin,
can_recover: true,
});
} else {
@ -219,6 +221,7 @@ const Post = RestModel.extend({
this.setProperties({
cooked: cooked,
can_delete: false,
can_permanently_delete: false,
version: this.version + 1,
can_recover: true,
can_edit: false,

View File

@ -451,6 +451,8 @@ const Topic = RestModel.extend({
deleted_by,
"details.can_delete": false,
"details.can_recover": true,
"details.can_permanently_delete":
this.siteSettings.can_permanently_delete && deleted_by.admin,
});
if (!deleted_by.staff) {
DiscourseURL.redirectTo("/");

View File

@ -37,7 +37,7 @@ export function buildManageButtons(attrs, currentUser, siteSettings) {
});
}
if (attrs.canPermanentlyDelete || attrs.canPermanentlyDeleteTopic) {
if (attrs.canPermanentlyDelete) {
contents.push({
icon: "trash-alt",
className: "popup-menu-button permanently-delete",

View File

@ -656,7 +656,7 @@ discourseModule("Integration | Component | Widget | post", function (hooks) {
componentTest("permanently delete topic", {
template: hbs`{{mount-widget widget="post" args=args permanentlyDeletePost=permanentlyDeletePost}}`,
beforeEach() {
this.set("args", { canManage: true, canPermanentlyDeleteTopic: true });
this.set("args", { canManage: true, canPermanentlyDelete: true });
this.set("permanentlyDeletePost", () => (this.deleted = true));
},
async test(assert) {

View File

@ -1676,6 +1676,7 @@ security:
hidden: true
can_permanently_delete:
default: false
client: true
hidden: true
onebox: