Commit ff2425a1 authored by Michał Zając's avatar Michał Zając

Apply reviewer suggestions

parent 7c5a5558
# frozen_string_literal: true # frozen_string_literal: true
module VulnerabilitiesHelper module VulnerabilitiesHelper
def vulnerability_data(vulnerability, pipeline, current_user: nil) def vulnerability_data(vulnerability, pipeline)
return unless vulnerability return unless vulnerability
{ {
...@@ -10,8 +10,8 @@ module VulnerabilitiesHelper ...@@ -10,8 +10,8 @@ module VulnerabilitiesHelper
create_issue_url: create_vulnerability_feedback_issue_path(vulnerability.finding.project), create_issue_url: create_vulnerability_feedback_issue_path(vulnerability.finding.project),
pipeline_json: vulnerability_pipeline_data(pipeline).to_json, pipeline_json: vulnerability_pipeline_data(pipeline).to_json,
has_mr: !!vulnerability.finding.merge_request_feedback.try(:merge_request_iid), has_mr: !!vulnerability.finding.merge_request_feedback.try(:merge_request_iid),
vulnerability_feedback_help_path: help_page_path("user/application_security/index", anchor: "interacting-with-the-vulnerabilities"), vulnerability_feedback_help_path: help_page_path('user/application_security/index', anchor: 'interacting-with-the-vulnerabilities'),
finding_json: vulnerability_finding_data(vulnerability.finding, current_user: current_user).to_json finding_json: vulnerability_finding_data(vulnerability.finding).to_json
} }
end end
...@@ -25,20 +25,20 @@ module VulnerabilitiesHelper ...@@ -25,20 +25,20 @@ module VulnerabilitiesHelper
} }
end end
def vulnerability_finding_data(finding, current_user: nil) def vulnerability_finding_data(finding)
occurrence = Vulnerabilities::OccurrenceSerializer.new(current_user: current_user).represent(finding) occurrence = Vulnerabilities::OccurrenceSerializer.new(current_user: current_user).represent(finding)
remediation = occurrence[:remediations]&.first remediation = occurrence[:remediations]&.first
{ occurrence.slice(
description: occurrence[:description], :description,
identifiers: occurrence[:identifiers], :identifiers,
links: occurrence[:links], :links,
location: occurrence[:location], :location,
name: occurrence[:name], :name,
solution: occurrence[:solution], :issue_feedback,
remediation: remediation, :project
issue_feedback: occurrence[:issue_feedback], ).merge(
project: occurrence[:project] solution: remediation ? remediation['summary'] : occurrence[:solution]
} )
end end
end end
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- page_title @vulnerability.title - page_title @vulnerability.title
- page_description @vulnerability.description - page_description @vulnerability.description
#js-vulnerability-management-app{ data: vulnerability_data(@vulnerability, @pipeline, current_user: @current_user) } #js-vulnerability-management-app{ data: vulnerability_data(@vulnerability, @pipeline) }
.issue-details.issuable-details .issue-details.issuable-details
.detail-page-description .detail-page-description
...@@ -38,4 +38,4 @@ ...@@ -38,4 +38,4 @@
%li %li
%a{ :href=>identifier.url, target: "_blank", rel: 'noopener noreferrer' }= identifier.name %a{ :href=>identifier.url, target: "_blank", rel: 'noopener noreferrer' }= identifier.name
#js-vulnerability-footer{ data: vulnerability_data(@vulnerability, @pipeline, current_user: @current_user) } #js-vulnerability-footer{ data: vulnerability_data(@vulnerability, @pipeline) }
...@@ -8,7 +8,10 @@ describe VulnerabilitiesHelper do ...@@ -8,7 +8,10 @@ describe VulnerabilitiesHelper do
expect(subject).to include( expect(subject).to include(
vulnerability_json: vulnerability.to_json, vulnerability_json: vulnerability.to_json,
project_fingerprint: vulnerability.finding.project_fingerprint, project_fingerprint: vulnerability.finding.project_fingerprint,
create_issue_url: be_present create_issue_url: anything,
has_mr: anything,
vulnerability_feedback_help_path: anything,
finding_json: anything
) )
end end
end end
...@@ -63,7 +66,9 @@ describe VulnerabilitiesHelper do ...@@ -63,7 +66,9 @@ describe VulnerabilitiesHelper do
identifiers: finding.identifiers, identifiers: finding.identifiers,
links: finding.links, links: finding.links,
location: finding.location, location: finding.location,
name: finding.name name: finding.name,
issue_feedback: anything,
project: anything
) )
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment