Commit 3549d7c1 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

PUT becomes POST on archiving endpoints

Also the specs have a minor improvement. Mainly the access right spec.
Changes are reflected in the docs
parent 2c5bcf2e
...@@ -4,6 +4,7 @@ v 8.7.0 (unreleased) ...@@ -4,6 +4,7 @@ v 8.7.0 (unreleased)
- Preserve time notes/comments have been updated at when moving issue - Preserve time notes/comments have been updated at when moving issue
- Make HTTP(s) label consistent on clone bar (Stan Hu) - Make HTTP(s) label consistent on clone bar (Stan Hu)
- Fix avatar stretching by providing a cropping feature - Fix avatar stretching by providing a cropping feature
- Add endpoints to archive or unarchive a project !3372
v 8.6.1 v 8.6.1
- Add option to reload the schema before restoring a database backup. !2807 - Add option to reload the schema before restoring a database backup. !2807
......
...@@ -493,14 +493,15 @@ Parameters: ...@@ -493,14 +493,15 @@ Parameters:
### Archive a project ### Archive a project
Archives a project if the user has the right access level to this project. This action is Archives the project if the user is either admin or the project owner of this project. This action is
idempotent, thus archiving an already archived project will not change the project. idempotent, thus archiving an already archived project will not change the project.
Status code 200 with the project as body is given when successful, in case the user doesn't Status code 201 with the project as body is given when successful, in case the user doesn't
have the proper access rights, code 404 is returned. have the proper access rights, code 403 is returned. Status 404 is returned if the project
doesn't exist, or is hidden to the user.
``` ```
PUT /projects/:id/archive POST /projects/:id/archive
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
...@@ -508,7 +509,7 @@ PUT /projects/:id/archive ...@@ -508,7 +509,7 @@ PUT /projects/:id/archive
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
```bash ```bash
curl -X PUT -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/archive" curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/archive"
``` ```
Example response: Example response:
...@@ -575,14 +576,15 @@ Example response: ...@@ -575,14 +576,15 @@ Example response:
### Unarchive a project ### Unarchive a project
Unarchives a project if the user has the right access level to this project. This action is Unarchives the project if the user is either admin or the project owner of this project. This action is
idempotent, thus unarchiving an non-archived project will not change the project. idempotent, thus unarchiving an non-archived project will not change the project.
Status code 200 with the project as body is given when successful, in case the user doesn't Status code 201 with the project as body is given when successful, in case the user doesn't
have the proper access rights, code 404 is returned. have the proper access rights, code 403 is returned. Status 404 is returned if the project
doesn't exist, or is hidden to the user.
``` ```
PUT /projects/:id/archive POST /projects/:id/archive
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
...@@ -590,7 +592,7 @@ PUT /projects/:id/archive ...@@ -590,7 +592,7 @@ PUT /projects/:id/archive
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
```bash ```bash
curl -X PUT -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/unarchive" curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/unarchive"
``` ```
Example response: Example response:
......
...@@ -250,12 +250,12 @@ module API ...@@ -250,12 +250,12 @@ module API
# id (required) - The ID of a project # id (required) - The ID of a project
# Example Request: # Example Request:
# PUT /projects/:id/archive # PUT /projects/:id/archive
put ':id/archive' do post ':id/archive' do
authorize!(:archive_project, user_project) authorize!(:archive_project, user_project)
user_project.archive! user_project.archive!
present @project, with: Entities::Project present user_project, with: Entities::Project
end end
# Unarchive project # Unarchive project
...@@ -264,12 +264,12 @@ module API ...@@ -264,12 +264,12 @@ module API
# id (required) - The ID of a project # id (required) - The ID of a project
# Example Request: # Example Request:
# PUT /projects/:id/unarchive # PUT /projects/:id/unarchive
put ':id/unarchive' do post ':id/unarchive' do
authorize!(:archive_project, user_project) authorize!(:archive_project, user_project)
user_project.unarchive! user_project.unarchive!
present @project, with: Entities::Project present user_project, with: Entities::Project
end end
# Remove project # Remove project
......
...@@ -948,20 +948,14 @@ describe API::API, api: true do ...@@ -948,20 +948,14 @@ describe API::API, api: true do
end end
end end
describe 'PUT /projects/:id/archive' do describe 'POST /projects/:id/archive' do
context 'on an unarchived project' do context 'on an unarchived project' do
it 'archives the project' do it 'archives the project' do
put api("/projects/#{project.id}/archive", user) post api("/projects/#{project.id}/archive", user)
expect(response.status).to eq(200) expect(response.status).to eq(201)
expect(json_response['archived']).to be_truthy expect(json_response['archived']).to be_truthy
end end
it 'rejects archivation on other users' do
put api("/projects/#{project.id}/archive", user3)
expect(response.status).to eq(404)
end
end end
context 'on an archived project' do context 'on an archived project' do
...@@ -970,34 +964,34 @@ describe API::API, api: true do ...@@ -970,34 +964,34 @@ describe API::API, api: true do
end end
it 'remains archived' do it 'remains archived' do
put api("/projects/#{project.id}/archive", user) post api("/projects/#{project.id}/archive", user)
expect(response.status).to eq(200) expect(response.status).to eq(201)
expect(json_response['archived']).to be_truthy expect(json_response['archived']).to be_truthy
end end
end
context 'user without archiving rights to the project' do
before do
project.team << [user3, :developer]
end
it 'rejects archivation on other users' do it 'rejects the action' do
put api("/projects/#{project.id}/archive", user3) post api("/projects/#{project.id}/archive", user3)
expect(response.status).to eq(404) expect(response.status).to eq(403)
end end
end end
end end
describe 'PUT /projects/:id/unarchive' do describe 'POST /projects/:id/unarchive' do
context 'on an unarchived project' do context 'on an unarchived project' do
it 'remains unarchived' do it 'remains unarchived' do
put api("/projects/#{project.id}/unarchive", user) post api("/projects/#{project.id}/unarchive", user)
expect(response.status).to eq(200) expect(response.status).to eq(201)
expect(json_response['archived']).to be_falsey expect(json_response['archived']).to be_falsey
end end
it 'rejects archivation on other users' do
put api("/projects/#{project.id}/unarchive", user3)
expect(response.status).to eq(404)
end
end end
context 'on an archived project' do context 'on an archived project' do
...@@ -1005,17 +999,23 @@ describe API::API, api: true do ...@@ -1005,17 +999,23 @@ describe API::API, api: true do
project.archive! project.archive!
end end
it 'remains archived' do it 'unarchives the project' do
put api("/projects/#{project.id}/unarchive", user) post api("/projects/#{project.id}/unarchive", user)
expect(response.status).to eq(200) expect(response.status).to eq(201)
expect(json_response['archived']).to be_falsey expect(json_response['archived']).to be_falsey
end end
end
it 'rejects archivation on other users' do context 'user without archiving rights to the project' do
put api("/projects/#{project.id}/archive", user3) before do
project.team << [user3, :developer]
end
expect(response.status).to eq(404) it 'rejects the action' do
post api("/projects/#{project.id}/unarchive", user3)
expect(response.status).to eq(403)
end end
end end
end end
......
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