diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-06-29 13:50:02 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-06-29 13:50:02 +0000 |
commit | f316cb9b9a5d0d13d54ef0bb94845310ff640aae (patch) | |
tree | 054ec2caa0f6db9fdd1058ce697aa5a499e61c38 | |
parent | cf55dd8b402dc400955039e5617cf701ef1c9930 (diff) | |
parent | c3de6a86734f8756de214cc87ac230820fa33acc (diff) | |
download | gitlab-ce-f316cb9b9a5d0d13d54ef0bb94845310ff640aae.tar.gz |
Merge branch 'transfer_project_api_endpoint' into 'master'
Add transfer project endpoint to the Projects API
Closes #45146
See merge request gitlab-org/gitlab-ce!20122
-rw-r--r-- | changelogs/unreleased/transfer_project_api_endpoint.yml | 5 | ||||
-rw-r--r-- | doc/api/projects.md | 10 | ||||
-rw-r--r-- | lib/api/projects.rb | 17 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 32 |
4 files changed, 64 insertions, 0 deletions
diff --git a/changelogs/unreleased/transfer_project_api_endpoint.yml b/changelogs/unreleased/transfer_project_api_endpoint.yml new file mode 100644 index 00000000000..60c704c62a0 --- /dev/null +++ b/changelogs/unreleased/transfer_project_api_endpoint.yml @@ -0,0 +1,5 @@ +--- +title: Add transfer project API endpoint +merge_request: 20122 +author: Aram Visser +type: added diff --git a/doc/api/projects.md b/doc/api/projects.md index 30a41839f28..b4599fdc97e 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -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. diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 3ef3680c5d9..b83da00502d 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -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 diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 99103039f77..abf9ad738bd 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -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 } |