FIX: Bug with permanent delete modal (#18825)
Repro steps: - enable permanent deletes (via hidden site setting) - set `min_topic_views_for_delete_confirm` to 0 When permanently deleting, the delete confirm modal is shown (for a second time) and it doesn't pass the `force_destroy` parameter to the request and the action results in a 422 error (i.e. can't perma-delete). This change skips showing the confirm modal when perma-deleting given that it has already been show on the first delete action.
This commit is contained in:
parent
2ae09db4aa
commit
343037b022
|
@ -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
|
||||
) {
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue