[API] Creating a topic with a new tag without tag-creation permission fails silently

When using the API to create a topic that contains a new tag, if the user identified by api_username cannot create tags, the query creates the topic but silently fails to add the tag.

EDIT - Additional issue: when using the API to create a topic that contains a new tag, if the Discourse instance has the “tags” feature turned off, the query creates the topic but silently fails to add the tag.

4 Likes

hi can i work on this.

2 Likes

I support improving the API here to properly return an error vs silently dropping the tags. pr-welcome

6 Likes

hi sorry for being late can you please direct me how to proceed and where to find this issue. i tried creating topic but not able find any option to add tag in it .

1 Like

@aki, the API point to create a topic is documented here. To set tags, use the undocumented additional parameter tags, which is an array of strings.

1 Like

Thanks @jack2 what should be displayed in error message. topic should be allowed to create without tag in that case or not?

1 Like

I think topic creation should fail if tag(s) cannot be created.

Here is the response I get when trying to create a topic with an invalid title:

{ 
  statusCode: 422,
  data: {
    action: 'create_post',
    errors: [ 'Title has already been used' ] 
  }
}

So maybe in our case we should have this:

{ 
  statusCode: 422,
  data: {
    action: 'create_post',
    errors: [ 'Tag creation not allowed' ]
  }
}
2 Likes

Notice that the issue described in this thread also occurs when creating a tagged topic with the tag feature turned off. I will edit my first post to reflect that.

2 Likes

hi @jack2
i have solve this bug trying to push my code and getting permission denied error.

1 Like

Have you submitted a pull request for this?

4 Likes

hi @erlend_sh
i am trying to push my branch to github but i am getting permission denied error.

Hey Aki, you’ll need to fork the Discourse repo and push your branch to the fork. Check out this part of the guide:

6 Likes

If you need any more guidance with this @aki just let us know where you’re stuck. Git can be a bit confusing at first!

Luckily there’s lots of tutorials around. GitHub has a pretty good one, and there’s plenty of other ones (including interactive tutorials) just a search away.

4 Likes

I created a PR to improve the API here so that a 422 error is returned now when trying to tag a topic when you don’t have permission to do so.

https://github.com/discourse/discourse/pull/10400

5 Likes