-
-
Notifications
You must be signed in to change notification settings - Fork 304
Option to filter Vulnerable and Non Vulnerable Packages #1760
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
9468680
5f88c3c
011ceec
c69ee1c
9c10e69
d32ef52
7cda435
0d27c7c
9db3464
d997268
8fad52e
2d11906
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,14 @@ | |
| <div> | ||
| {{ page_obj.paginator.count|intcomma }} results | ||
| </div> | ||
| <form method="get" style="display: inline;"> | ||
| {% if search %}<input type="hidden" name="search" value="{{ search }}">{% endif %} | ||
| <select name="vulnerable_only" class="select" id="vulnerable-select" onchange="this.form.submit()"> | ||
| <option value="">All Packages</option> | ||
| <option value="true" {% if request.GET.vulnerable_only == 'true' %}selected{% endif %}>Vulnerable Only</option> | ||
| <option value="false" {% if request.GET.vulnerable_only == 'false' %}selected{% endif %}>Non-Vulnerable Only</option> | ||
| </select> | ||
| </form> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is how we want to have filters, how about a filter icon to the left with drop-down with All, Non-vulnerable, Vulnerable options.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure would add that as well. |
||
| {% if is_paginated %} | ||
| {% include 'includes/pagination.html' with page_obj=page_obj %} | ||
| {% endif %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,12 +58,18 @@ def get_queryset(self, query=None): | |
| on exact purl, partial purl or just name and namespace. | ||
| """ | ||
| query = query or self.request.GET.get("search") or "" | ||
| return ( | ||
| queryset = ( | ||
| self.model.objects.search(query) | ||
| .with_vulnerability_counts() | ||
| .prefetch_related() | ||
| .order_by("package_url") | ||
| ) | ||
| if hasattr(self, "request"): | ||
| vulnerable_only = self.request.GET.get("vulnerable_only", "").lower() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be much cleaner to use a form instead?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes It would be clean as well as safer from XSS attacks.. would handle it from form. |
||
| if vulnerable_only in ["true", "false"]: | ||
| queryset = queryset.with_is_vulnerable() | ||
| queryset = queryset.filter(is_vulnerable=vulnerable_only == "true") | ||
| return queryset | ||
|
|
||
|
|
||
| class VulnerabilitySearch(ListView): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue description quotes if the same thing can be implemented in the API so I have added it in the API as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I get that we need filter in the API, but what I'm trying to understand is whether we need this
queryset = queryset.exclude(version="").