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
df6bd040
Commit
df6bd040
authored
Aug 20, 2019
by
Tetiana Chupryna
Committed by
Douwe Maan
Aug 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add licenses to the response
Also added granular permission to this info
parent
e32aab74
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
12 deletions
+62
-12
ee/app/serializers/dependency_entity.rb
ee/app/serializers/dependency_entity.rb
+9
-0
ee/changelogs/unreleased/13084-add-licenses-to-dl-response.yml
...angelogs/unreleased/13084-add-licenses-to-dl-response.yml
+5
-0
ee/spec/factories/dependencies.rb
ee/spec/factories/dependencies.rb
+9
-0
ee/spec/fixtures/api/schemas/dependency.json
ee/spec/fixtures/api/schemas/dependency.json
+13
-1
ee/spec/serializers/dependency_entity_spec.rb
ee/spec/serializers/dependency_entity_spec.rb
+24
-9
ee/spec/serializers/dependency_list_serializer_spec.rb
ee/spec/serializers/dependency_list_serializer_spec.rb
+2
-2
No files found.
ee/app/serializers/dependency_entity.rb
View file @
df6bd040
...
...
@@ -11,13 +11,22 @@ class DependencyEntity < Grape::Entity
expose
:name
,
:severity
end
class
LicenseEntity
<
Grape
::
Entity
expose
:name
,
:url
end
expose
:name
,
:packager
,
:version
expose
:location
,
using:
LocationEntity
expose
:vulnerabilities
,
using:
VulnerabilityEntity
,
if:
->
(
_
)
{
can_read_vulnerabilities?
}
expose
:licenses
,
using:
LicenseEntity
,
if:
->
(
_
)
{
can_read_licenses?
}
private
def
can_read_vulnerabilities?
can?
(
request
.
user
,
:read_project_security_dashboard
,
request
.
project
)
end
def
can_read_licenses?
can?
(
request
.
user
,
:read_software_license_policy
,
request
.
project
)
end
end
ee/changelogs/unreleased/13084-add-licenses-to-dl-response.yml
0 → 100644
View file @
df6bd040
---
title
:
Add Licenses info into Dependencies response
merge_request
:
15160
author
:
type
:
added
ee/spec/factories/dependencies.rb
View file @
df6bd040
...
...
@@ -26,6 +26,15 @@ FactoryBot.define do
end
end
trait
:with_licenses
do
licenses
do
[{
name:
'MIT'
,
url:
'http://opensource.org/licenses/mit-license'
}]
end
end
initialize_with
{
attributes
}
end
end
ee/spec/fixtures/api/schemas/dependency.json
View file @
df6bd040
...
...
@@ -5,7 +5,8 @@
"packager"
,
"version"
,
"location"
,
"vulnerabilities"
"vulnerabilities"
,
"licenses"
],
"properties"
:
{
"name"
:
{
...
...
@@ -35,6 +36,17 @@
"type"
:
"string"
}
}
},
"licenses"
:
{
"type"
:
"array"
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
},
"url"
:
{
"type"
:
"string"
}
}
}
},
"additionalProperties"
:
false
...
...
ee/spec/serializers/dependency_entity_spec.rb
View file @
df6bd040
...
...
@@ -6,32 +6,47 @@ describe DependencyEntity do
describe
'#as_json'
do
subject
{
described_class
.
represent
(
dependency
,
request:
request
).
as_json
}
set
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
let
(
:request
)
{
double
(
'request'
)
}
let
(
:dependency
)
{
build
(
:dependency
,
:with_vulnerabilities
)
}
let
(
:dependency
)
{
build
(
:dependency
,
:with_vulnerabilities
,
:with_licenses
)
}
before
do
stub_licensed_features
(
security_dashboard:
true
)
allow
(
request
).
to
receive
(
:project
).
and_return
(
project
)
allow
(
request
).
to
receive
(
:user
).
and_return
(
user
)
end
context
'w
ith developer
'
do
context
'w
hen all required features available
'
do
before
do
project
.
add_developer
(
user
)
stub_licensed_features
(
security_dashboard:
true
,
license_management:
true
)
allow
(
request
).
to
receive
(
:project
).
and_return
(
project
)
allow
(
request
).
to
receive
(
:user
).
and_return
(
user
)
end
it
do
is_expected
.
to
eq
(
dependency
.
except
(
:licenses
))
context
'with developer'
do
before
do
project
.
add_developer
(
user
)
end
it
{
is_expected
.
to
eq
(
dependency
)
}
end
context
'with reporter'
do
let
(
:dependency_info
)
{
build
(
:dependency
,
:with_licenses
)
}
before
do
project
.
add_reporter
(
user
)
end
it
{
is_expected
.
to
eq
(
dependency_info
)
}
end
end
context
'w
ith reporter
'
do
context
'w
hen all required features are unavailable
'
do
let
(
:dependency_info
)
{
build
(
:dependency
).
except
(
:licenses
)
}
before
do
project
.
add_
report
er
(
user
)
project
.
add_
develop
er
(
user
)
end
it
{
is_expected
.
to
eq
(
dependency_info
)
}
...
...
ee/spec/serializers/dependency_list_serializer_spec.rb
View file @
df6bd040
...
...
@@ -6,14 +6,14 @@ describe DependencyListSerializer do
set
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:ci_build
)
{
create
(
:ee_ci_build
,
:success
)
}
let
(
:dependencies
)
{
[
build
(
:dependency
,
:with_vulnerabilities
)]
}
let
(
:dependencies
)
{
[
build
(
:dependency
,
:with_vulnerabilities
,
:with_licenses
)]
}
let
(
:serializer
)
do
described_class
.
new
(
project:
project
,
user:
user
).
represent
(
dependencies
,
build:
ci_build
)
end
before
do
stub_licensed_features
(
security_dashboard:
true
)
stub_licensed_features
(
security_dashboard:
true
,
license_management:
true
)
project
.
add_developer
(
user
)
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