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
1b560a56
Commit
1b560a56
authored
Aug 06, 2019
by
Can Eldem
Committed by
Stan Hu
Aug 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dry merge request serializer
Reuse some of the methods
parent
eef3c955
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
47 deletions
+23
-47
ee/app/presenters/ee/merge_request_presenter.rb
ee/app/presenters/ee/merge_request_presenter.rb
+1
-23
ee/app/serializers/ee/merge_request_widget_entity.rb
ee/app/serializers/ee/merge_request_widget_entity.rb
+3
-3
ee/app/serializers/vulnerabilities/occurrence_entity.rb
ee/app/serializers/vulnerabilities/occurrence_entity.rb
+12
-14
ee/spec/presenters/merge_request_presenter_spec.rb
ee/spec/presenters/merge_request_presenter_spec.rb
+2
-2
ee/spec/serializers/vulnerabilities/occurrence_entity_spec.rb
...pec/serializers/vulnerabilities/occurrence_entity_spec.rb
+5
-5
No files found.
ee/app/presenters/ee/merge_request_presenter.rb
View file @
1b560a56
...
...
@@ -3,6 +3,7 @@
module
EE
module
MergeRequestPresenter
include
::
VisibleApprovable
include
::
EE
::
ProjectsHelper
# rubocop: disable Cop/InjectEnterpriseEditionModule
def
approvals_path
if
expose_mr_approval_path?
...
...
@@ -56,33 +57,10 @@ module EE
project_vulnerability_feedback_index_path
(
merge_request
.
project
)
end
def
create_vulnerability_feedback_issue_path
if
expose_create_feedback_path?
(
:issue
)
vulnerability_feedback_path
end
end
def
create_vulnerability_feedback_merge_request_path
if
expose_create_feedback_path?
(
:merge_request
)
vulnerability_feedback_path
end
end
def
create_vulnerability_feedback_dismissal_path
if
expose_create_feedback_path?
(
:dismissal
)
vulnerability_feedback_path
end
end
private
def
expose_mr_approval_path?
approval_feature_available?
&&
merge_request
.
iid
end
def
expose_create_feedback_path?
(
feedback_type
)
feedback
=
Vulnerabilities
::
Feedback
.
new
(
project:
merge_request
.
project
,
feedback_type:
feedback_type
)
can?
(
current_user
,
:create_vulnerability_feedback
,
feedback
)
end
end
end
ee/app/serializers/ee/merge_request_widget_entity.rb
View file @
1b560a56
...
...
@@ -117,15 +117,15 @@ module EE
end
expose
:create_vulnerability_feedback_issue_path
do
|
merge_request
|
presenter
(
merge_request
).
create_vulnerability_feedback_issue_path
presenter
(
merge_request
).
create_vulnerability_feedback_issue_path
(
merge_request
.
project
)
end
expose
:create_vulnerability_feedback_merge_request_path
do
|
merge_request
|
presenter
(
merge_request
).
create_vulnerability_feedback_merge_request_path
presenter
(
merge_request
).
create_vulnerability_feedback_merge_request_path
(
merge_request
.
project
)
end
expose
:create_vulnerability_feedback_dismissal_path
do
|
merge_request
|
presenter
(
merge_request
).
create_vulnerability_feedback_dismissal_path
presenter
(
merge_request
).
create_vulnerability_feedback_dismissal_path
(
merge_request
.
project
)
end
expose
:rebase_commit_sha
...
...
ee/app/serializers/vulnerabilities/occurrence_entity.rb
View file @
1b560a56
# frozen_string_literal: true
class
Vulnerabilities::OccurrenceEntity
<
Grape
::
Entity
include
::
EE
::
ProjectsHelper
# rubocop: disable Cop/InjectEnterpriseEditionModule
include
RequestAwareEntity
expose
:id
,
:report_type
,
:name
,
:severity
,
:confidence
expose
:scanner
,
using:
Vulnerabilities
::
ScannerEntity
expose
:identifiers
,
using:
Vulnerabilities
::
IdentifierEntity
expose
:project_fingerprint
expose
:vulnerability_feedback_path
,
as: :create_vulnerability_feedback_issue_path
,
if:
->
(
_
,
_
)
{
can_create_feedback?
(
:issue
)
}
expose
:vulnerability_feedback_path
,
as: :create_vulnerability_feedback_merge_request_path
,
if:
->
(
_
,
_
)
{
can_create_feedback?
(
:merge_request
)
}
expose
:vulnerability_feedback_path
,
as: :create_vulnerability_feedback_dismissal_path
,
if:
->
(
_
,
_
)
{
can_create_feedback?
(
:dismissal
)
}
expose
:create_vulnerability_feedback_issue_path
do
|
occurrence
|
create_vulnerability_feedback_issue_path
(
occurrence
.
project
)
end
expose
:create_vulnerability_feedback_merge_request_path
do
|
occurrence
|
create_vulnerability_feedback_merge_request_path
(
occurrence
.
project
)
end
expose
:create_vulnerability_feedback_dismissal_path
do
|
occurrence
|
create_vulnerability_feedback_dismissal_path
(
occurrence
.
project
)
end
expose
:project
,
using:
::
ProjectEntity
expose
:dismissal_feedback
,
using:
Vulnerabilities
::
FeedbackEntity
expose
:issue_feedback
,
using:
Vulnerabilities
::
FeedbackEntity
...
...
@@ -28,15 +36,5 @@ class Vulnerabilities::OccurrenceEntity < Grape::Entity
end
alias_method
:occurrence
,
:object
private
def
vulnerability_feedback_path
project_vulnerability_feedback_index_path
(
occurrence
.
project
)
end
def
can_create_feedback?
(
feedback_type
)
feedback
=
Vulnerabilities
::
Feedback
.
new
(
project:
occurrence
.
project
,
feedback_type:
feedback_type
)
can?
(
request
.
current_user
,
:create_vulnerability_feedback
,
feedback
)
end
delegate
:current_user
,
to: :request
end
ee/spec/presenters/merge_request_presenter_spec.rb
View file @
1b560a56
...
...
@@ -135,14 +135,14 @@ describe MergeRequestPresenter do
end
with_them
do
subject
{
described_class
.
new
(
merge_request
,
current_user:
user
).
public_send
(
create_feedback_path
)
}
subject
{
described_class
.
new
(
merge_request
,
current_user:
user
).
public_send
(
create_feedback_path
,
merge_request
.
project
)
}
it
{
is_expected
.
to
eq
(
"/
#{
merge_request
.
project
.
full_path
}
/vulnerability_feedback"
)
}
context
'when not allowed to create vulnerability feedback'
do
let
(
:unauthorized_user
)
{
create
(
:user
)
}
subject
{
described_class
.
new
(
merge_request
,
current_user:
unauthorized_user
).
public_send
(
create_feedback_path
)
}
subject
{
described_class
.
new
(
merge_request
,
current_user:
unauthorized_user
).
public_send
(
create_feedback_path
,
merge_request
.
project
)
}
it
"does not contain
#{
params
[
'create_feedback_path'
]
}
"
do
expect
(
subject
).
to
be_nil
...
...
ee/spec/serializers/vulnerabilities/occurrence_entity_spec.rb
View file @
1b560a56
...
...
@@ -62,9 +62,9 @@ describe Vulnerabilities::OccurrenceEntity do
end
it
'does not contain vulnerability feedback paths'
do
expect
(
subject
).
not_to
include
(
:create_vulnerability_feedback_issue_path
)
expect
(
subject
).
not_to
include
(
:create_vulnerability_feedback_merge_request_path
)
expect
(
subject
).
not_to
include
(
:create_vulnerability_feedback_dismissal_path
)
expect
(
subject
[
:create_vulnerability_feedback_issue_path
]).
to
be_falsey
expect
(
subject
[
:create_vulnerability_feedback_merge_request_path
]).
to
be_falsey
expect
(
subject
[
:create_vulnerability_feedback_dismissal_path
]).
to
be_falsey
end
end
...
...
@@ -89,7 +89,7 @@ describe Vulnerabilities::OccurrenceEntity do
let
(
:project
)
{
create
(
:project
,
issues_access_level:
ProjectFeature
::
DISABLED
)
}
it
'does not contain vulnerability feedback issue path'
do
expect
(
subject
).
not_to
include
(
:create_vulnerability_feedback_issue_path
)
expect
(
subject
[
:create_vulnerability_feedback_issue_path
]).
to
be_falsey
end
it
'contains vulnerability feedback dismissal path'
do
...
...
@@ -105,7 +105,7 @@ describe Vulnerabilities::OccurrenceEntity do
let
(
:project
)
{
create
(
:project
,
merge_requests_access_level:
ProjectFeature
::
DISABLED
)
}
it
'does not contain vulnerability feedback merge_request path'
do
expect
(
subject
).
not_to
include
(
:create_vulnerability_feedback_merge_request_path
)
expect
(
subject
[
:create_vulnerability_feedback_merge_request_path
]).
to
be_falsey
end
it
'contains vulnerability feedback issue path'
do
...
...
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