A platform for community discussion. Free, open, simple.
FIX: Permit new tags when allow_global_tags true. (#7722)
Dan Ungureanu8bd815dab20e
diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rbindex ab276c51589..9f824a259c5 100644--- a/lib/discourse_tagging.rb+++ b/lib/discourse_tagging.rb@@ -56,7 +56,7 @@ module DiscourseTaggingselected_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)diff --git a/spec/components/discourse_tagging_spec.rb b/spec/components/discourse_tagging_spec.rbindex 39ff18920d0..8ab8b613abe 100644--- a/spec/components/discourse_tagging_spec.rb+++ b/spec/components/discourse_tagging_spec.rb@@ -108,6 +108,22 @@ describe DiscourseTagging doendend+ 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' dofab!(:category) { Fabricate(:category, minimum_required_tags: 2) }fab!(:topic) { Fabricate(:topic, category: category) }