Skip to content

Commit

Permalink
Refine the compute_weighted_risk_score method #102
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 23, 2024
1 parent ac48923 commit 1e415d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions product_portfolio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ def tab_vulnerabilities(self):
label = (
f"Vulnerabilities"
f'<span class="badge badge-vulnerability ps-1 ms-1">'
f' <i class="fas fa-archive"></i>{vulnerable_package_count}'
f' <i class="fas fa-bug"></i>{vulnerability_count}'
f' <i class="fas fa-archive" style="height: auto"></i>{vulnerable_package_count}'
f' <i class="fas fa-bug" style="height: auto"></i>{vulnerability_count}'
f"</span>"
)

Expand Down
4 changes: 2 additions & 2 deletions vulnerabilities/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1e415d4

Please sign in to comment.