From d5cf128dbd239350ab4e1acd36b78a0bd8662a22 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 24 Feb 2023 13:48:08 +0100 Subject: [PATCH] DEV: Fix an error in topic deletion (#20440) Spotted as log entry in tests: ``` TypeError: Cannot read properties of undefined (reading 'force_destroy') ``` --- .../discourse/app/controllers/delete-topic-confirm.js | 5 ++--- app/assets/javascripts/discourse/app/models/topic.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js b/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js index eb5496e89a7..423999c3c0f 100644 --- a/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js +++ b/app/assets/javascripts/discourse/app/controllers/delete-topic-confirm.js @@ -1,4 +1,4 @@ -import Controller, { inject as controller } from "@ember/controller"; +import Controller from "@ember/controller"; import I18n from "I18n"; import ModalFunctionality from "discourse/mixins/modal-functionality"; import { action } from "@ember/object"; @@ -7,7 +7,6 @@ import discourseComputed from "discourse-common/utils/decorators"; // Modal that displays confirmation text when user deletes a topic // The modal will display only if the topic exceeds a certain amount of views export default Controller.extend(ModalFunctionality, { - topicController: controller("topic"), deletingTopic: false, @discourseComputed("deletingTopic") @@ -25,7 +24,7 @@ export default Controller.extend(ModalFunctionality, { deleteTopic() { this.set("deletingTopic", true); - this.topicController.model + this.model .destroy(this.currentUser) .then(() => this.send("closeModal")) .catch(() => { diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js index 700037c827d..39521f4f18a 100644 --- a/app/assets/javascripts/discourse/app/models/topic.js +++ b/app/assets/javascripts/discourse/app/models/topic.js @@ -453,7 +453,7 @@ const Topic = RestModel.extend({ }, // Delete this topic - destroy(deleted_by, opts) { + destroy(deleted_by, opts = {}) { return ajax(`/t/${this.id}`, { data: { context: window.location.pathname, ...opts }, type: "DELETE",