Commit b9305369 authored by Douwe Maan's avatar Douwe Maan Committed by Robert Speicher

Fix transferring of project to another group using the API.

parent f94587ec
......@@ -48,6 +48,7 @@ v 7.12.2
- Correctly show anonymous authorized applications under Profile > Applications.
- Faster automerge check and merge itself when source and target branches are in same repository
- Audit log for user authentication
- Fix transferring of project to another group using the API.
v 7.12.1
- Fix error when deleting a user who has projects (Stan Hu)
......
......@@ -23,7 +23,8 @@ class Admin::ProjectsController < Admin::ApplicationController
end
def transfer
::Projects::TransferService.new(@project, current_user, params.dup).execute
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(@project, current_user, params.dup).execute(namespace)
@project.reload
redirect_to admin_namespace_project_path(@project.namespace, @project)
......
......@@ -52,10 +52,11 @@ class ProjectsController < ApplicationController
end
def transfer
transfer_params = params.permit(:new_namespace_id)
::Projects::TransferService.new(project, current_user, transfer_params).execute
if @project.errors[:namespace_id].present?
flash[:alert] = @project.errors[:namespace_id].first
namespace = Namespace.find_by(id: params[:new_namespace_id])
::Projects::TransferService.new(project, current_user).execute(namespace)
if @project.errors[:new_namespace].present?
flash[:alert] = @project.errors[:new_namespace].first
end
end
......
......@@ -11,19 +11,16 @@ module Projects
include Gitlab::ShellAdapter
class TransferError < StandardError; end
def execute
namespace_id = params[:new_namespace_id]
namespace = Namespace.find_by(id: namespace_id)
if allowed_transfer?(current_user, project, namespace)
transfer(project, namespace)
def execute(new_namespace)
if allowed_transfer?(current_user, project, new_namespace)
transfer(project, new_namespace)
else
project.errors.add(:namespace, 'is invalid')
project.errors.add(:new_namespace, 'is invalid')
false
end
rescue Projects::TransferService::TransferError => ex
project.reload
project.errors.add(:namespace_id, ex.message)
project.errors.add(:new_namespace, ex.message)
false
end
......
......@@ -74,9 +74,9 @@ module API
# POST /groups/:id/projects/:project_id
post ":id/projects/:project_id" do
authenticated_as_admin!
group = Group.find(params[:id])
group = Group.find_by(id: params[:id])
project = Project.find(params[:project_id])
result = ::Projects::TransferService.new(project, current_user, namespace_id: group.id).execute
result = ::Projects::TransferService.new(project, current_user).execute(group)
if result
present group
......
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