Skip to content

Commit

Permalink
Apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mtruj013 committed Aug 14, 2024
1 parent a22ba05 commit c1a59df
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
23 changes: 11 additions & 12 deletions static/js/src/cve/cve.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ const vulnerableStatuses = ["pending", "needed", "deferred"];
const releaseCheckboxes = releaseFilter.querySelectorAll(".p-checkbox__input");
const applyFiltersButton = document.querySelector("#apply-filters");
const packageInput = document.querySelector("#affectedPackages");
const priorityCheckboxes = priorityFilter.querySelectorAll(
".p-checkbox__input"
);
const priorityCheckboxes =
priorityFilter.querySelectorAll(".p-checkbox__input");
const statusCheckboxes = statusFilter.querySelectorAll(".p-checkbox__input");
const unmaintainedReleasesLink = document.querySelector(
".js-show-unmaintained-releases"
".js-show-unmaintained-releases",
);
const unmaintainedReleasesContainer = document.querySelector(
".js-unmaintained-releases"
".js-unmaintained-releases",
);
const showPackagesLinks = document.querySelectorAll(".js-show-packages");
const hidePackagesLinks = document.querySelectorAll(".js-hide-packages");
Expand All @@ -31,15 +30,15 @@ const detailedTables = document.querySelectorAll(".detailed-table");
const cveDescs = document.querySelectorAll(".cve-summary");
// eslint-disable-next-line no-undef
const maintainedReleases = Object.values(maintainedReleasesObj).map(
(release) => release.codename
(release) => release.codename,
);
// eslint-disable-next-line no-undef
const ltsReleases = Object.values(ltsReleasesObj).map(
(release) => release.codename
(release) => release.codename,
);
// eslint-disable-next-line no-undef
const unmaintainedReleases = Object.values(unmaintainedReleasesObj).map(
(release) => release.codename
(release) => release.codename,
);

function handleSearchInput() {
Expand Down Expand Up @@ -70,7 +69,7 @@ handlePackageInput();
// Adds event listeners to all filter checkboxes
function handleFilters() {
releaseCheckboxes.forEach(function (checkbox) {
checkbox.addEventListener("change", function (event) {
checkbox.addEventListener("change", function (event) {
if (event.target.checked) {
addParam(releaseFilter.name, event.target.value);
} else {
Expand Down Expand Up @@ -116,7 +115,7 @@ function removeParam(param, value) {
} else {
if (maintainedReleases.includes(value)) {
const maintainedCheckbox = document.querySelector(
"input[type='checkbox'][value='maintained']"
"input[type='checkbox'][value='maintained']",
);
maintainedCheckbox.checked = false;
}
Expand Down Expand Up @@ -151,7 +150,7 @@ function handleFilterPersist() {

if (includesFilterSubset(params, maintainedReleases)) {
let maintainedCheckbox = releaseFilter.querySelector(
"input[value='maintained']"
"input[value='maintained']",
);
maintainedCheckbox.checked = true;
}
Expand Down Expand Up @@ -233,7 +232,7 @@ function addParam(param, value) {
function getCheckboxFromRelease(release) {
const releaseCheckboxesArray = Array.from(releaseCheckboxes);
const checkbox = releaseCheckboxesArray.find(
(checkbox) => checkbox.value === release
(checkbox) => checkbox.value === release,
);

return checkbox;
Expand Down
12 changes: 8 additions & 4 deletions templates/security/cves/_cve-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ <h2 class="p-heading--5">
{% if cve.summarized_status %}
{% set status = cve.summarized_status %}
<div class="col-3 cve-summary col-medium-2" {% if status.icon %}style="padding-top: 0.4rem;"{% endif %}>
{% if status.name == "Some fixed" %}
{% if status.icon %}
<i class="p-icon--{{ status.icon }}"></i> {{ status.name }}
{% else %}
<p style="padding-top: 0.5rem;">
Some fixes available <span class="u-text--muted">{{ status.fixed_count }} of {{ status.fixable_count }}</span>
{% if status.name == "Some fixed" %}
Some fixes available <span class="u-text--muted">{{ status.fixed_count }} of {{ status.fixable_count }}</span>
{% else %}
{{ status.name }}
{% endif %}
</p>
{% else %}
<i class="p-icon--{{ status.icon }}"></i> {{ status.name }}
{% endif %}
</div>
{% endif %}
Expand Down
22 changes: 10 additions & 12 deletions webapp/security/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def get_summarized_status(

if count == 1:
if key_with_non_zero_value == "ignored-high":
cve["summarized_status"] = friendly_names["ignored"]
return friendly_names["ignored"]
else:
cve["summarized_status"] = friendly_names[key_with_non_zero_value]
return friendly_names[key_with_non_zero_value]
else:
"""
Calculate the number of cases that are “Fixable”, which is the total
Expand All @@ -81,24 +81,22 @@ def get_summarized_status(
)

if total_fixable and status_count["released"] == total_fixable:
cve["summarized_status"] = friendly_names["released"]
return friendly_names["released"]
elif total_fixable and status_count["vulnerable"] == total_fixable:
cve["summarized_status"] = friendly_names["vulnerable"]
return friendly_names["vulnerable"]
elif status_count["released"] > 0:
cve["summarized_status"] = {
return {
"name": "Some fixed",
"fixed_count": status_count["released"],
"fixable_count": total_fixable,
}
elif status_count["vulnerable"] > 0:
cve["summarized_status"] = friendly_names["vulnerable"]
return friendly_names["vulnerable"]
elif status_count["needs-triage"] > 0:
cve["summarized_status"] = friendly_names["needs-triage"]
return friendly_names["needs-triage"]
elif status_count["ignored-high"] > 0:
cve["summarized_status"] = friendly_names["ignored"]
return friendly_names["ignored"]
elif status_count["not-affected"] > 0:
cve["summarized_status"] = friendly_names["not-affected"]
return friendly_names["not-affected"]
elif status_count["DNE"] > 0:
cve["summarized_status"] = friendly_names["DNE"]

return cve["summarized_status"]
return friendly_names["DNE"]
9 changes: 3 additions & 6 deletions webapp/security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
from datetime import datetime
from math import ceil, floor
from collections import Counter

# Packages
import flask
Expand Down Expand Up @@ -324,7 +323,7 @@ def cve_index():
statuses=statuses,
order=order,
)

cves = cves_response.get("cves")
total_results = cves_response.get("total_results")

Expand Down Expand Up @@ -427,8 +426,7 @@ def cve_index():
}

for cve in high_priority_cves:
cve["summarized_status"] = {}
get_summarized_status(
cve["summarized_status"] = get_summarized_status(
cve,
ignored_low_indicators,
vulnerable_indicators,
Expand All @@ -437,8 +435,7 @@ def cve_index():
)

for cve in cves:
cve["summarized_status"] = {}
get_summarized_status(
cve["summarized_status"] = get_summarized_status(
cve,
ignored_low_indicators,
vulnerable_indicators,
Expand Down

0 comments on commit c1a59df

Please sign in to comment.