Skip to content

Commit 5165913

Browse files
committed
add support for calculating CVSS
Signed-off-by: Ziad <ziadhany2016@gmail.com>
1 parent 27b64d3 commit 5165913

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

vulnerabilities/models.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,27 @@ class VulnerabilitySeverity(models.Model):
367367
),
368368
)
369369

370-
value = models.CharField(max_length=50, help_text="Example: 9.0, Important, High")
370+
value = models.CharField(
371+
max_length=50,
372+
help_text="Score Value expressed as a number such as 9.0 that can be sorted or compared",
373+
)
371374

372-
@property
373-
def scoring_element(self):
374-
try:
375-
score = SCORING_SYSTEMS[self.scoring_system].as_score(self.value)
376-
return score
377-
except NotImplementedError:
378-
return
375+
scoring_elements = models.CharField(
376+
max_length=100,
377+
null=True,
378+
help_text="Supporting a scoring elements as a string "
379+
"For example a CVSS vector Important, High, Medium ,Low."
380+
"Typically used to compute the value",
381+
)
382+
383+
def save(self, *args, **kwargs):
384+
super().save(*args, **kwargs)
385+
if not self.value and self.scoring_elements:
386+
try:
387+
self.value = SCORING_SYSTEMS[self.scoring_system].as_score(self.value)
388+
super().save(update_fields=["value"])
389+
except NotImplementedError:
390+
pass
379391

380392
class Meta:
381393
unique_together = ["reference", "scoring_system", "value"]

0 commit comments

Comments
 (0)