Skip to content

Commit

Permalink
Fix UI break
Browse files Browse the repository at this point in the history
Recent model changes break the UI as now the PackageRelatedVulnerability
contains a ``fix`` flag to mark the relationship as a fix.
This is leveraged to eliminate multiple columns like patched_package or
vulnerable_package.

Known defects (in current PR):
-[x] UI break
-[ ] might crash in multiple imports / improves
-[ ] No improver than default improver is implemented yet
-[ ] normalized function of ``AdvisoryData`` has no body
-[ ] nginx importer still has remains of set_api etc
-[x] Inference -> AdvisoryData encapsulation
-[ ] Duplicated data in database
-[ ] ???

Knows defects (to be solved in different PR):
-[ ] inconsistent naming - will be resolved in a different PR
-[ ] unordered imports

Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
  • Loading branch information
Hritik14 committed Aug 29, 2021
1 parent 9fceb51 commit 1834ef0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def vulnerable_to(self):
"""
Returns packages which are vulnerable to this vulnerability.
"""
return self.vulnerable_packages.all()
return self.packages.filter(vulnerabilities__packagerelatedvulnerability__fix=False)

@property
def resolved_to(self):
"""
Returns packages, which first received patch against this vulnerability
in their particular version history.
"""
return self.patched_packages.all().distinct()
return self.packages.filter(vulnerabilities__packagerelatedvulnerability__fix=True)

def __str__(self):
return self.vulnerability_id or self.summary
Expand Down Expand Up @@ -149,14 +149,14 @@ def vulnerable_to(self):
"""
Returns vulnerabilities which are affecting this package.
"""
return self.vulnerabilities.all()
return self.vulnerabilities.filter(packagerelatedvulnerability__fix=False)

@property
def resolved_to(self):
"""
Returns the vulnerabilities which this package is patched against.
"""
return self.resolved_vulnerabilities.all().distinct()
return self.vulnerabilities.filter(packagerelatedvulnerability__fix=True)

class Meta:
unique_together = ("name", "namespace", "type", "version", "qualifiers", "subpath")
Expand Down
9 changes: 5 additions & 4 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from django.core.paginator import Paginator
from django.db.models import Count
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.urls import reverse
Expand Down Expand Up @@ -73,8 +74,8 @@ def request_to_queryset(request):
models.Package.objects.all()
.filter(name__icontains=package_name, type__icontains=package_type)
.annotate(
vulnerability_count=Count("vulnerabilities"),
patched_vulnerability_count=Count("resolved_vulnerabilities"),
vulnerability_count=Count("vulnerabilities", filter=Q(vulnerabilities__packagerelatedvulnerability__fix=False)),
patched_vulnerability_count=Count("vulnerabilities",filter=Q(vulnerabilities__packagerelatedvulnerability__fix=True)),
)
.prefetch_related()
)
Expand All @@ -101,8 +102,8 @@ def request_to_vulnerabilities(request):
vuln_id = request.GET["vuln_id"]
return list(
models.Vulnerability.objects.filter(vulnerability_id__icontains=vuln_id).annotate(
vulnerable_package_count=Count("vulnerable_packages"),
patched_package_count=Count("patched_packages"),
vulnerable_package_count=Count("packages", filter=Q(packagerelatedvulnerability__fix=False)),
patched_package_count=Count("packages", filter=Q(packagerelatedvulnerability__fix=True)),
)
)

Expand Down

0 comments on commit 1834ef0

Please sign in to comment.