diff options
3 files changed, 37 insertions, 2 deletions
diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index c2a0c5fa7f3..3746cfef702 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -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 diff --git a/changelogs/unreleased/41292-users-stuck-on-a-redirect-loop-after-transferring-project.yml b/changelogs/unreleased/41292-users-stuck-on-a-redirect-loop-after-transferring-project.yml new file mode 100644 index 00000000000..830c02510f2 --- /dev/null +++ b/changelogs/unreleased/41292-users-stuck-on-a-redirect-loop-after-transferring-project.yml @@ -0,0 +1,5 @@ +--- +title: Fix project transfer name validation issues causing a redirect loop +merge_request: 21408 +author: +type: fixed diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 1a85c52fc97..92c5ac7354a 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -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) |