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
ad25c574
Commit
ad25c574
authored
Oct 08, 2019
by
Victor Zagorodny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move pagination to API level where it should be
parent
d75b5723
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
14 deletions
+14
-14
ee/app/finders/security/vulnerabilities_finder.rb
ee/app/finders/security/vulnerabilities_finder.rb
+2
-8
ee/lib/api/vulnerabilities.rb
ee/lib/api/vulnerabilities.rb
+3
-3
ee/spec/finders/security/vulnerabilities_finder_spec.rb
ee/spec/finders/security/vulnerabilities_finder_spec.rb
+2
-3
ee/spec/requests/api/vulnerabilities_spec.rb
ee/spec/requests/api/vulnerabilities_spec.rb
+7
-0
No files found.
ee/app/finders/security/vulnerabilities_finder.rb
View file @
ad25c574
...
...
@@ -6,23 +6,17 @@
#
# Arguments:
# project: a Project to query for Vulnerabilities
# params:
# page: Integer
# per_page: Integer
module
Security
class
VulnerabilitiesFinder
attr_reader
:project
attr_reader
:page
,
:per_page
def
initialize
(
project
,
params
=
{}
)
def
initialize
(
project
)
@project
=
project
@page
=
params
[
:page
]
||
1
@per_page
=
params
[
:per_page
]
||
20
end
def
execute
project
.
vulnerabilities
.
page
(
page
).
per
(
per_page
)
project
.
vulnerabilities
end
end
end
ee/lib/api/vulnerabilities.rb
View file @
ad25c574
...
...
@@ -7,8 +7,8 @@ module API
helpers
::
API
::
Helpers
::
VulnerabilityFindingsHelpers
helpers
do
def
vulnerabilities_by
(
project
,
params
)
Security
::
VulnerabilitiesFinder
.
new
(
project
,
params
).
execute
def
vulnerabilities_by
(
project
)
Security
::
VulnerabilitiesFinder
.
new
(
project
).
execute
end
end
...
...
@@ -36,7 +36,7 @@ module API
authorize!
:read_project_security_dashboard
,
user_project
vulnerabilities
=
paginate
(
vulnerabilities_by
(
user_project
,
declared_params
)
vulnerabilities_by
(
user_project
)
)
present
vulnerabilities
,
with:
VulnerabilityEntity
...
...
ee/spec/finders/security/vulnerabilities_finder_spec.rb
View file @
ad25c574
...
...
@@ -4,11 +4,10 @@ require 'spec_helper'
describe
Security
::
VulnerabilitiesFinder
do
let
(
:project
)
{
create
(
:project
,
:with_vulnerabilities
)
}
let
(
:params
)
{
{
page:
2
,
per_page:
1
}
}
subject
{
described_class
.
new
(
project
,
params
).
execute
}
subject
{
described_class
.
new
(
project
).
execute
}
it
'returns vulnerabilities of a project and respects pagination params'
do
expect
(
subject
).
to
contain_exactly
(
project
.
vulnerabilities
.
drop
(
1
).
take
(
1
).
first
)
expect
(
subject
).
to
match_array
(
project
.
vulnerabilities
)
end
end
ee/spec/requests/api/vulnerabilities_spec.rb
View file @
ad25c574
...
...
@@ -26,6 +26,13 @@ describe API::Vulnerabilities do
expect
(
response
).
to
match_response_schema
(
'vulnerability_list'
,
dir:
'ee'
)
expect
(
response
.
headers
[
'X-Total'
]).
to
eq
project
.
vulnerabilities
.
count
.
to_s
end
it
'paginates the vulnerabilities according to the pagination params'
do
get
api
(
"
#{
project_vulnerabilities_path
}
?page=2&per_page=1"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
.
map
{
|
v
|
v
[
'id'
]
}).
to
contain_exactly
(
project
.
vulnerabilities
.
drop
(
1
).
take
(
1
).
first
.
id
)
end
end
it_behaves_like
'forbids access to vulnerability-like endpoint in expected cases'
...
...
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