Resolve "Forking with namespace doesn't work (API)"

This commit is contained in:
Jan 2018-03-26 09:22:03 +00:00 committed by Douwe Maan
parent bf27275648
commit 54baf3a362
4 changed files with 22 additions and 10 deletions

View File

@ -0,0 +1,5 @@
---
title: Fix forking to subgroup via API when namespace is given by name
merge_request: 17815
author: Jan Beckmann
type: fixed

View File

@ -228,11 +228,7 @@ module API
namespace_id = fork_params[:namespace]
if namespace_id.present?
fork_params[:namespace] = if namespace_id =~ /^\d+$/
Namespace.find_by(id: namespace_id)
else
Namespace.find_by_path_or_name(namespace_id)
end
fork_params[:namespace] = find_namespace(namespace_id)
unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace])
not_found!('Target Namespace')

View File

@ -268,11 +268,7 @@ module API
namespace_id = fork_params[:namespace]
if namespace_id.present?
fork_params[:namespace] = if namespace_id =~ /^\d+$/
Namespace.find_by(id: namespace_id)
else
Namespace.find_by_path_or_name(namespace_id)
end
fork_params[:namespace] = find_namespace(namespace_id)
unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace])
not_found!('Target Namespace')

View File

@ -1718,6 +1718,12 @@ describe API::Projects do
group
end
let(:group3) do
group = create(:group, name: 'group3_name', parent: group2)
group.add_owner(user2)
group
end
before do
project.add_reporter(user2)
end
@ -1813,6 +1819,15 @@ describe API::Projects do
expect(json_response['namespace']['name']).to eq(group2.name)
end
it 'forks to owned subgroup' do
full_path = "#{group2.path}/#{group3.path}"
post api("/projects/#{project.id}/fork", user2), namespace: full_path
expect(response).to have_gitlab_http_status(201)
expect(json_response['namespace']['name']).to eq(group3.name)
expect(json_response['namespace']['full_path']).to eq(full_path)
end
it 'fails to fork to not owned group' do
post api("/projects/#{project.id}/fork", user2), namespace: group.name