From 8bd815dab20e460598941a73cf865d133a608abd Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Fri, 7 Jun 2019 08:45:16 +0300 Subject: [PATCH] FIX: Permit new tags when allow_global_tags true. (#7722) --- lib/discourse_tagging.rb | 2 +- spec/components/discourse_tagging_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb index ab276c51589..9f824a259c5 100644 --- a/lib/discourse_tagging.rb +++ b/lib/discourse_tagging.rb @@ -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) diff --git a/spec/components/discourse_tagging_spec.rb b/spec/components/discourse_tagging_spec.rb index 39ff18920d0..8ab8b613abe 100644 --- a/spec/components/discourse_tagging_spec.rb +++ b/spec/components/discourse_tagging_spec.rb @@ -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) }