FIX: Don't show the "Flag to delete" message to staff

FIX: Don’t show the “Flag to delete” message to staff

If they can’t delete, flagging should not either.

diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6
index 90693c3..4aad29a 100644
--- a/app/assets/javascripts/discourse/lib/transform-post.js.es6
+++ b/app/assets/javascripts/discourse/lib/transform-post.js.es6
@@ -45,6 +45,7 @@ export function transformBasicPost(post) {
     created_at: post.created_at,
     updated_at: post.updated_at,
     canDelete: post.can_delete,
+    showFlagDelete: false,
     canRecover: post.can_recover,
     canEdit: post.can_edit,
     canFlag: !Ember.isEmpty(post.get("flagsAvailable")),
@@ -230,6 +231,15 @@ export default function transformPost(
     postAtts.canRecoverTopic = postAtts.isDeleted && details.can_recover;
     postAtts.canDeleteTopic = !postAtts.isDeleted && details.can_delete;
     postAtts.expandablePost = topic.expandable_first_post;
+
+    // Show a "Flag to delete" message if not staff and you can't
+    // otherwise delete it.
+    postAtts.showFlagDelete = (
+      !postAtts.canDelete &&
+      postAtts.yours &&
+      (currentUser && !currentUser.staff)
+    );
+
   } else {
     postAtts.canRecover = postAtts.isDeleted && postAtts.canRecover;
     postAtts.canDelete =
diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6
index dea4763..06fe905 100644
--- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6
@@ -307,7 +307,7 @@ registerButton("delete", attrs => {
       icon: "far-trash-alt",
       className: "delete"
     };
-  } else if (!attrs.canDelete && attrs.firstPost && attrs.yours) {
+  } else if (attrs.showFlagDelete) {
     return {
       id: "delete_topic",
       action: "showDeleteTopicModal",

GitHub sha: 7a9e85b1

1 Like

Was the issue only in the client side?

For this part yes. The server was returning false for canDelete but the front end had some logic to show the button anyway with a message.

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: