A platform for community discussion. Free, open, simple.
FIX: Keep existent tags when editing tag topics (#15050)
Dan Ungureanu948a1523ea9f
diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rbindex 96dd3274a44..16e240ade53 100644--- a/lib/discourse_tagging.rb+++ b/lib/discourse_tagging.rb@@ -77,6 +77,9 @@ module DiscourseTaggingonly_tag_names: tag_names)+ # keep existent tags that current user cannot use+ tags += Tag.where(name: old_tag_names & tag_names)+tags = Tag.where(id: tags.map(&:id)).all.to_a if tags.size > 0if tags.size < tag_names.size && (category.nil? || category.allow_global_tags || (category.tags.count == 0 && category.tag_groups.count == 0))diff --git a/spec/components/discourse_tagging_spec.rb b/spec/components/discourse_tagging_spec.rbindex 815e399d263..5ef7c3e7eec 100644--- a/spec/components/discourse_tagging_spec.rb+++ b/spec/components/discourse_tagging_spec.rb@@ -383,6 +383,18 @@ describe DiscourseTagging doexpect(topic.tags.pluck(:name)).to be_blankend+ it 'can remove tags and keep existent ones' do+ tag1 = Fabricate(:tag)+ tag2 = Fabricate(:tag)+ topic = Fabricate(:topic, tags: [tag1, tag2])+ Fabricate(:category, allowed_tags: [tag1.name])++ result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag1.name])++ expect(result).to eq(true)+ expect(topic.reload.tags.pluck(:name)).to eq([tag1.name])+ end+context 'respects category minimum_required_tags setting' dofab!(:category) { Fabricate(:category, minimum_required_tags: 2) }fab!(:topic) { Fabricate(:topic, category: category) }