Commit 5945f702 authored by Dave Liu's avatar Dave Liu Committed by dave

Refactor issue vulnerability description template

add helper method vulnerability_scan_data? to reduce duplication
parent 158e768a
......@@ -74,4 +74,8 @@ module VulnerabilitiesHelper
data
end
def vulnerability_scan_data?(vulnerability)
vulnerability.scanner.present? || vulnerability.scan.present?
end
end
......@@ -60,25 +60,26 @@
</details>
<% end %>
<% end %>
<% if vulnerability.scanner.present? || vulnerability.scan.present? %>
<% if vulnerability_scan_data?(vulnerability) %>
### <%= _("Scanner") %>:
<% if vulnerability.scanner.present? %>
* <%= _("Name") %>: <%= vulnerability.scanner[:name] %>
<% end %>
<% if vulnerability.scan.present? %>
<% if vulnerability.scan[:type].present? %>
* <%= _("Type") %>: <%= vulnerability.scan[:type] %>
<%- scan_data = vulnerability.scan -%>
<% if scan_data.present? %>
<% if scan_data[:type].present? %>
* <%= _("Type") %>: <%= scan_data[:type] %>
<% end %>
<% if vulnerability.scan[:status].present? %>
* <%= _("Status") %>: <%= vulnerability.scan[:status] %>
<% if scan_data[:status].present? %>
* <%= _("Status") %>: <%= scan_data[:status] %>
<% end %>
<% if vulnerability.scan[:start_time].present? %>
* <%= _("Start Time") %>: <%= vulnerability.scan[:start_time] %>
<% if scan_data[:start_time].present? %>
* <%= _("Start Time") %>: <%= scan_data[:start_time] %>
<% end %>
<% if vulnerability.scan[:end_time].present? %>
* <%= _("End Time") %>: <%= vulnerability.scan[:end_time] %>
<% if scan_data[:end_time].present? %>
* <%= _("End Time") %>: <%= scan_data[:end_time] %>
<% end %>
<% end %>
<% end %>
......@@ -52,24 +52,25 @@ h3. <%= _("Links") %>:
<%= _("See vulnerability %{vulnerability_link} for any Remediation details.".html_safe) % { vulnerability_link: "[#{vulnerability.id}|#{vulnerability_url(vulnerability)}]" } %>
<% end %>
<% if vulnerability.scanner.present? || vulnerability.scan.present? %>
<% if vulnerability_scan_data?(vulnerability) %>
h3. <%= _("Scanner") %>:
<% if vulnerability.scanner.present? %>
* <%= _("Name") %>: <%= vulnerability.scanner[:name] %>
<% end %>
<% if vulnerability.scan.present? %>
<% if vulnerability.scan.type.present? %>
* <%= _("Type") %>: <%= vulnerability.scan.type %>
<%- scan_data = vulnerability.scan -%>
<% if scan_data.present? %>
<% if scan_data.type.present? %>
* <%= _("Type") %>: <%= scan_data.type %>
<% end %>
<% if vulnerability.scan.status.present? %>
* <%= _("Status") %>: <%= vulnerability.scan.status %>
<% if scan_data.status.present? %>
* <%= _("Status") %>: <%= scan_data.status %>
<% end %>
<% if vulnerability.scan.start_time.present? %>
* <%= _("Start Time") %>: <%= vulnerability.scan.start_time %>
<% if scan_data.start_time.present? %>
* <%= _("Start Time") %>: <%= scan_data.start_time %>
<% end %>
<% if vulnerability.scan.end_time.present? %>
* <%= _("End Time") %>: <%= vulnerability.scan.end_time %>
<% if scan_data.end_time.present? %>
* <%= _("End Time") %>: <%= scan_data.end_time %>
<% end %>
<% end %>
<% end %>
......@@ -283,4 +283,34 @@ RSpec.describe VulnerabilitiesHelper do
end
end
end
describe '#vulnerability_scan_data?' do
subject { helper.vulnerability_scan_data?(vulnerability) }
context 'scanner present' do
before do
allow(vulnerability).to receive(:scanner).and_return(true)
end
it { is_expected.to be_truthy }
end
context 'scan present' do
before do
allow(vulnerability).to receive(:scanner).and_return(false)
allow(vulnerability).to receive(:scan).and_return(true)
end
it { is_expected.to be_truthy }
end
context 'neither scan nor scanner being present' do
before do
allow(vulnerability).to receive(:scanner).and_return(false)
allow(vulnerability).to receive(:scan).and_return(false)
end
it { is_expected.to be_falsey }
end
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