mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 13:25:36 +08:00
FIX: Permit new tags when allow_global_tags true. (#7722)
This commit is contained in:
parent
a0474a0774
commit
8bd815dab2
@ -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) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user