Commit d2ebf05c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'feature/topics-delete' into 'master'

Add API endpoint to delete topics

See merge request gitlab-org/gitlab!80725
parents 98e43eed e22f57ff
...@@ -203,3 +203,28 @@ curl --request PUT \ ...@@ -203,3 +203,28 @@ curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \ --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1" "https://gitlab.example.com/api/v4/topics/1"
``` ```
## Delete a project topic
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80725) in GitLab 14.9.
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 ...@@ -77,5 +77,19 @@ module API
render_validation_error!(topic) render_validation_error!(topic)
end end
end end
desc 'Delete a topic' do
detail 'This feature was introduced in GitLab 14.9.'
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
end end
...@@ -255,4 +255,43 @@ RSpec.describe API::Topics do ...@@ -255,4 +255,43 @@ RSpec.describe API::Topics do
end end
end 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 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