Skip to content

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

FIX: Bug with permanent delete modal (#18825)

Penar Musaraj343037b0228c
diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js
index f682f8e68b1..7e473e321cd 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic.js
@@ -564,8 +564,8 @@ export default Controller.extend(bufferedProperty("model"), {
return this.get("model.details").removeAllowedGroup(group);
},
- deleteTopic() {
- this.deleteTopic();
+ deleteTopic(opts = {}) {
+ this.deleteTopic(opts);
},
// Archive a PM (as opposed to archiving a topic)
@@ -1522,7 +1522,11 @@ export default Controller.extend(bufferedProperty("model"), {
this.model.recover();
},
- deleteTopic(opts) {
+ deleteTopic(opts = {}) {
+ if (opts.force_destroy) {
+ return this.model.destroy(this.currentUser, opts);
+ }
+
if (
this.model.views > this.siteSettings.min_topic_views_for_delete_confirm
) {
diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js
index ce9696e2725..940bc252d0d 100644
--- a/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/controllers/topic-test.js
@@ -7,6 +7,7 @@ import { Placeholder } from "discourse/lib/posts-with-placeholders";
import User from "discourse/models/user";
import { next } from "@ember/runloop";
import { getOwner } from "discourse-common/lib/get-owner";
+import sinon from "sinon";
function topicWithStream(streamDetails) {
const topic = this.store.createRecord("topic");
@@ -78,6 +79,27 @@ module("Unit | Controller | topic", function (hooks) {
assert.ok(destroyed, "destroy not popular topic");
});
+ test("deleteTopic permanentDelete", function (assert) {
+ const opts = { force_destroy: true };
+ const model = this.store.createRecord("topic");
+ const siteSettings = this.owner.lookup("service:site-settings");
+ siteSettings.min_topic_views_for_delete_confirm = 5;
+
+ const controller = this.owner.lookup("controller:topic");
+ controller.setProperties({ model });
+ model.set("views", 100);
+
+ const stub = sinon.stub(model, "destroy");
+ controller.send("deleteTopic", { force_destroy: true });
+
+ assert.deepEqual(
+ stub.getCall(0).args[1],
+ opts,
+ "does not show delete confirm permanently deleting, passes opts to model action"
+ // permanent delete happens after first delete, no need to show modal again
+ );
+ });
+
test("toggleMultiSelect", async function (assert) {
const model = this.store.createRecord("topic");
const controller = getOwner(this).lookup("controller:topic");