FIX: when creating a topic in a category that only allows tags from a tag group, don't allow creation of new tags

This commit is contained in:
Neil Lalonde 2018-03-19 11:41:58 -04:00
parent 9de134caa0
commit 6ca71e1319
2 changed files with 8 additions and 1 deletions

View File

@ -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)

View File

@ -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