Commit f8573b56 authored by Kassio Borges's avatar Kassio Borges

Fix group avatar API

Group avatar API endpoint was not working for subgroups like 'g1/g1.1'.
This commit fixes this issue by properly parsing the URL.

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63934
parent 974d2a9f
...@@ -6,13 +6,13 @@ module API ...@@ -6,13 +6,13 @@ module API
feature_category :subgroups feature_category :subgroups
resource :groups do params do
requires :id, type: String, desc: 'The ID of a group'
end
resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Download the group avatar' do desc 'Download the group avatar' do
detail 'This feature was introduced in GitLab 14.0' detail 'This feature was introduced in GitLab 14.0'
end end
params do
requires :id, type: String, desc: 'The group id'
end
get ':id/avatar' do get ':id/avatar' do
present_carrierwave_file!(user_group.avatar) present_carrierwave_file!(user_group.avatar)
end end
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe API::GroupAvatar do RSpec.describe API::GroupAvatar do
def avatar_path(group) def avatar_path(group)
"/groups/#{group.id}/avatar" "/groups/#{ERB::Util.url_encode(group.full_path)}/avatar"
end end
describe 'GET /groups/:id/avatar' do describe 'GET /groups/:id/avatar' do
...@@ -26,6 +26,16 @@ RSpec.describe API::GroupAvatar do ...@@ -26,6 +26,16 @@ RSpec.describe API::GroupAvatar do
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
context 'when the group is a subgroup' do
it 'returns :ok' do
group = create(:group, :nested, :public, :with_avatar, name: 'g1.1')
get api(avatar_path(group))
expect(response).to have_gitlab_http_status(:ok)
end
end
end end
context 'when the group is private' do context 'when the group is private' do
......
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