mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 19:51:40 +08:00
FIX: Fail if none of our tags could be updated
For example, if a category has a tag restriction and the API tries to attempt to update it but cannot. See: https://meta.discourse.org/t/unallowed-tag-in-conversation-returns-200/122170
This commit is contained in:
parent
5494e17c71
commit
c2c169f5b7
@ -83,6 +83,7 @@ module DiscourseTagging
|
||||
return false
|
||||
end
|
||||
|
||||
return false if tags.size == 0
|
||||
topic.tags = tags
|
||||
else
|
||||
# validate minimum required tags for a category
|
||||
|
@ -116,14 +116,29 @@ describe DiscourseTagging do
|
||||
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'])
|
||||
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name, other_tag.name, 'hello'])
|
||||
expect(result).to eq(true)
|
||||
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'])
|
||||
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name, other_tag.name, 'hello'])
|
||||
expect(result).to eq(true)
|
||||
expect(topic.tags.pluck(:name)).to contain_exactly(tag.name, 'hello')
|
||||
end
|
||||
|
||||
it 'raises an error if no tags could be updated' 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)
|
||||
|
||||
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [other_tag.name])
|
||||
expect(result).to eq(false)
|
||||
expect(topic.tags.pluck(:name)).to be_blank
|
||||
end
|
||||
|
||||
context 'respects category minimum_required_tags setting' do
|
||||
fab!(:category) { Fabricate(:category, minimum_required_tags: 2) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user