Commit b8856d66 authored by Sean McGivern's avatar Sean McGivern

Merge branch '41292-users-stuck-on-a-redirect-loop-after-transferring-project' into 'master'

Resolve "Users stuck on a redirect loop after transferring project"

Closes #41292

See merge request gitlab-org/gitlab-ce!21408
parents f474f16f 14949ba6
......@@ -43,8 +43,8 @@ module Projects
@new_path = File.join(@new_namespace.try(:full_path) || '', project.path)
@old_namespace = project.namespace
if Project.where(path: project.path, namespace_id: @new_namespace.try(:id)).exists?
raise TransferError.new("Project with same path in target namespace already exists")
if Project.where(namespace_id: @new_namespace.try(:id)).where('path = ? or name = ?', project.path, project.name).exists?
raise TransferError.new("Project with same name or path in target namespace already exists")
end
if project.has_container_registry_tags?
......@@ -118,6 +118,7 @@ module Projects
def rollback_side_effects
rollback_folder_move
project.reload
update_namespace_and_visibility(@old_namespace)
write_repository_config(@old_path)
end
......
---
title: Fix project transfer name validation issues causing a redirect loop
merge_request: 21408
author:
type: fixed
......@@ -169,6 +169,35 @@ describe Projects::TransferService do
it { expect(project.errors[:new_namespace]).to include('Cannot move project') }
end
context 'target namespace containing the same project name' do
before do
group.add_owner(user)
project.update(name: 'new_name')
create(:project, name: 'new_name', group: group, path: 'other')
@result = transfer_project(project, user, group)
end
it { expect(@result).to eq false }
it { expect(project.namespace).to eq(user.namespace) }
it { expect(project.errors[:new_namespace]).to include('Project with same name or path in target namespace already exists') }
end
context 'target namespace containing the same project path' do
before do
group.add_owner(user)
create(:project, name: 'other-name', path: project.path, group: group)
@result = transfer_project(project, user, group)
end
it { expect(@result).to eq false }
it { expect(project.namespace).to eq(user.namespace) }
it { expect(project.errors[:new_namespace]).to include('Project with same name or path in target namespace already exists') }
end
def transfer_project(project, user, new_namespace)
service = Projects::TransferService.new(project, user)
......
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