A platform for community discussion. Free, open, simple.
FIX: Ability to delete nested topic (#41347)
Mark VanLandingham85df88c703f7
diff --git a/app/assets/stylesheets/common/nested-view.scss b/app/assets/stylesheets/common/nested-view.scssindex b914c5eb4d4..9946bf74356 100644--- a/app/assets/stylesheets/common/nested-view.scss+++ b/app/assets/stylesheets/common/nested-view.scss@@ -304,6 +304,12 @@min-width: 0;}+ &__op-article.is-deleted {+ .nested-view__op-content > .cooked {+ background-color: var(--danger-low-mid);+ }+ }+&__op-content {margin-top: 0.5em;}diff --git a/frontend/discourse/app/components/nested.gjs b/frontend/discourse/app/components/nested.gjsindex d3f26687953..a5cdd0b7962 100644--- a/frontend/discourse/app/components/nested.gjs+++ b/frontend/discourse/app/components/nested.gjs@@ -808,8 +808,10 @@ export default class Nested extends Component {@replyToPost={{@replyToPost}}@changeNotice={{@changeNotice}}@changePostOwner={{@changePostOwner}}+ @deletePost={{@deletePost}}@grantBadge={{@grantBadge}}@lockPost={{@lockPost}}+ @recoverPost={{@recoverPost}}@unlockPost={{@unlockPost}}@permanentlyDeletePost={{@permanentlyDeletePost}}@rebakePost={{@rebakePost}}diff --git a/frontend/discourse/app/components/nested/op.gjs b/frontend/discourse/app/components/nested/op.gjsindex d2e759c7c17..af7570d2337 100644--- a/frontend/discourse/app/components/nested/op.gjs+++ b/frontend/discourse/app/components/nested/op.gjs@@ -19,6 +19,7 @@ import nestedPostUrl from "discourse/lib/nested-post-url";import postActionFeedback from "discourse/lib/post-action-feedback";import { nativeShare } from "discourse/lib/pwa-utils";import { clipboardCopy } from "discourse/lib/utilities";+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";export default class NestedOp extends Component {@service capabilities;@@ -117,8 +118,12 @@ export default class NestedOp extends Component {{{#let (lazyHash post=@post nestedReplyView=true) as |postOutletArgs|}}<PluginOutlet @name="post-article" @outletArgs={{postOutletArgs}}><article- class="nested-view__op-article boxed- {{if this.selected 'selected'}}"+ class={{dConcatClass+ "nested-view__op-article"+ "boxed"+ (if this.selected "selected")+ (if @post.deleted "is-deleted deleted")+ }}data-post-id={{@post.id}}data-post-number={{@post.post_number}}{{@registerPost @post}}@@ -163,7 +168,9 @@ export default class NestedOp extends Component {@canCreatePost={{this.canCreatePost}}@copyLink={{this.copyLink}}@replyToPost={{@replyToPost}}+ @deletePost={{fn @deletePost @post}}@editPost={{fn @editPost @post}}+ @recoverPost={{fn @recoverPost @post}}@changeNotice={{fn @changeNotice @post}}@changePostOwner={{fn @changePostOwner @post}}@grantBadge={{fn @grantBadge @post}}diff --git a/frontend/discourse/app/controllers/nested.js b/frontend/discourse/app/controllers/nested.jsindex 1931f887a8c..613bd9e0f69 100644--- a/frontend/discourse/app/controllers/nested.js+++ b/frontend/discourse/app/controllers/nested.js@@ -470,7 +470,11 @@ export default class NestedController extends Controller {}@action- deletePost(post) {+ deletePost(post, opts) {+ if (post.post_number === 1) {+ return this.#topicController.deletePost(post, opts);+ }+if (!post.can_delete) {return;}diff --git a/frontend/discourse/tests/integration/components/nested/op-test.gjs b/frontend/discourse/tests/integration/components/nested/op-test.gjsindex f6cac8e7f06..3c820bd7066 100644--- a/frontend/discourse/tests/integration/components/nested/op-test.gjs+++ b/frontend/discourse/tests/integration/components/nested/op-test.gjs@@ -18,6 +18,8 @@ function renderComponent(context) {@editPost={{noop}}@showHistory={{noop}}@replyToPost={{noop}}+ @deletePost={{context.deletePost}}+ @recoverPost={{context.recoverPost}}@changeNotice={{noop}}@changePostOwner={{noop}}@grantBadge={{noop}}@@ -45,6 +47,10 @@ module("Integration | Component | Nested | Op", function (hooks) {setupRenderingTest(hooks);hooks.beforeEach(function () {+ this.siteSettings.post_menu =+ "read|like|copyLink|share|flag|edit|bookmark|delete|admin|reply";+ this.siteSettings.post_menu_hidden_items = "";+this.store = getOwner(this).lookup("service:store");this.topic = this.store.createRecord("topic", {id: 1,@@ -58,6 +64,8 @@ module("Integration | Component | Nested | Op", function (hooks) {});this.multiSelect = false;this.showPostMenu = false;+ this.deletePost = noop;+ this.recoverPost = noop;this.togglePostSelection = noop;this.selectReplies = noop;this.selectBelow = noop;@@ -86,6 +94,55 @@ module("Integration | Component | Nested | Op", function (hooks) {.doesNotExist("nested OP menu suppresses the flat replies button");});+ test("renders an enabled delete-topic button for the OP", async function (assert) {+ this.showPostMenu = true;+ this.topic.details = { can_delete: true };+ this.deletePost = (post) => {+ assert.strictEqual(post, this.post, "passes the OP to the delete action");+ assert.step("delete action");+ };++ await renderComponent(this);++ assert+ .dom(".nested-view__op-menu .post-action-menu__delete")+ .isNotDisabled("the OP delete-topic button is actionable");++ await click(".nested-view__op-menu .post-action-menu__delete");++ assert.verifySteps(["delete action"], "invokes the delete action");+ });++ test("renders a deleted OP with an enabled recover-topic button", async function (assert) {+ this.showPostMenu = true;+ this.topic.setProperties({+ deleted_at: "2026-01-01T00:00:00.000Z",+ details: { can_recover: true },+ });+ this.recoverPost = (post) => {+ assert.strictEqual(+ post,+ this.post,+ "passes the OP to the recover action"+ );+ assert.step("recover action");+ };++ await renderComponent(this);++ assert+ .dom(".nested-view__op-article")+ .hasClass("is-deleted", "marks the deleted OP for nested view styling")+ .hasClass("deleted", "reuses the flat deleted post style hooks");+ assert+ .dom(".nested-view__op-menu .post-action-menu__recover")+ .isNotDisabled("the OP recover-topic button is actionable");++ await click(".nested-view__op-menu .post-action-menu__recover");++ assert.verifySteps(["recover action"], "invokes the recover action");+ });+test("renders multi-select controls for the OP", async function (assert) {let selectedPost;this.multiSelect = true;diff --git a/frontend/discourse/tests/unit/controllers/nested-test.js b/frontend/discourse/tests/unit/controllers/nested-test.jsindex ac8bf622357..814251f6ed1 100644--- a/frontend/discourse/tests/unit/controllers/nested-test.js+++ b/frontend/discourse/tests/unit/controllers/nested-test.js@@ -234,6 +234,27 @@ module("Unit | Controller | nested", function (hooks) {);});+ test("deletePost delegates first post deletion to the topic controller", function (assert) {+ const topic = buildTopic(this.store, 724);+ const op = buildPost(this.store, topic, 1001, 1);+ const topicController = this.owner.lookup("controller:topic");+ const opts = { force_destroy: true };+ let destroyArgs;++ topic.destroy = (deletedBy, passedOpts) => {+ destroyArgs = { deletedBy, passedOpts };+ };+ topicController.set("model", topic);++ this.controller.deletePost(op, opts);++ assert.deepEqual(+ destroyArgs,+ { deletedBy: this.currentUser, passedOpts: opts },+ "uses the topic delete path for the OP"+ );+ });+test("context view still dispatches live child replies", async function (assert) {const topic = buildTopic(this.store, 724);const childPostId = 2001;