Skip to content

A platform for community discussion. Free, open, simple.

FIX: error when changing a topic's category and creating a tag

Neil Lalonde29e733832d7f
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 99ff5fb6258..238746ffb06 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -342,6 +342,8 @@ class TopicsController < ApplicationController
end
end
+ invalid_tags = Tag.where_name(invalid_tags).pluck(:name)
+
if !invalid_tags.empty?
if (invalid_tags & DiscourseTagging.hidden_tag_names).present?
return render_json_error(I18n.t('category.errors.disallowed_tags_generic'))
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index 947d244971b..c5ff3ecc7aa 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -1038,6 +1038,32 @@ RSpec.describe TopicsController do
expect(topic.tags.pluck(:id)).to contain_exactly(tag.id)
end
+ it "can create a tag" do
+ SiteSetting.min_trust_to_create_tag = 0
+ expect do
+ put "/t/#{topic.slug}/#{topic.id}.json", params: {
+ tags: ["newtag"]
+ }
+ end.to change { topic.reload.first_post.revisions.count }.by(1)
+
+ expect(response.status).to eq(200)
+ expect(topic.reload.tags.pluck(:name)).to contain_exactly("newtag")
+ end
+
+ it "can change the category and create a new tag" do
+ SiteSetting.min_trust_to_create_tag = 0
+ category = Fabricate(:category)
+ expect do
+ put "/t/#{topic.slug}/#{topic.id}.json", params: {
+ tags: ["newtag"],
+ category_id: category.id
+ }
+ end.to change { topic.reload.first_post.revisions.count }.by(1)
+
+ expect(response.status).to eq(200)
+ expect(topic.reload.tags.pluck(:name)).to contain_exactly("newtag")
+ end
+
it "can add a tag to wiki topic" do
SiteSetting.min_trust_to_edit_wiki_post = 2
topic.first_post.update!(wiki: true)