Skip to content
Snippets Groups Projects
Commit e6cb3266 authored by Marcin Sedlak-Jakubowski's avatar Marcin Sedlak-Jakubowski
Browse files

Merge branch 'topics-api/update-remove-avatar' into 'master'

Topic API: allow to remove avatar by update

See merge request gitlab-org/gitlab!76860
parents d6e158c1 1d7e543c
No related branches found
No related tags found
1 merge request!76860Topic API: allow to remove avatar by update
Pipeline #431767527 passed with warnings
Pipeline: GitLab

#431772762

    ......@@ -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"
    ```
    ......@@ -69,6 +69,8 @@ class Topics < ::API::Base
    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
    ......
    ......@@ -5,6 +5,7 @@ module Validations
    module Types
    class WorkhorseFile
    def self.parse(value)
    return if value.blank?
    raise "#{value.class} is not an UploadedFile type" unless parsed?(value)
    value
    ......
    ......@@ -5,15 +5,15 @@
    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 @@
    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 @@
    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
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment