Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Descending Sorting for Packages and Vulnerabilities in API and UI #1758

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions vulnerabilities/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
)

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down