Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
97888a2e
Commit
97888a2e
authored
Feb 20, 2019
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DELETE package API endpoint
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
85582cb3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
14 deletions
+133
-14
doc/api/packages.md
doc/api/packages.md
+27
-3
ee/changelogs/unreleased/9514-add-rest-endpoints-to-delete-packages.yml
...unreleased/9514-add-rest-endpoints-to-delete-packages.yml
+5
-0
ee/lib/api/helpers/packages_helpers.rb
ee/lib/api/helpers/packages_helpers.rb
+4
-0
ee/lib/api/packages.rb
ee/lib/api/packages.rb
+15
-0
ee/spec/fixtures/api/schemas/public_api/v4/packages/package.json
.../fixtures/api/schemas/public_api/v4/packages/package.json
+9
-0
ee/spec/fixtures/api/schemas/public_api/v4/packages/packages.json
...fixtures/api/schemas/public_api/v4/packages/packages.json
+2
-5
ee/spec/requests/api/packages_spec.rb
ee/spec/requests/api/packages_spec.rb
+71
-6
No files found.
doc/api/packages.md
View file @
97888a2e
...
@@ -15,7 +15,7 @@ GET /projects/:id/packages
...
@@ -15,7 +15,7 @@ GET /projects/:id/packages
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes |
The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user.
|
|
`id`
| integer/string | yes |
ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
|
```
bash
```
bash
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/:id/packages
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/:id/packages
...
@@ -54,8 +54,8 @@ GET /projects/:id/packages/:package_id/package_files
...
@@ -54,8 +54,8 @@ GET /projects/:id/packages/:package_id/package_files
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes |
The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user.
|
|
`id`
| integer/string | yes |
ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
|
|
`package_id`
| integer | yes |
The
ID of a package. |
|
`package_id`
| integer | yes | ID of a package. |
```
bash
```
bash
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/1/packages/4/package_files
curl
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/1/packages/4/package_files
...
@@ -96,3 +96,27 @@ Example response:
...
@@ -96,3 +96,27 @@ Example response:
```
```
By default, the
`GET`
request will return 20 results, since the API is
[
paginated
](
README.md#pagination
)
.
By default, the
`GET`
request will return 20 results, since the API is
[
paginated
](
README.md#pagination
)
.
## Delete a project package
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9623) in GitLab 11.9.
Deletes a project package.
```
DELETE /projects/:id/packages/:package_id
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
|
|
`package_id`
| integer | yes | ID of a package. |
```
bash
curl
--request
DELETE
--header
"PRIVATE-TOKEN: <your_access_token>"
https://gitlab.example.com/api/v4/projects/:id/packages/:package_id
```
Can return the following status codes:
-
`204 No Content`
, if the package was deleted successfully.
-
`404 Not Found`
, if the package was not found.
ee/changelogs/unreleased/9514-add-rest-endpoints-to-delete-packages.yml
0 → 100644
View file @
97888a2e
---
title
:
Add DELETE package API endpoint
merge_request
:
9623
author
:
type
:
added
ee/lib/api/helpers/packages_helpers.rb
View file @
97888a2e
...
@@ -19,6 +19,10 @@ module API
...
@@ -19,6 +19,10 @@ module API
def
authorize_create_package!
def
authorize_create_package!
authorize!
(
:create_package
,
user_project
)
authorize!
(
:create_package
,
user_project
)
end
end
def
authorize_destroy_package!
authorize!
(
:destroy_package
,
user_project
)
end
end
end
end
end
end
end
ee/lib/api/packages.rb
View file @
97888a2e
...
@@ -28,6 +28,21 @@ module API
...
@@ -28,6 +28,21 @@ module API
present
paginate
(
packages
),
with:
EE
::
API
::
Entities
::
Package
present
paginate
(
packages
),
with:
EE
::
API
::
Entities
::
Package
end
end
desc
'Remove a package'
do
detail
'This feature was introduced in GitLab 11.9'
end
params
do
requires
:package_id
,
type:
Integer
,
desc:
'The ID of a package'
end
delete
':id/packages/:package_id'
do
authorize_destroy_package!
package
=
::
Packages
::
PackageFinder
.
new
(
user_project
,
params
[
:package_id
]).
execute
destroy_conditionally!
(
package
)
end
end
end
end
end
end
end
ee/spec/fixtures/api/schemas/public_api/v4/packages/package.json
0 → 100644
View file @
97888a2e
{
"type"
:
"object"
,
"required"
:
[
"name"
,
"version"
,
"package_type"
],
"properties"
:
{
"name"
:
{
"type"
:
"string"
},
"version"
:
{
"type"
:
"string"
},
"package_type"
:
{
"type"
:
"string"
}
}
}
ee/spec/fixtures/api/schemas/public_api/v4/packages/packages.json
View file @
97888a2e
...
@@ -2,11 +2,8 @@
...
@@ -2,11 +2,8 @@
"type"
:
"array"
,
"type"
:
"array"
,
"items"
:
{
"items"
:
{
"type"
:
"object"
,
"type"
:
"object"
,
"required"
:
[
"name"
,
"version"
,
"packages_type"
],
"properties"
:
{
"properties"
:
{
"$ref"
:
"./package.json"
"name"
:
{
"type"
:
"string"
},
"version"
:
{
"type"
:
"string"
},
"packages_type"
:
{
"type"
:
"string"
}
}
}
}
}
}
}
ee/spec/requests/api/packages_spec.rb
View file @
97888a2e
...
@@ -7,10 +7,6 @@ describe API::Packages do
...
@@ -7,10 +7,6 @@ describe API::Packages do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:package
)
{
create
(
:npm_package
,
project:
project
)
}
let
(
:package
)
{
create
(
:npm_package
,
project:
project
)
}
before
do
project
.
add_developer
(
user
)
end
describe
'GET /projects/:id/packages'
do
describe
'GET /projects/:id/packages'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages"
}
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages"
}
...
@@ -37,14 +33,14 @@ describe API::Packages do
...
@@ -37,14 +33,14 @@ describe API::Packages do
end
end
it
'returns 404 for a user without access to the project'
do
it
'returns 404 for a user without access to the project'
do
project
.
team
.
truncate
get
api
(
url
,
user
)
get
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
it
'returns 200 and valid response schema'
do
it
'returns 200 and valid response schema'
do
project
.
add_maintainer
(
user
)
get
api
(
url
,
user
)
get
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
...
@@ -59,6 +55,7 @@ describe API::Packages do
...
@@ -59,6 +55,7 @@ describe API::Packages do
let!
(
:package3
)
{
create
(
:maven_package
,
project:
project
)
}
let!
(
:package3
)
{
create
(
:maven_package
,
project:
project
)
}
before
do
before
do
project
.
add_maintainer
(
user
)
stub_licensed_features
(
packages:
true
)
stub_licensed_features
(
packages:
true
)
end
end
...
@@ -92,4 +89,72 @@ describe API::Packages do
...
@@ -92,4 +89,72 @@ describe API::Packages do
end
end
end
end
end
end
describe
'DELETE /projects/:id/packages/:package_id'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages/
#{
package
.
id
}
"
}
context
'packages feature enabled'
do
before
do
stub_licensed_features
(
packages:
true
)
end
context
'project is public'
do
it
'returns 403 for non authenticated user'
do
delete
api
(
url
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
it
'returns 403 for a user without access to the project'
do
delete
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'project is private'
do
let
(
:project
)
{
create
(
:project
,
:private
)
}
it
'returns 404 for non authenticated user'
do
delete
api
(
url
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
it
'returns 404 for a user without access to the project'
do
delete
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
it
'returns 403 for a user without enough permissions'
do
project
.
add_developer
(
user
)
delete
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
it
'returns 204'
do
project
.
add_maintainer
(
user
)
delete
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
end
end
context
'packages feature disabled'
do
before
do
stub_licensed_features
(
packages:
false
)
end
it
'returns 403'
do
delete
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment