Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
  • Loading branch information
TG1999 committed Nov 15, 2023
1 parent 3881944 commit 9d29cbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Migration(migrations.Migration):

dependencies = [
("vulnerabilities", "0040_remove_advisory_date_improved_advisory_date_imported"),
("vulnerabilities", "0041_remove_vulns_with_empty_aliases"),
]

operations = [
Expand Down
14 changes: 11 additions & 3 deletions vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def with_package_counts(self):
class VulnerabilityStatusType(models.IntegerChoices):
"""List of vulnerability statuses."""

PUBLISHED = 1, "published"
DISPUTED = 2, "disputed"
INVALID = 3, "invalid"
PUBLISHED = 1, "Published"
DISPUTED = 2, "Disputed"
INVALID = 3, "Invalid"


class Vulnerability(models.Model):
Expand Down Expand Up @@ -238,6 +238,14 @@ def get_aliases(self):

alias = get_aliases

@property
def get_status_label(self):
label_by_status = {
choice[0] : choice[1]
for choice in VulnerabilityStatusType.choices
}
return label_by_status.get(self.status) or VulnerabilityStatusType.PUBLISHED.label

def get_absolute_url(self):
"""
Return this Vulnerability details absolute URL.
Expand Down
10 changes: 1 addition & 9 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,13 @@ class VulnerabilityDetails(DetailView):
def get_queryset(self):
return super().get_queryset().prefetch_related("references", "aliases", "weaknesses")

def get_status(self, status):
status_by_keys = {
VulnerabilityStatusType.PUBLISHED: "Published",
VulnerabilityStatusType.INVALID: "Invalid",
VulnerabilityStatusType.DISPUTED: "Disputed",
}
return status_by_keys[status]

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
weaknesses = self.object.weaknesses.all()
weaknesses_present_in_db = [
weakness_object for weakness_object in weaknesses if weakness_object.weakness
]
status = self.get_status(self.object.status)
status = self.object.get_status_label
context.update(
{
"vulnerability": self.object,
Expand Down

0 comments on commit 9d29cbd

Please sign in to comment.