Commit d6c4fcf4 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '30477-vfazio-alert-transfer-error' into 'master'

Alert on transfer error in admin project controller

See merge request gitlab-org/gitlab!50541
parents 2a031968 5dc31622
......@@ -57,6 +57,10 @@ class Admin::ProjectsController < Admin::ApplicationController
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
if @project.errors[:new_namespace].present?
flash[:alert] = @project.errors[:new_namespace].first
end
@project.reset
redirect_to admin_project_path(@project)
end
......
---
title: Flash transfer errors in the admin project controller
merge_request: 50541
author: Vincent Fazio
type: fixed
......@@ -77,4 +77,34 @@ RSpec.describe Admin::ProjectsController do
expect(response.body).to match(project.name)
end
end
describe 'PUT /projects/transfer/:id' do
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:new_namespace) { create(:namespace) }
it 'updates namespace' do
put :transfer, params: { namespace_id: project.namespace.path, new_namespace_id: new_namespace.id, id: project.path }
project.reload
expect(project.namespace).to eq(new_namespace)
expect(response).to have_gitlab_http_status(:redirect)
expect(response).to redirect_to(admin_project_path(project))
end
context 'when project transfer fails' do
it 'flashes error' do
old_namespace = project.namespace
put :transfer, params: { namespace_id: old_namespace.path, new_namespace_id: nil, id: project.path }
project.reload
expect(project.namespace).to eq(old_namespace)
expect(response).to have_gitlab_http_status(:redirect)
expect(response).to redirect_to(admin_project_path(project))
expect(flash[:alert]).to eq s_('TransferProject|Please select a new namespace for your project.')
end
end
end
end
......@@ -733,7 +733,7 @@ RSpec.describe ProjectsController do
describe '#transfer', :enable_admin_mode do
render_views
let_it_be(:project, reload: true) { create(:project, :repository) }
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:admin) { create(:admin) }
let_it_be(:new_namespace) { create(:namespace) }
......
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