diff --git a/product_portfolio/models.py b/product_portfolio/models.py index 7adc2d21..5b348807 100644 --- a/product_portfolio/models.py +++ b/product_portfolio/models.py @@ -804,20 +804,20 @@ def set_review_status_from_policy(self): self.review_status = status_from_policy def compute_weighted_risk_score(self): + if self.package.risk_score is None: + return None + exposure_factor = 1.0 - if self.purpose and self.purpose.exposure_factor is not None: + if self.purpose and self.purpose.exposure_factor: exposure_factor = self.purpose.exposure_factor - if self.package.risk_score is not None: - weighted_risk_score = float(self.package.risk_score) * float(exposure_factor) - return weighted_risk_score + weighted_risk_score = float(self.package.risk_score) * float(exposure_factor) + return weighted_risk_score - def set_weighted_risk_score(self, save=False): + def set_weighted_risk_score(self): weighted_risk_score = self.compute_weighted_risk_score() if weighted_risk_score != self.weighted_risk_score: self.weighted_risk_score = weighted_risk_score - if save: - self.save(update_fields=["weighted_risk_score"]) def get_status_from_item_policy(self): """ diff --git a/product_portfolio/views.py b/product_portfolio/views.py index 52fb298a..65b63bc0 100644 --- a/product_portfolio/views.py +++ b/product_portfolio/views.py @@ -570,8 +570,8 @@ def tab_vulnerabilities(self): label = ( f"Vulnerabilities" f'' - f' {vulnerable_package_count}' - f' {vulnerability_count}' + f' {vulnerable_package_count}' + f' {vulnerability_count}' f"" ) diff --git a/vulnerabilities/fetch.py b/vulnerabilities/fetch.py index c7436537..95be80ba 100644 --- a/vulnerabilities/fetch.py +++ b/vulnerabilities/fetch.py @@ -113,8 +113,8 @@ def fetch_for_packages( if package_risk_score := vc_entry.get("risk_score"): affected_packages.update(risk_score=package_risk_score) + # TODO: This should be improved. product_package_qs = ProductPackage.objects.filter(package__in=affected_packages) - for product_package in product_package_qs: - product_package.set_weighted_risk_score(save=True) + product_package_qs.update_weighted_risk_score() return created_vulnerabilities