Skip to content

Commit 1834ef0

Browse files
committed
Fix UI break
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>
1 parent 9fceb51 commit 1834ef0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

vulnerabilities/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ def vulnerable_to(self):
8989
"""
9090
Returns packages which are vulnerable to this vulnerability.
9191
"""
92-
return self.vulnerable_packages.all()
92+
return self.packages.filter(vulnerabilities__packagerelatedvulnerability__fix=False)
9393

9494
@property
9595
def resolved_to(self):
9696
"""
9797
Returns packages, which first received patch against this vulnerability
9898
in their particular version history.
9999
"""
100-
return self.patched_packages.all().distinct()
100+
return self.packages.filter(vulnerabilities__packagerelatedvulnerability__fix=True)
101101

102102
def __str__(self):
103103
return self.vulnerability_id or self.summary
@@ -149,14 +149,14 @@ def vulnerable_to(self):
149149
"""
150150
Returns vulnerabilities which are affecting this package.
151151
"""
152-
return self.vulnerabilities.all()
152+
return self.vulnerabilities.filter(packagerelatedvulnerability__fix=False)
153153

154154
@property
155155
def resolved_to(self):
156156
"""
157157
Returns the vulnerabilities which this package is patched against.
158158
"""
159-
return self.resolved_vulnerabilities.all().distinct()
159+
return self.vulnerabilities.filter(packagerelatedvulnerability__fix=True)
160160

161161
class Meta:
162162
unique_together = ("name", "namespace", "type", "version", "qualifiers", "subpath")

vulnerabilities/views.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from django.core.paginator import Paginator
2626
from django.db.models import Count
27+
from django.db.models import Q
2728
from django.http import HttpResponse
2829
from django.shortcuts import render, redirect
2930
from django.urls import reverse
@@ -73,8 +74,8 @@ def request_to_queryset(request):
7374
models.Package.objects.all()
7475
.filter(name__icontains=package_name, type__icontains=package_type)
7576
.annotate(
76-
vulnerability_count=Count("vulnerabilities"),
77-
patched_vulnerability_count=Count("resolved_vulnerabilities"),
77+
vulnerability_count=Count("vulnerabilities", filter=Q(vulnerabilities__packagerelatedvulnerability__fix=False)),
78+
patched_vulnerability_count=Count("vulnerabilities",filter=Q(vulnerabilities__packagerelatedvulnerability__fix=True)),
7879
)
7980
.prefetch_related()
8081
)
@@ -101,8 +102,8 @@ def request_to_vulnerabilities(request):
101102
vuln_id = request.GET["vuln_id"]
102103
return list(
103104
models.Vulnerability.objects.filter(vulnerability_id__icontains=vuln_id).annotate(
104-
vulnerable_package_count=Count("vulnerable_packages"),
105-
patched_package_count=Count("patched_packages"),
105+
vulnerable_package_count=Count("packages", filter=Q(packagerelatedvulnerability__fix=False)),
106+
patched_package_count=Count("packages", filter=Q(packagerelatedvulnerability__fix=True)),
106107
)
107108
)
108109

0 commit comments

Comments
 (0)