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

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

It needed a page refresh because the post was not updated on the client side.

diff --git a/app/assets/javascripts/discourse/app/lib/transform-post.js b/app/assets/javascripts/discourse/app/lib/transform-post.js
index 3cc5b17..37a1e49 100644
--- a/app/assets/javascripts/discourse/app/lib/transform-post.js
+++ b/app/assets/javascripts/discourse/app/lib/transform-post.js
@@ -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]));
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js
index 6d2a43d..0751271 100644
--- a/app/assets/javascripts/discourse/app/models/post.js
+++ b/app/assets/javascripts/discourse/app/models/post.js
@@ -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,
diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index b2b638b..6883581 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js
@@ -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("/");
diff --git a/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js b/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js
index 68d79f3..7564ce2 100644
--- a/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/post-admin-menu.js
@@ -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",
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 e66db63..187617d 100644
--- a/app/assets/javascripts/discourse/tests/integration/widgets/post-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/widgets/post-test.js
@@ -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) {
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 5cfbd0e..11f0248 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1676,6 +1676,7 @@ security:
     hidden: true
   can_permanently_delete:
     default: false
+    client: true
     hidden: true
 
 onebox:

GitHub sha: 42f65b4c485bfb318eb528629b3d5c977d249d94

This commit appears in #14740 which was approved by eviltrout. It was merged by nbianca.