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
73926ac0
Commit
73926ac0
authored
Sep 10, 2019
by
Can Eldem
Committed by
James Lopez
Sep 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check current user is nil when serialising
parent
bcb605fa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
ee/app/serializers/vulnerabilities/feedback_entity.rb
ee/app/serializers/vulnerabilities/feedback_entity.rb
+7
-3
ee/spec/serializers/vulnerabilities/feedback_entity_spec.rb
ee/spec/serializers/vulnerabilities/feedback_entity_spec.rb
+17
-0
No files found.
ee/app/serializers/vulnerabilities/feedback_entity.rb
View file @
73926ac0
...
@@ -57,14 +57,18 @@ class Vulnerabilities::FeedbackEntity < Grape::Entity
...
@@ -57,14 +57,18 @@ class Vulnerabilities::FeedbackEntity < Grape::Entity
end
end
def
can_destroy_feedback?
def
can_destroy_feedback?
can?
(
request
.
current_user
,
:destroy_vulnerability_feedback
,
feedback
)
can?
(
current_user
,
:destroy_vulnerability_feedback
,
feedback
)
end
end
def
can_read_issue?
def
can_read_issue?
feedback
.
issue
.
present?
&&
can?
(
request
.
current_user
,
:read_issue
,
feedback
.
issue
)
feedback
.
issue
.
present?
&&
can?
(
current_user
,
:read_issue
,
feedback
.
issue
)
end
end
def
can_read_merge_request?
def
can_read_merge_request?
feedback
.
merge_request
.
present?
&&
can?
(
request
.
current_user
,
:read_merge_request
,
feedback
.
merge_request
)
feedback
.
merge_request
.
present?
&&
can?
(
current_user
,
:read_merge_request
,
feedback
.
merge_request
)
end
def
current_user
return
request
.
current_user
if
request
.
respond_to?
(
:current_user
)
end
end
end
end
ee/spec/serializers/vulnerabilities/feedback_entity_spec.rb
View file @
73926ac0
...
@@ -44,6 +44,23 @@ describe Vulnerabilities::FeedbackEntity do
...
@@ -44,6 +44,23 @@ describe Vulnerabilities::FeedbackEntity do
end
end
end
end
context
'when there is no current user'
do
let
(
:entity
)
{
described_class
.
represent
(
feedback
,
request:
request
)
}
before
do
allow
(
request
).
to
receive
(
:current_user
).
and_return
(
nil
)
allow
(
feedback
).
to
receive
(
:author
).
and_return
(
nil
)
end
subject
{
entity
.
as_json
}
it
'does not include fields related to current user'
do
is_expected
.
not_to
include
(
:issue_url
)
is_expected
.
not_to
include
(
:destroy_vulnerability_feedback_dismissal_path
)
is_expected
.
not_to
include
(
:merge_request_path
)
end
end
context
'when issue is not present'
do
context
'when issue is not present'
do
let
(
:feedback
)
{
build
(
:vulnerability_feedback
,
feedback_type: :issue
,
project:
project
,
issue:
nil
)
}
let
(
:feedback
)
{
build
(
:vulnerability_feedback
,
feedback_type: :issue
,
project:
project
,
issue:
nil
)
}
...
...
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