Commit c3de6a86 authored by Aram Visser's avatar Aram Visser

Add transfer project endpoint to the Projects API

parent 2452f1a7
---
title: Add transfer project API endpoint
merge_request: 20122
author: Aram Visser
type: added
......@@ -1390,6 +1390,16 @@ POST /projects/:id/housekeeping
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) |
### Transfer a project to a new namespace
```
PUT /projects/:id/transfer
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `namespace` | integer/string | yes | The ID or path of the namespace to transfer to project to |
## Branches
Read more in the [Branches](branches.md) documentation.
......
......@@ -459,6 +459,23 @@ module API
conflict!(error.message)
end
end
desc 'Transfer a project to a new namespace'
params do
requires :namespace, type: String, desc: 'The ID or path of the new namespace'
end
put ":id/transfer" do
authorize! :change_namespace, user_project
namespace = find_namespace!(params[:namespace])
result = ::Projects::TransferService.new(user_project, current_user).execute(namespace)
if result
present user_project, with: Entities::Project
else
render_api_error!("Failed to transfer project #{user_project.errors.messages}", 400)
end
end
end
end
end
......@@ -1990,6 +1990,38 @@ describe API::Projects do
end
end
describe 'PUT /projects/:id/transfer' do
context 'when authenticated as owner' do
let(:group) { create :group }
it 'transfers the project to the new namespace' do
group.add_owner(user)
put api("/projects/#{project.id}/transfer", user), namespace: group.id
expect(response).to have_gitlab_http_status(200)
end
it 'fails when transferring to a non owned namespace' do
put api("/projects/#{project.id}/transfer", user), namespace: group.id
expect(response).to have_gitlab_http_status(404)
end
it 'fails when transferring to an unknown namespace' do
put api("/projects/#{project.id}/transfer", user), namespace: 'unknown'
expect(response).to have_gitlab_http_status(404)
end
it 'fails on missing namespace' do
put api("/projects/#{project.id}/transfer", user)
expect(response).to have_gitlab_http_status(400)
end
end
end
it_behaves_like 'custom attributes endpoints', 'projects' do
let(:attributable) { project }
let(:other_attributable) { project2 }
......
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