diff --git a/vulnerabilities/api_v2.py b/vulnerabilities/api_v2.py index 10ffb6d98..b9424ffbd 100644 --- a/vulnerabilities/api_v2.py +++ b/vulnerabilities/api_v2.py @@ -141,7 +141,7 @@ def get_queryset(self): if aliases: queryset = queryset.filter(aliases__alias__in=aliases).distinct() - return queryset + return queryset.order_by("-aliases__alias") def get_serializer_class(self): if self.action == "list": @@ -284,7 +284,7 @@ def get_queryset(self): queryset = queryset.filter( fixing_vulnerabilities__vulnerability_id=fixing_vulnerability ) - return queryset.with_is_vulnerable() + return queryset.with_is_vulnerable().order_by("type", "namespace", "name", "-version") def list(self, request, *args, **kwargs): queryset = self.get_queryset() @@ -427,8 +427,8 @@ def bulk_search(self, request): query = ( Package.objects.filter(plain_package_url__in=plain_purls) - .order_by("plain_package_url") - .distinct("plain_package_url") + .order_by("type", "namespace", "name", "-version") + .distinct("type", "namespace", "name", "version") .with_is_vulnerable() ) @@ -498,8 +498,8 @@ def all(self, request): vulnerable_purls = ( Package.objects.vulnerable() .only("package_url") - .order_by("package_url") - .distinct() + .order_by("type", "namespace", "name", "-version") + .distinct("type", "namespace", "name", "version") .values_list("package_url", flat=True) ) return Response(vulnerable_purls) diff --git a/vulnerabilities/views.py b/vulnerabilities/views.py index a2df48634..3be0cf0e4 100644 --- a/vulnerabilities/views.py +++ b/vulnerabilities/views.py @@ -62,14 +62,14 @@ def get_queryset(self, query=None): self.model.objects.search(query) .with_vulnerability_counts() .prefetch_related() - .order_by("package_url") + .order_by("type", "namespace", "name", "-version") ) class VulnerabilitySearch(ListView): model = models.Vulnerability template_name = "vulnerabilities.html" - ordering = ["vulnerability_id"] + ordering = ["aliases"] paginate_by = PAGE_SIZE def get_context_data(self, **kwargs): @@ -81,7 +81,7 @@ def get_context_data(self, **kwargs): def get_queryset(self, query=None): query = query or self.request.GET.get("search") or "" - return self.model.objects.search(query=query).with_package_counts() + return self.model.objects.search(query=query).with_package_counts().order_by("-aliases") class PackageDetails(DetailView): @@ -94,10 +94,10 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) package = self.object context["package"] = package - context["affected_by_vulnerabilities"] = package.affected_by.order_by("vulnerability_id") + context["affected_by_vulnerabilities"] = package.affected_by.order_by("-aliases") # Ghost package should not fix any vulnerability. context["fixing_vulnerabilities"] = ( - None if package.is_ghost else package.fixing.order_by("vulnerability_id") + None if package.is_ghost else package.fixing.order_by("-aliases") ) context["package_search_form"] = PackageSearchForm(self.request.GET) context["fixed_package_details"] = package.fixed_package_details