From ec9e937000263a180bcbc42001ac8a48a5b37923 Mon Sep 17 00:00:00 2001 From: Jonas Date: Thu, 20 Feb 2025 13:53:37 -0500 Subject: [PATCH 1/7] feat: enabled permissions in privileges/posts.js so that topic owners can delete posts in their topic. modified socket.io/posts/tools.js to not display admin positions along with topic owner position --- src/privileges/posts.js | 3 ++- src/socket.io/posts/tools.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/privileges/posts.js b/src/privileges/posts.js index fbd6858..e002814 100644 --- a/src/privileges/posts.js +++ b/src/privileges/posts.js @@ -168,6 +168,7 @@ privsPosts.canDelete = async function (pid, uid) { isMod: posts.isModerator([pid], uid), isLocked: topics.isLocked(postData.tid), isOwner: posts.isOwner(pid, uid), + isTopicOwner: topics.isOwner(postData.tid, uid), 'posts:delete': privsPosts.can('posts:delete', pid, uid), }); results.isMod = results.isMod[0]; @@ -184,7 +185,7 @@ privsPosts.canDelete = async function (pid, uid) { return { flag: false, message: `[[error:post-delete-duration-expired, ${meta.config.postDeleteDuration}]]` }; } const { deleterUid } = postData; - const flag = results['posts:delete'] && ((results.isOwner && (deleterUid === 0 || deleterUid === postData.uid)) || results.isMod); + const flag = results['posts:delete'] && ((results.isOwner && (deleterUid === 0 || deleterUid === postData.uid)) || results.isMod || results.isTopicOwner); return { flag: flag, message: '[[error:no-privileges]]' }; }; diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js index 5e195ac..1455a12 100644 --- a/src/socket.io/posts/tools.js +++ b/src/socket.io/posts/tools.js @@ -46,7 +46,7 @@ module.exports = function (SocketPosts) { postData.display_purge_tools = results.canPurge; postData.display_flag_tools = socket.uid && results.canFlag.flag; postData.display_topic_owner_tools = socket.uid === topicsData.uid; - postData.display_moderator_tools = postData.display_edit_tools || postData.display_delete_tools; + postData.display_moderator_tools = results.isAdmin || results.isModerator && (postData.display_edit_tools || postData.display_delete_tools); postData.display_move_tools = results.isAdmin || results.isModerator; postData.display_change_owner_tools = results.isAdmin || results.isModerator; postData.display_ip_ban = (results.isAdmin || results.isGlobalMod) && !postData.selfPost; From ce1c3ecb868b71631b8eca6f3040a030d53db613 Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 21 Feb 2025 14:21:17 -0500 Subject: [PATCH 2/7] fix: updated code format to pass the lint --- src/socket.io/posts/tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js index 1455a12..408f481 100644 --- a/src/socket.io/posts/tools.js +++ b/src/socket.io/posts/tools.js @@ -46,7 +46,7 @@ module.exports = function (SocketPosts) { postData.display_purge_tools = results.canPurge; postData.display_flag_tools = socket.uid && results.canFlag.flag; postData.display_topic_owner_tools = socket.uid === topicsData.uid; - postData.display_moderator_tools = results.isAdmin || results.isModerator && (postData.display_edit_tools || postData.display_delete_tools); + postData.display_moderator_tools = results.isAdmin || results.isModerator; postData.display_move_tools = results.isAdmin || results.isModerator; postData.display_change_owner_tools = results.isAdmin || results.isModerator; postData.display_ip_ban = (results.isAdmin || results.isGlobalMod) && !postData.selfPost; From e4a691867858f4d105ff86658a0e1dc3901e0fdb Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 24 Feb 2025 14:52:26 -0500 Subject: [PATCH 3/7] testing a bug where front end changes won't appear --- .../partials/topic/post-menu-list.tpl | 4 ++-- nodebb-theme-harmony/templates/topic.tpl | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl b/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl index 6599da7..e14d906 100644 --- a/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl +++ b/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl @@ -64,11 +64,11 @@ {{{ if posts.display_topic_owner_tools }}} {{{ if !posts.selfPost}}} -
  • +{{*
  • [[topic:delete]] -
  • + *}} {{{end}}} {{{end}}} diff --git a/nodebb-theme-harmony/templates/topic.tpl b/nodebb-theme-harmony/templates/topic.tpl index 62557e8..a811490 100644 --- a/nodebb-theme-harmony/templates/topic.tpl +++ b/nodebb-theme-harmony/templates/topic.tpl @@ -69,6 +69,7 @@
      {{{ each posts }}} + {{{ if posts.endorsed == "true"}}}
    • > @@ -82,6 +83,23 @@ {{{ each ./events}}}{{{ end }}} {{{ end }}} {{{ end }}} + {{{ end }}} + {{{ each posts }}} + {{{ if posts.endorsed != "true"}}} +
    • > + + + {{{ if ./editedISO }}} + + {{{ end }}} + + +
    • + {{{ if (config.topicPostSort != "most_votes") }}} + {{{ each ./events}}}{{{ end }}} + {{{ end }}} + {{{ end }}} + {{{ end }}}
    {{{ if browsingUsers }}}
    From 74647f2ae014adbc9464200e20d8202077f6d555 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 24 Feb 2025 23:28:01 -0500 Subject: [PATCH 4/7] uncommented the code lines aftering testing showed no update to the front end --- .../templates/partials/topic/post-menu-list.tpl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl b/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl index e14d906..7fb32ed 100644 --- a/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl +++ b/nodebb-theme-harmony/templates/partials/topic/post-menu-list.tpl @@ -64,12 +64,17 @@ {{{ if posts.display_topic_owner_tools }}} {{{ if !posts.selfPost}}} -{{*
  • +
  • [[topic:delete]] -
  • *}} + {{{end}}} +
  • + + Endorse + +
  • {{{end}}} {{{ if !posts.deleted }}} From d7621990164dc29ee56cdec41213ff86100ccace Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 26 Feb 2025 11:44:14 -0500 Subject: [PATCH 5/7] added test cases for topic owner can delete posts under their topics --- test/posts.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/posts.js b/test/posts.js index 20403e2..8d3e1a4 100644 --- a/test/posts.js +++ b/test/posts.js @@ -1215,3 +1215,59 @@ describe('Posts\'', async () => { }); }); }); + +describe('Post deletion by topic owner', () => { + let topicOwnerUid; + let posterUid; + let cid; + let tid; + let mainPid; + let replyPid; + + before(async () => { + topicOwnerUid = await user.create({ username: 'topicowner' }); + posterUid = await user.create({ username: 'regularuser' }); + + ({ cid } = await categories.create({ + name: 'Test Category', + description: 'Test category for topic owner deletion tests', + })); + + const topicData = await topics.post({ + uid: topicOwnerUid, + cid: cid, + title: 'Test Topic for Owner Deletion Rights', + content: 'This is the main post of the topic', + }); + + tid = topicData.topicData.tid; + mainPid = topicData.postData.pid; + + const replyData = await topics.reply({ + uid: posterUid, + tid: tid, + content: 'This is a reply posted by another user', + }); + + replyPid = replyData.pid; + }); + + it('should allow topic owner to delete any post under their topic', async () => { + assert(await user.exists(topicOwnerUid), 'Topic owner user should exist'); + assert(await user.exists(posterUid), 'Poster user should exist'); + + const isOwner = await topics.isOwner(tid, topicOwnerUid); + assert.strictEqual(isOwner, true, 'User should be the topic owner'); + + const isPostOwner = await posts.isOwner(replyPid, topicOwnerUid); + assert.strictEqual(isPostOwner, false, 'Topic owner should not be the post owner'); + + await apiPosts.delete({ uid: topicOwnerUid }, { pid: replyPid, tid: tid }); + + const isDeleted = await posts.getPostField(replyPid, 'deleted'); + assert.strictEqual(isDeleted, 1, 'Post should be marked as deleted'); + + const postExists = await posts.exists(replyPid); + assert.strictEqual(postExists, true, 'Post should still exist in database after deletion'); + }); +}); \ No newline at end of file From 3a614f7528de75cbf61dcf74f5de7281c8848c66 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 26 Feb 2025 11:47:45 -0500 Subject: [PATCH 6/7] fix: lint require new line at end of file --- test/posts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/posts.js b/test/posts.js index 8d3e1a4..2e74b5c 100644 --- a/test/posts.js +++ b/test/posts.js @@ -1270,4 +1270,4 @@ describe('Post deletion by topic owner', () => { const postExists = await posts.exists(replyPid); assert.strictEqual(postExists, true, 'Post should still exist in database after deletion'); }); -}); \ No newline at end of file +}); From d84de525e7fb908a81a882a6afa5dc44cab5b175 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 26 Feb 2025 21:23:46 -0500 Subject: [PATCH 7/7] fix: attempt to resolve branch conflict with main --- nodebb-theme-harmony/templates/topic.tpl | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/nodebb-theme-harmony/templates/topic.tpl b/nodebb-theme-harmony/templates/topic.tpl index a811490..62557e8 100644 --- a/nodebb-theme-harmony/templates/topic.tpl +++ b/nodebb-theme-harmony/templates/topic.tpl @@ -69,7 +69,6 @@
      {{{ each posts }}} - {{{ if posts.endorsed == "true"}}}
    • > @@ -83,23 +82,6 @@ {{{ each ./events}}}{{{ end }}} {{{ end }}} {{{ end }}} - {{{ end }}} - {{{ each posts }}} - {{{ if posts.endorsed != "true"}}} -
    • > - - - {{{ if ./editedISO }}} - - {{{ end }}} - - -
    • - {{{ if (config.topicPostSort != "most_votes") }}} - {{{ each ./events}}}{{{ end }}} - {{{ end }}} - {{{ end }}} - {{{ end }}}
    {{{ if browsingUsers }}}