Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8c777b84
Commit
8c777b84
authored
Feb 15, 2022
by
Timo Furrer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API endpoint to delete topics
Refs
https://gitlab.com/gitlab-org/gitlab/-/issues/350743
parent
0b624241
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
doc/api/topics.md
doc/api/topics.md
+23
-0
lib/api/topics.rb
lib/api/topics.rb
+14
-0
spec/requests/api/topics_spec.rb
spec/requests/api/topics_spec.rb
+39
-0
No files found.
doc/api/topics.md
View file @
8c777b84
...
...
@@ -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"
```
lib/api/topics.rb
View file @
8c777b84
...
...
@@ -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
spec/requests/api/topics_spec.rb
View file @
8c777b84
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment