mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Provide an error message if no valid tags were selected
This commit is contained in:
@@ -4231,6 +4231,9 @@ en:
|
|||||||
other: "You must select at least %{count} tags."
|
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."
|
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:
|
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'
|
in_this_category: '"%{tag_name}" cannot be used in this category'
|
||||||
restricted_to:
|
restricted_to:
|
||||||
one: '"%{tag_name}" is restricted to the "%{category_names}" category'
|
one: '"%{tag_name}" is restricted to the "%{category_names}" category'
|
||||||
|
|||||||
@@ -83,7 +83,11 @@ module DiscourseTagging
|
|||||||
return false
|
return false
|
||||||
end
|
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
|
topic.tags = tags
|
||||||
else
|
else
|
||||||
# validate minimum required tags for a category
|
# validate minimum required tags for a category
|
||||||
|
|||||||
@@ -966,6 +966,23 @@ describe PostsController do
|
|||||||
expect(response.status).to eq(403)
|
expect(response.status).to eq(403)
|
||||||
end
|
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
|
it 'creates the post' do
|
||||||
post "/posts.json", params: {
|
post "/posts.json", params: {
|
||||||
raw: 'this is the test content',
|
raw: 'this is the test content',
|
||||||
|
|||||||
Reference in New Issue
Block a user