From de2669a2c64c99838e33f423d9a5ee9eaba8e9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 24 Apr 2023 15:39:00 -0400 Subject: [PATCH] fix: only remove deleted tag, closes #11515 --- src/topics/tags.js | 11 ++++++++--- test/topics.js | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/topics/tags.js b/src/topics/tags.js index 314b5cfd84..3b17027672 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -232,10 +232,15 @@ module.exports = function (Topics) { if (!tids.length) { return; } + let topicsTags = await Topics.getTopicsTags(tids); + topicsTags = topicsTags.map( + topicTags => topicTags.filter(topicTag => topicTag && topicTag !== tag) + ); - await db.deleteObjectFields( - tids.map(tid => `topic:${tid}`), - ['tags'], + await db.setObjectBulk( + tids.map((tid, index) => ([ + `topic:${tid}`, { tags: topicsTags[index].join(',') }, + ])) ); }); } diff --git a/test/topics.js b/test/topics.js index 44587639bc..f27ed80ad4 100644 --- a/test/topics.js +++ b/test/topics.js @@ -1932,6 +1932,14 @@ describe('Topic\'s', () => { }); }); + it('should only delete one tag from topic', async () => { + const result1 = await topics.post({ uid: adminUid, tags: ['deleteme1', 'deleteme2', 'deleteme3'], title: 'topic tagged with plugins', content: 'topic 1 content', cid: topic.categoryId }); + await topics.deleteTag('deleteme2'); + const topicData = await topics.getTopicData(result1.topicData.tid); + const tags = topicData.tags.map(t => t.value); + assert.deepStrictEqual(tags, ['deleteme1', 'deleteme3']); + }); + it('should delete tag', (done) => { topics.deleteTag('javascript', (err) => { assert.ifError(err);