Commit 54baf3a3 authored by Jan's avatar Jan Committed by Douwe Maan

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

parent bf272756
---
title: Fix forking to subgroup via API when namespace is given by name
merge_request: 17815
author: Jan Beckmann
type: fixed
...@@ -228,11 +228,7 @@ module API ...@@ -228,11 +228,7 @@ module API
namespace_id = fork_params[:namespace] namespace_id = fork_params[:namespace]
if namespace_id.present? if namespace_id.present?
fork_params[:namespace] = if namespace_id =~ /^\d+$/ fork_params[:namespace] = find_namespace(namespace_id)
Namespace.find_by(id: namespace_id)
else
Namespace.find_by_path_or_name(namespace_id)
end
unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace]) unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace])
not_found!('Target Namespace') not_found!('Target Namespace')
......
...@@ -268,11 +268,7 @@ module API ...@@ -268,11 +268,7 @@ module API
namespace_id = fork_params[:namespace] namespace_id = fork_params[:namespace]
if namespace_id.present? if namespace_id.present?
fork_params[:namespace] = if namespace_id =~ /^\d+$/ fork_params[:namespace] = find_namespace(namespace_id)
Namespace.find_by(id: namespace_id)
else
Namespace.find_by_path_or_name(namespace_id)
end
unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace]) unless fork_params[:namespace] && can?(current_user, :create_projects, fork_params[:namespace])
not_found!('Target Namespace') not_found!('Target Namespace')
......
...@@ -1718,6 +1718,12 @@ describe API::Projects do ...@@ -1718,6 +1718,12 @@ describe API::Projects do
group group
end end
let(:group3) do
group = create(:group, name: 'group3_name', parent: group2)
group.add_owner(user2)
group
end
before do before do
project.add_reporter(user2) project.add_reporter(user2)
end end
...@@ -1813,6 +1819,15 @@ describe API::Projects do ...@@ -1813,6 +1819,15 @@ describe API::Projects do
expect(json_response['namespace']['name']).to eq(group2.name) expect(json_response['namespace']['name']).to eq(group2.name)
end 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 it 'fails to fork to not owned group' do
post api("/projects/#{project.id}/fork", user2), namespace: group.name post api("/projects/#{project.id}/fork", user2), namespace: group.name
......
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