From 6ca71e1319cca123bcffac6adc22a6ed7b5cc933 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 19 Mar 2018 11:41:58 -0400 Subject: [PATCH] FIX: when creating a topic in a category that only allows tags from a tag group, don't allow creation of new tags --- lib/discourse_tagging.rb | 2 +- spec/integration/category_tag_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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