diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 99ff5fb6258b79..238746ffb067b6 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -342,6 +342,8 @@ def update 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 947d244971be5d..c5ff3ecc7aa0f2 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1038,6 +1038,32 @@ def topic_user_post_timings_count(user, topic) 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)