Admin project controller should notify on transfer error
Summary
The Admin project controller doesn't present errors from the underlying transfer service if one is encountered.
Steps to reproduce
Create a personal repository with tagged docker images in the registry. Ensure there's a group available that you are not an "Owner" of. Via the admin project path, attempt to move the project to that available group See that it doesn't transfer
What is the current bug behavior?
The admin project controller does not flash a message when an error occurs within the transfer service
What is the expected correct behavior?
There should be some indication that there was an error during this process
Possible fixes
# rubocop: disable CodeReuse/ActiveRecord
def transfer
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
@project.reset
redirect_to admin_project_path(@project)
end
The transfer service does raise an error and then stashes it in project.errors
def execute(new_namespace)
...
transfer(project)
current_user.invalidate_personal_projects_count
true
rescue Projects::TransferService::TransferError => ex
project.reset
project.errors.add(:new_namespace, ex.message)
false
end
# rubocop: disable CodeReuse/ActiveRecord
def transfer(project)
@old_path = project.full_path
@old_group = project.group
@new_path = File.join(@new_namespace.try(:full_path) || '', project.path)
@old_namespace = project.namespace
if Project.where(namespace_id: @new_namespace.try(:id)).where('path = ? or name = ?', project.path, project.name).exists?
raise TransferError.new(s_("TransferProject|Project with same name or path in target namespace already exists"))
end
if project.has_container_registry_tags?
# We currently don't support renaming repository if it contains tags in container registry
raise TransferError.new(s_('TransferProject|Project cannot be transferred, because tags are present in its container registry'))
end
attempt_transfer_transaction
end
Something akin to the below may work (I have not tested it)
# rubocop: disable CodeReuse/ActiveRecord
def transfer
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
Edited by Vincent Fazio