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
49f4c684
Commit
49f4c684
authored
Jan 24, 2019
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor packages API backend based on review
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
7578529c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
36 deletions
+34
-36
ee/lib/api/helpers/packages_helpers.rb
ee/lib/api/helpers/packages_helpers.rb
+1
-0
ee/lib/api/packages.rb
ee/lib/api/packages.rb
+2
-1
ee/spec/requests/api/packages_spec.rb
ee/spec/requests/api/packages_spec.rb
+31
-35
No files found.
ee/lib/api/helpers/packages_helpers.rb
View file @
49f4c684
...
...
@@ -14,6 +14,7 @@ module API
def
authorize_download_package!
authorize!
(
:read_package
,
user_project
)
end
alias_method
:authorize_read_package!
,
:authorize_download_package!
def
authorize_create_package!
authorize!
(
:create_package
,
user_project
)
...
...
ee/lib/api/packages.rb
View file @
49f4c684
...
...
@@ -7,7 +7,7 @@ module API
before
do
require_packages_enabled!
authorize_packages_feature!
authorize_
downlo
ad_package!
authorize_
re
ad_package!
end
helpers
::
API
::
Helpers
::
PackagesHelpers
...
...
@@ -17,6 +17,7 @@ module API
end
resource
:projects
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
desc
'Get all project packages'
do
detail
'This feature was introduced in GitLab 11.8'
success
EE
::
API
::
Entities
::
Package
end
params
do
...
...
ee/spec/requests/api/packages_spec.rb
View file @
49f4c684
...
...
@@ -6,29 +6,19 @@ describe API::Packages do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:package
)
{
create
(
:npm_package
,
project:
project
)
}
let
(
:params
)
{
nil
}
before
do
project
.
add_developer
(
user
)
stub_licensed_features
(
packages:
true
)
end
describe
'GET /projects/:id/packages'
do
let
(
:url
)
{
"/projects/
#{
project
.
id
}
/packages"
}
context
'
when packages feature is dis
abled'
do
context
'
packages feature en
abled'
do
before
do
stub_licensed_features
(
packages:
false
)
end
it
'returns 403'
do
get
api
(
url
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
stub_licensed_features
(
packages:
true
)
end
end
context
'when packages feature is enabled'
do
context
'project is public'
do
it
'returns 200'
do
get
api
(
url
)
...
...
@@ -38,9 +28,7 @@ describe API::Packages do
end
context
'project is private'
do
before
do
project
.
update
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
end
let
(
:project
)
{
create
(
:project
,
:private
)
}
it
'returns 404 for non authenticated user'
do
get
api
(
url
)
...
...
@@ -63,36 +51,44 @@ describe API::Packages do
expect
(
response
).
to
match_response_schema
(
'public_api/v4/packages/packages'
,
dir:
'ee'
)
end
end
end
context
'with pagination params'
do
let
(
:per_page
)
{
2
}
let!
(
:package1
)
{
create
(
:npm_package
,
project:
project
)
}
let!
(
:package2
)
{
create
(
:npm_package
,
project:
project
)
}
let!
(
:package3
)
{
create
(
:maven_package
,
project:
project
)
}
context
'with pagination params'
do
let
(
:per_page
)
{
2
}
let!
(
:package1
)
{
create
(
:npm_package
,
project:
project
)
}
let!
(
:package2
)
{
create
(
:npm_package
,
project:
project
)
}
let!
(
:package3
)
{
create
(
:maven_package
,
project:
project
)
}
before
do
stub_licensed_features
(
packages:
true
)
end
before
do
stub_licensed_features
(
packages:
true
)
end
context
'when viewing the first page'
do
let
(
:expected
)
{
[
package1
.
id
,
package2
.
id
]
}
context
'when viewing the first page'
do
it
'returns first 2 packages'
do
get
api
(
url
,
user
),
params:
{
page:
1
,
per_page:
per_page
}
it
'returns first 2 packages'
do
get
api
(
url
,
user
),
params:
{
page:
1
,
per_page:
per_page
}
expect_paginated_array_response
([
package1
.
id
,
package2
.
id
])
end
end
expect_paginated_array_response
(
expected
)
context
'viewing the second page'
do
it
'returns the last package'
do
get
api
(
url
,
user
),
params:
{
page:
2
,
per_page:
per_page
}
expect_paginated_array_response
([
package3
.
id
])
end
end
end
end
context
'viewing the second page'
do
let
(
:expected
)
{
[
package3
.
id
]
}
context
'packages feature disabled'
do
before
do
stub_licensed_features
(
packages:
false
)
end
it
'returns the last package
'
do
get
api
(
url
,
user
),
params:
{
page:
2
,
per_page:
per_page
}
it
'returns 403
'
do
get
api
(
url
,
user
)
expect_paginated_array_response
(
expected
)
end
expect
(
response
).
to
have_gitlab_http_status
(
403
)
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