Skip to content
Browse files

FIX: Return error if new topic category not found

If creating a topic via the api as an admin and the category you specify
cannot be found an error will now be returned instead of just creating
the topic with no category. This will prevent accidental public topic
creation originally intended for a private category.
  • Loading branch information
oblakeerickson committed May 8, 2019
1 parent a92c925 commit 9c606dd99a7ce227bde38527986b250d6e6c22dc
Showing with 17 additions and 0 deletions.
  1. +3 −0 lib/topic_creator.rb
  2. +14 −0 spec/requests/posts_controller_spec.rb
@@ -122,6 +122,9 @@ def setup_topic_params

@guardian.ensure_can_create!(Topic, category) unless (@opts[:skip_validations] || @opts[:archetype] == Archetype.private_message)

if @opts[:category] && category.nil?
raise Discourse::NotFound
topic_params[:category_id] = if category.present?

topic_params[:created_at] =[:created_at].to_s) if @opts[:created_at].present?
@@ -775,6 +775,20 @@
expect(response.status).to eq(403)

it 'will raise an error if specified category cannot be found' do
user = Fabricate(:admin)
master_key = ApiKey.create_master_key.key

post "/posts.json", params: {
api_username: user.username,
api_key: master_key,
title: 'this is a test title',
raw: 'this is test body',
category: 'invalid'
expect(response.status).to eq(404)

describe "when logged in" do

1 comment on commit 9c606dd

Please sign in to comment.
You can’t perform that action at this time.