mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
FIX: Provide an error message if no valid tags were selected
This commit is contained in:
parent
fd12c414e7
commit
a727968112
@ -4231,6 +4231,9 @@ en:
|
||||
other: "You must select at least %{count} tags."
|
||||
upload_row_too_long: "The CSV file should have one tag per line. Optionally the tag can be followed by a comma, then the tag group name."
|
||||
forbidden:
|
||||
invalid:
|
||||
one: "The tag you selected cannot be used"
|
||||
other: "None of the tags you selected can be used"
|
||||
in_this_category: '"%{tag_name}" cannot be used in this category'
|
||||
restricted_to:
|
||||
one: '"%{tag_name}" is restricted to the "%{category_names}" category'
|
||||
|
@ -83,7 +83,11 @@ module DiscourseTagging
|
||||
return false
|
||||
end
|
||||
|
||||
return false if tags.size == 0
|
||||
if tags.size == 0
|
||||
topic.errors.add(:base, I18n.t("tags.forbidden.invalid", count: new_tag_names.size))
|
||||
return false
|
||||
end
|
||||
|
||||
topic.tags = tags
|
||||
else
|
||||
# validate minimum required tags for a category
|
||||
|
@ -966,6 +966,23 @@ describe PostsController do
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it 'can not create a post with a tag that is restricted' do
|
||||
SiteSetting.tagging_enabled = true
|
||||
tag = Fabricate(:tag)
|
||||
category.allowed_tags = [tag.name]
|
||||
category.save!
|
||||
|
||||
post "/posts.json", params: {
|
||||
raw: 'this is the test content',
|
||||
title: 'this is the test title for the topic',
|
||||
tags: [tag.name],
|
||||
}
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
json = JSON.parse(response.body)
|
||||
expect(json['errors']).to be_present
|
||||
end
|
||||
|
||||
it 'creates the post' do
|
||||
post "/posts.json", params: {
|
||||
raw: 'this is the test content',
|
||||
|
Loading…
Reference in New Issue
Block a user