Skip to content

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

FEATURE: show modal when user without permissions tries to delete their own topic (#6086)

Maja Komelfa38891a9895
diff --git a/app/assets/javascripts/discourse/templates/modal/delete-topic-disallowed.hbs b/app/assets/javascripts/discourse/templates/modal/delete-topic-disallowed.hbs
new file mode 100644
index 00000000000..90c11afd65b
--- /dev/null
+++ b/app/assets/javascripts/discourse/templates/modal/delete-topic-disallowed.hbs
@@ -0,0 +1,6 @@
+{{#d-modal-body}}
+ <p>{{{i18n "post.controls.delete_topic_disallowed_modal"}}}</p>
+{{/d-modal-body}}
+<div class="modal-footer">
+ {{d-button action="closeModal" class="btn-primary" label="close"}}
+</div>
diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6
index 55f44ab0057..7e65b0ac478 100644
--- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6
@@ -1,6 +1,7 @@
import { applyDecorators, createWidget } from "discourse/widgets/widget";
import { avatarAtts } from "discourse/widgets/actions-summary";
import { h } from "virtual-dom";
+import showModal from "discourse/lib/show-modal";
const LIKE_ACTION = 2;
@@ -281,6 +282,14 @@ registerButton("delete", attrs => {
icon: "trash-o",
className: "delete"
};
+ } else if (!attrs.canDelete && attrs.firstPost && attrs.yours) {
+ return {
+ id: "delete_topic",
+ action: "showDeleteTopicModal",
+ title: "post.controls.delete_topic_disallowed",
+ icon: "trash-o",
+ className: "delete"
+ };
}
});
@@ -467,6 +476,10 @@ export default createWidget("post-menu", {
this.state.adminVisible = false;
},
+ showDeleteTopicModal() {
+ showModal("delete-topic-disallowed");
+ },
+
showMoreActions() {
this.state.collapsed = false;
if (!this.state.likedUsers.length) {
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index b6a1dcce2dc..2ec1caf0ea9 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2104,6 +2104,8 @@ en:
lock_post_description: "prevent the poster from editing this post"
unlock_post: "Unlock Post"
unlock_post_description: "allow the poster to edit this post"
+ delete_topic_disallowed_modal: "You don't have permission to delete this topic. If you really want it to be deleted, submit a flag for moderator attention together with reasoning."
+ delete_topic_disallowed: "you don't have permission to delete this topic"
actions:
flag: 'Flag'
diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6
index 4cc8fb34ced..7bd21c9342a 100644
--- a/test/javascripts/widgets/post-test.js.es6
+++ b/test/javascripts/widgets/post-test.js.es6
@@ -298,6 +298,30 @@ widgetTest(`delete topic button - can't delete`, {
}
});
+widgetTest(
+ `delete topic button - can't delete when topic author without permission`,
+ {
+ template:
+ '{{mount-widget widget="post" args=args deletePost="deletePost"}}',
+ beforeEach() {
+ this.set("args", {
+ canDeleteTopic: false,
+ yours: true,
+ firstPost: true
+ });
+ },
+
+ test(assert) {
+ assert.equal(this.$("button.delete").length, 1, `button is displayed`);
+ assert.equal(
+ this.$("button.delete").attr("title"),
+ I18n.t("post.controls.delete_topic_disallowed"),
+ `shows the right button title for users without permissions`
+ );
+ }
+ }
+);
+
widgetTest("recover topic button", {
template:
'{{mount-widget widget="post" args=args recoverPost="recoverPost"}}',