Commit ffd11d27 authored by Imre Farkas's avatar Imre Farkas

Merge branch '208167-bigfix-unable-to-fork-project-to-the-same-namespace' into 'master'

Allow to fork to the same namespace with different name

Closes #208167

See merge request gitlab-org/gitlab!26062
parents 9af9cf32 bbf35765
...@@ -39,7 +39,7 @@ class Projects::ForksController < Projects::ApplicationController ...@@ -39,7 +39,7 @@ class Projects::ForksController < Projects::ApplicationController
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def new def new
@namespaces = fork_service.valid_fork_targets @namespaces = fork_service.valid_fork_targets - [project.namespace]
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -8,7 +8,7 @@ class ForkTargetsFinder ...@@ -8,7 +8,7 @@ class ForkTargetsFinder
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def execute def execute
::Namespace.where(id: user.manageable_namespaces).where.not(id: project.namespace).sort_by_type ::Namespace.where(id: user.manageable_namespaces).sort_by_type
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
title: Allow to fork to the same namespace and different path via API call
merge_request: 26062
author:
type: fixed
...@@ -28,8 +28,8 @@ describe ForkTargetsFinder do ...@@ -28,8 +28,8 @@ describe ForkTargetsFinder do
end end
describe '#execute' do describe '#execute' do
it 'returns all user manageable namespaces except project namespace' do it 'returns all user manageable namespaces' do
expect(finder.execute).to match_array([user.namespace, maintained_group, owned_group]) expect(finder.execute).to match_array([user.namespace, maintained_group, owned_group, project.namespace])
end end
end end
end end
...@@ -2935,6 +2935,26 @@ describe API::Projects do ...@@ -2935,6 +2935,26 @@ describe API::Projects do
expect(response).to have_gitlab_http_status(:conflict) expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']['name']).to eq(['has already been taken']) expect(json_response['message']['name']).to eq(['has already been taken'])
end end
it 'forks to the same namespace with alternative path and name' do
post api("/projects/#{project.id}/fork", user), params: { path: 'path_2', name: 'name_2' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response['name']).to eq('name_2')
expect(json_response['path']).to eq('path_2')
expect(json_response['owner']['id']).to eq(user.id)
expect(json_response['namespace']['id']).to eq(user.namespace.id)
expect(json_response['forked_from_project']['id']).to eq(project.id)
expect(json_response['import_status']).to eq('scheduled')
end
it 'fails to fork to the same namespace without alternative path and name' do
post api("/projects/#{project.id}/fork", user)
expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']['path']).to eq(['has already been taken'])
expect(json_response['message']['name']).to eq(['has already been taken'])
end
end end
context 'when unauthenticated' do context 'when unauthenticated' 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