Skip to content

Commit

Permalink
fix: only remove deleted tag, closes #11515
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Apr 24, 2023
1 parent 21fb859 commit de2669a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/topics/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',') },
]))
);
});
}
Expand Down
8 changes: 8 additions & 0 deletions test/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit de2669a

Please sign in to comment.