Commit 8c777b84 authored by Timo Furrer's avatar Timo Furrer

Add API endpoint to delete topics

Refs https://gitlab.com/gitlab-org/gitlab/-/issues/350743
parent 0b624241
......@@ -203,3 +203,26 @@ curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1"
```
## Delete a project topic
You must be an administrator to delete a project.
When you delete a project topic, you also delete the topic assignment for projects.
```plaintext
DELETE /topics/:id
```
Supported attributes:
| Attribute | Type | Required | Description |
| ------------- | ------- | ---------------------- | ------------------- |
| `id` | integer | **{check-circle}** Yes | ID of project topic |
Example request:
```shell
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1"
```
......@@ -77,5 +77,19 @@ module API
render_validation_error!(topic)
end
end
desc 'Delete a topic' do
detail 'This feature was introduced in GitLab 14.8.'
end
params do
requires :id, type: Integer, desc: 'ID of project topic'
end
delete 'topics/:id' do
authenticated_as_admin!
topic = ::Projects::Topic.find(params[:id])
destroy_conditionally!(topic)
end
end
end
......@@ -248,4 +248,43 @@ RSpec.describe API::Topics do
end
end
end
describe 'DELETE /topics', :aggregate_failures do
context 'as administrator' do
it 'deletes a topic' do
delete api("/topics/#{topic_3.id}", admin), params: { name: 'my-topic' }
expect(response).to have_gitlab_http_status(:no_content)
end
it 'returns 404 for non existing id' do
delete api("/topics/#{non_existing_record_id}", admin), params: { name: 'my-topic' }
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns 400 for invalid `id` parameter' do
delete api('/topics/invalid', admin), params: { name: 'my-topic' }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eql('id is invalid')
end
end
context 'as normal user' do
it 'returns 403 Forbidden' do
delete api("/topics/#{topic_3.id}", user), params: { name: 'my-topic' }
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'as anonymous' do
it 'returns 401 Unauthorized' do
delete api("/topics/#{topic_3.id}"), params: { name: 'my-topic' }
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment