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
1d7e543c
Commit
1d7e543c
authored
Dec 17, 2021
by
Jonas Wälter
Committed by
Marcin Sedlak-Jakubowski
Dec 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Topic API: allow to remove avatar by update
parent
a4cb0770
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
3 deletions
+55
-3
doc/api/topics.md
doc/api/topics.md
+15
-0
lib/api/topics.rb
lib/api/topics.rb
+2
-0
lib/api/validations/types/workhorse_file.rb
lib/api/validations/types/workhorse_file.rb
+1
-0
spec/requests/api/topics_spec.rb
spec/requests/api/topics_spec.rb
+37
-3
No files found.
doc/api/topics.md
View file @
1d7e543c
...
...
@@ -188,3 +188,18 @@ curl --request PUT \
"https://gitlab.example.com/api/v4/topics/1"
\
--form
"avatar=@/tmp/example.png"
```
### Remove a topic avatar
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/348148) in GitLab 14.6.
To remove a topic avatar, use a blank value for the
`avatar`
attribute.
Example request:
```
shell
curl
--request
PUT
\
--data
"avatar="
\
--header
"PRIVATE-TOKEN: <your_access_token>"
\
"https://gitlab.example.com/api/v4/topics/1"
```
lib/api/topics.rb
View file @
1d7e543c
...
...
@@ -69,6 +69,8 @@ module API
topic
=
::
Projects
::
Topic
.
find
(
params
[
:id
])
topic
.
remove_avatar!
if
params
.
key?
(
:avatar
)
&&
params
[
:avatar
].
nil?
if
topic
.
update
(
declared_params
(
include_missing:
false
))
present
topic
,
with:
Entities
::
Projects
::
Topic
else
...
...
lib/api/validations/types/workhorse_file.rb
View file @
1d7e543c
...
...
@@ -5,6 +5,7 @@ module API
module
Types
class
WorkhorseFile
def
self
.
parse
(
value
)
return
if
value
.
blank?
raise
"
#{
value
.
class
}
is not an UploadedFile type"
unless
parsed?
(
value
)
value
...
...
spec/requests/api/topics_spec.rb
View file @
1d7e543c
...
...
@@ -5,15 +5,15 @@ require 'spec_helper'
RSpec
.
describe
API
::
Topics
do
include
WorkhorseHelpers
let_it_be
(
:topic_1
)
{
create
(
:topic
,
name:
'Git'
,
total_projects_count:
1
)
}
let_it_be
(
:file
)
{
fixture_file_upload
(
'spec/fixtures/dk.png'
)
}
let_it_be
(
:topic_1
)
{
create
(
:topic
,
name:
'Git'
,
total_projects_count:
1
,
avatar:
file
)
}
let_it_be
(
:topic_2
)
{
create
(
:topic
,
name:
'GitLab'
,
total_projects_count:
2
)
}
let_it_be
(
:topic_3
)
{
create
(
:topic
,
name:
'other-topic'
,
total_projects_count:
3
)
}
let_it_be
(
:admin
)
{
create
(
:user
,
:admin
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:file
)
{
fixture_file_upload
(
'spec/fixtures/dk.png'
)
}
describe
'GET /topics'
,
:aggregate_failures
do
it
'returns topics ordered by total_projects_count'
do
get
api
(
'/topics'
)
...
...
@@ -184,6 +184,14 @@ RSpec.describe API::Topics do
expect
(
json_response
[
'avatar_url'
]).
to
end_with
(
'dk.png'
)
end
it
'keeps avatar when updating other fields'
do
put
api
(
"/topics/
#{
topic_1
.
id
}
"
,
admin
),
params:
{
name:
'my-topic'
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'name'
]).
to
eq
(
'my-topic'
)
expect
(
topic_1
.
reload
.
avatar_url
).
not_to
be_nil
end
it
'returns 404 for non existing id'
do
put
api
(
"/topics/
#{
non_existing_record_id
}
"
,
admin
),
params:
{
name:
'my-topic'
}
...
...
@@ -196,6 +204,32 @@ RSpec.describe API::Topics do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
]).
to
eql
(
'id is invalid'
)
end
context
'with blank avatar'
do
it
'removes avatar'
do
put
api
(
"/topics/
#{
topic_1
.
id
}
"
,
admin
),
params:
{
avatar:
''
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'avatar_url'
]).
to
be_nil
expect
(
topic_3
.
reload
.
avatar_url
).
to
be_nil
end
it
'removes avatar besides other changes'
do
put
api
(
"/topics/
#{
topic_1
.
id
}
"
,
admin
),
params:
{
name:
'new-topic-name'
,
avatar:
''
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'name'
]).
to
eq
(
'new-topic-name'
)
expect
(
json_response
[
'avatar_url'
]).
to
be_nil
expect
(
topic_1
.
reload
.
avatar_url
).
to
be_nil
end
it
'does not remove avatar in case of other errors'
do
put
api
(
"/topics/
#{
topic_1
.
id
}
"
,
admin
),
params:
{
name:
topic_2
.
name
,
avatar:
''
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
topic_1
.
reload
.
avatar_url
).
not_to
be_nil
end
end
end
context
'as normal user'
do
...
...
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