FIX: Permit new tags when allow_global_tags true. ()

This commit is contained in:
Dan Ungureanu 2019-06-07 08:45:16 +03:00 committed by Sam
parent a0474a0774
commit 8bd815dab2
2 changed files with 17 additions and 1 deletions

@ -56,7 +56,7 @@ module DiscourseTagging
selected_tags: tag_names
).to_a
if tags.size < tag_names.size && (category.nil? || (category.tags.count == 0 && category.tag_groups.count == 0))
if tags.size < tag_names.size && (category.nil? || category.allow_global_tags || (category.tags.count == 0 && category.tag_groups.count == 0))
tag_names.each do |name|
unless Tag.where_name(name).exists?
tags << Tag.create(name: name)

@ -108,6 +108,22 @@ describe DiscourseTagging do
end
end
it 'respects category allow_global_tags setting' do
tag = Fabricate(:tag)
other_tag = Fabricate(:tag)
tag_group = Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [tag.name])
category = Fabricate(:category, allowed_tag_groups: [tag_group.name])
other_category = Fabricate(:category, allowed_tags: [other_tag.name])
topic = Fabricate(:topic, category: category)
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name, other_tag.name, 'hello'])
expect(topic.tags.pluck(:name)).to contain_exactly(tag.name)
category.update!(allow_global_tags: true)
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name, other_tag.name, 'hello'])
expect(topic.tags.pluck(:name)).to contain_exactly(tag.name, 'hello')
end
context 'respects category minimum_required_tags setting' do
fab!(:category) { Fabricate(:category, minimum_required_tags: 2) }
fab!(:topic) { Fabricate(:topic, category: category) }