diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb index 7f0cc0a68a7..758b8dcd75a 100644 --- a/lib/discourse_tagging.rb +++ b/lib/discourse_tagging.rb @@ -40,7 +40,7 @@ module DiscourseTagging selected_tags: tag_names ).to_a - if tags.size < tag_names.size && (category.nil? || category.tags.count == 0) + if tags.size < tag_names.size && (category.nil? || (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/integration/category_tag_spec.rb b/spec/integration/category_tag_spec.rb index 2e0abf30b0c..86ff857cb34 100644 --- a/spec/integration/category_tag_spec.rb +++ b/spec/integration/category_tag_spec.rb @@ -100,6 +100,13 @@ describe "category tag restrictions" do expect(filter_allowed_tags(for_input: true)).to contain_exactly(tag3) expect(filter_allowed_tags(for_input: true, category: other_category)).to contain_exactly(tag3) end + + it "enforces restrictions when creating a topic" do + category.allowed_tag_groups = [tag_group1.name] + category.reload + post = create_post(category: category, tags: [tag1.name, "newtag"]) + expect(post.topic.tags.map(&:name)).to eq([tag1.name]) + end end context "tag groups with parent tag" do