Skip to content

Commit c8ba591

Browse files
committed
Refine navigation and URLs #907
* Use search as form field name consistently #907 This replaces the vulnerability_id and package_name and esnure we have a better looking URL with a "search" query string. * Also make "search" a required field and use standard HTML for validation. Remove JS validations. * Use vulnerability_id rather than PK for URL in templates * Remove redundant, repeat display of search queries. * Rename "Total records" to "results" in search results pages Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 1c14803 commit c8ba591

File tree

11 files changed

+58
-145
lines changed

11 files changed

+58
-145
lines changed

vulnerabilities/forms.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ def get_known_package_types():
2323

2424
class PackageForm(forms.Form):
2525

26-
package_name = forms.CharField(
27-
required=False, widget=forms.TextInput(attrs={"placeholder": "Package name or purl"})
26+
search = forms.CharField(
27+
required=True,
28+
widget=forms.TextInput(
29+
attrs={"placeholder": "Package name, purl or purl fragment"},
30+
),
2831
)
2932

3033

3134
class VulnerabilityForm(forms.Form):
3235

33-
vulnerability_id = forms.CharField(
34-
required=False,
36+
search = forms.CharField(
37+
required=True,
3538
widget=forms.TextInput(
3639
attrs={"placeholder": "Vulnerability id or alias such as CVE or GHSA"}
3740
),

vulnerabilities/templates/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@
1212
{% include "vulnerability_search_box.html" %}
1313
</section>
1414
{% endblock %}
15-
16-
{% block scripts %}
17-
{% include "validate_form_scripts.html" %}
18-
{% endblock %}

vulnerabilities/templates/package_details.html

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,7 @@
1919
<div class="details-container">
2020
<article class="panel is-info panel-header-only">
2121
<div class="panel-heading py-2 is-size-6">
22-
<div class="field is-grouped is-grouped-multiline">
2322
Package details:
24-
<div class="control">
25-
<div class="tags has-addons">
26-
<span class="tag is-black custom">purl</span>
27-
<span class="tag is-white custom">
28-
{{ package.package_url }}
29-
</span>
30-
</div>
31-
</div>
32-
</div>
3323
</div>
3424
</article>
3525

@@ -38,7 +28,12 @@
3828
<tbody>
3929
<tr>
4030
<td class="two-col-left">
41-
<span class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left" data-tooltip="The package url or purl is a URL string used to identify and locate a software package.">purl</span>
31+
<span
32+
class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left"
33+
data-tooltip="The package url or purl is a URL string used to identify and locate a software package."
34+
>
35+
purl
36+
</span>
4237
</td>
4338
<td class="two-col-right">
4439
{{ package.package_url }}
@@ -71,7 +66,7 @@
7166
{% for vuln in impacted_vuln %}
7267
<tr>
7368
<td>
74-
<a href="{% url 'vulnerability_view' vuln.pk %}?vulnerability_id={{ vuln.vulnerability_id }}" target="_self">{{ vuln.vulnerability_id }}</a>
69+
<a href="{{ vulnerability.get_absolute_url }}" target="_self">{{ vuln.vulnerability_id }}</a>
7570
</td>
7671
<td>
7772
{{ vuln.summary }}
@@ -123,7 +118,7 @@
123118
{% for vuln in resolved_vuln %}
124119
<tr>
125120
<td>
126-
<a href="{% url 'vulnerability_view' vuln.pk %}?vulnerability_id={{ vuln.vulnerability_id }}" target="_self">{{ vuln.vulnerability_id }}</a>
121+
<a href="{{ vuln.get_absolute_url }}" target="_self">{{ vuln.vulnerability_id }}</a>
127122
</td>
128123
<td>
129124
{{ vuln.summary }}
@@ -144,7 +139,7 @@
144139
{% else %}
145140
<tr>
146141
<td colspan="3">
147-
This package does not fix any vulnerabilities.
142+
This package is not known to fix vulnerabilities.
148143
</td>
149144
</tr>
150145
{% endif %}
@@ -156,7 +151,3 @@
156151
{% endif %}
157152

158153
{% endblock %}
159-
160-
{% block scripts %}
161-
{% include "validate_form_scripts.html" %}
162-
{% endblock %}

vulnerabilities/templates/package_search_box.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Package URL
1818
</a>
1919
(aka. <strong>purl</strong>) such as <strong>pkg:maven/org.apache.logging.log4j/[email protected]</strong>
20+
or purl prefix fragment such as <strong>pkg:alpine</strong>
2021
or by package <strong>name</strong>.
2122
</div>
2223
</div>
@@ -29,12 +30,11 @@
2930
<form
3031
action="{% url 'package_search' %}"
3132
method="get"
32-
name="pkg_form"
33-
onsubmit="return validatePkgForm()"
33+
name="package_form"
3434
>
3535
<div class="field has-addons mt-3">
3636
<div class="control width-100-pct">
37-
{{ package_form.package_name|add_class:"input" }}
37+
{{ package_form.search|add_class:"input" }}
3838
</div>
3939
<div class="control">
4040
<button class="button is-link" type="submit" id="submit_pkg">
@@ -43,14 +43,6 @@
4343
</div>
4444
</div>
4545
</form>
46-
<div>
47-
{% if package_search %}
48-
<div class="notification search-alert">
49-
<button class=" delete"></button>
50-
{{ package_search }}
51-
</div>
52-
{% endif %}
53-
</div>
5446
</div>
5547
</div>
5648
</article>

vulnerabilities/templates/packages.html

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,17 @@
1414
{% include "package_search_box.html" %}
1515
</section>
1616

17-
{% if package_name %}
17+
{% if search %}
1818
<div class="is-max-desktop mb-3">
1919
<section class="mx-5">
20-
<article class="panel is-info panel-header-only">
21-
<div class="panel-heading py-2 is-size-6">
22-
<div class="field is-grouped is-grouped-multiline">
23-
Package search results:
24-
<div class="control">
25-
<div class="tags has-addons">
26-
<span class="tag is-white custom">
27-
{{ package_name }}
28-
</span>
29-
</div>
30-
</div>
31-
</div>
32-
</div>
33-
</article>
34-
3520
<div class="is-flex" style="justify-content: space-between;">
3621
<div>
37-
<strong>Total records:</strong> {{ page_obj.paginator.count|intcomma }}
22+
{{ page_obj.paginator.count|intcomma }} results
3823
</div>
3924
<div>
4025
{% if page_obj.has_previous %}
41-
<a class="small_page_button" href="?package_name={{ package_name }}&page=1">1</a>
42-
<a class="page_arrow_spacing" href="?package_name={{ package_name }}&page={{ page_obj.previous_page_number }}">&laquo;</a>
26+
<a class="small_page_button" href="?search={{ search }}&page=1">1</a>
27+
<a class="page_arrow_spacing" href="?search={{ search }}&page={{ page_obj.previous_page_number }}">&laquo;</a>
4328
{% else %}
4429
<span class="small_page_button">1</span>
4530
<span class="page_arrow_spacing">&laquo;</span>
@@ -48,11 +33,11 @@
4833
{% if page_obj.has_next %}
4934
<a
5035
class="page_arrow_spacing"
51-
href="?package_name={{ package_name }}&page={{ page_obj.next_page_number }}">&raquo;
36+
href="?search={{ search }}&page={{ page_obj.next_page_number }}">&raquo;
5237
</a>
5338
<a
5439
class="small_page_button"
55-
href="?package_name={{ package_name }}&page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages|intcomma }}
40+
href="?search={{ search }}&page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages|intcomma }}
5641
</a>
5742
{% else %}
5843
<span class="page_arrow_spacing">&raquo;</span>
@@ -96,7 +81,7 @@
9681
<tr>
9782
<td style="word-break: break-all;">
9883
<a
99-
href="{% url 'package_view' package.pk %}?package_name={{ package.package_url }}"
84+
href="{% url 'package_view' package.pk %}?search={{ search }}&purl={{ package.package_url }}"
10085
target="_self">{{ package.package_url }}</a>
10186
</td>
10287
<td>{{ package.vulnerability_count }}</td>
@@ -115,13 +100,13 @@
115100

116101
<nav class="pagination is-centered is-small" aria-label="pagination">
117102
{% if page_obj.has_previous %}
118-
<a href="?package_name={{ package_name }}&page={{ page_obj.previous_page_number }}" class="pagination-previous">Previous</a>
103+
<a href="?search={{ search }}&page={{ page_obj.previous_page_number }}" class="pagination-previous">Previous</a>
119104
{% else %}
120105
<a class="pagination-previous" disabled>Previous</a>
121106
{% endif %}
122107

123108
{% if page_obj.has_next %}
124-
<a href="?package_name={{ package_name }}&page={{ page_obj.next_page_number }}" class="pagination-next">Next</a>
109+
<a href="?search={{ search }}&page={{ page_obj.next_page_number }}" class="pagination-next">Next</a>
125110
{% else %}
126111
<a class="pagination-next" disabled>Next</a>
127112
{% endif %}
@@ -130,7 +115,7 @@
130115
{% if page_obj.number != 1%}
131116
<li>
132117
<a
133-
href="?package_name={{ package_name }}&page=1{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
118+
href="?search={{ search }}&page=1{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
134119
class="pagination-link"
135120
aria-label="Goto page 1">1
136121
</a>
@@ -156,7 +141,7 @@
156141
{% endif %}
157142
<li>
158143
<a
159-
href="?package_name={{ package_name }}&page={{ page_obj.paginator.num_pages }}{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
144+
href="?search={{ search }}&page={{ page_obj.paginator.num_pages }}{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
160145
class="pagination-link"
161146
aria-label="Goto page {{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages|intcomma }}
162147
</a>
@@ -168,7 +153,3 @@
168153
</section>
169154
{% endif %}
170155
{% endblock %}
171-
172-
{% block scripts %}
173-
{% include "validate_form_scripts.html" %}
174-
{% endblock %}

vulnerabilities/templates/validate_form_scripts.html

Lines changed: 0 additions & 26 deletions
This file was deleted.

vulnerabilities/templates/vulnerabilities.html

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,28 @@
1414
{% include "vulnerability_search_box.html" %}
1515
</section>
1616

17-
{% if vulnerability_id %}
17+
{% if search %}
1818
<div class="is-max-desktop mb-3">
1919
<section class="mx-5">
2020
<article class="panel is-info panel-header-only">
2121
<div class="panel-heading py-2 is-size-6">
22-
<div class="field is-grouped is-grouped-multiline">
23-
Vulnerability search results:
24-
<div class="control">
25-
<div class="tags">
26-
<span class="tag is-white custom">
27-
{{ vulnerability_id }}
28-
</span>
29-
</div>
30-
</div>
31-
</div>
22+
Vulnerability search results:
3223
</div>
3324
</article>
3425
<div class="is-flex" style="justify-content: space-between;">
3526
<div>
36-
<strong>Total records:</strong> {{ page_obj.paginator.count|intcomma }}
27+
{{ page_obj.paginator.count|intcomma }} results
3728
</div>
3829
<div>
3930
{% if page_obj.has_previous %}
4031
<a
4132
class="small_page_button"
42-
href="?vulnerability_id={{ vulnerability_id }}&page=1">
33+
href="?search={{ search }}&page=1">
4334
1
4435
</a>
4536
<a
4637
class="page_arrow_spacing"
47-
href="?vulnerability_id={{ vulnerability_id }}&page={{ page_obj.previous_page_number }}">
38+
href="?search={{ search }}&page={{ page_obj.previous_page_number }}">
4839
&laquo;
4940
</a>
5041
{% else %}
@@ -60,7 +51,7 @@
6051
</a>
6152
<a
6253
class="small_page_button"
63-
href="?vulnerability_id={{ vulnerability_id }}&page={{ page_obj.paginator.num_pages }}">
54+
href="?search={{ search }}&page={{ page_obj.paginator.num_pages }}">
6455
{{ page_obj.paginator.num_pages|intcomma }}
6556
</a>
6657
{% else %}
@@ -88,7 +79,7 @@
8879
<tr class="is-clipped-list">
8980
<td style="word-break: break-all;">
9081
<a
91-
href="{% url 'vulnerability_view' vulnerability.pk %}?vulnerability_id={{ vulnerability.vulnerability_id }}"
82+
href="{{ vulnerability.get_absolute_url }}?search={{ search }}"
9283
target="_self">{{ vulnerability.vulnerability_id }}
9384
</a>
9485
</td>
@@ -121,7 +112,7 @@
121112
<nav class="pagination is-centered is-small" aria-label="pagination">
122113
{% if page_obj.has_previous %}
123114
<a
124-
href="?vulnerability_id={{ vulnerability_id }}&page={{ page_obj.previous_page_number }}"
115+
href="?search={{ search }}&page={{ page_obj.previous_page_number }}"
125116
class="pagination-previous">
126117
Previous
127118
</a>
@@ -130,7 +121,7 @@
130121
{% endif %}
131122

132123
{% if page_obj.has_next %}
133-
<a href="?vulnerability_id={{ vulnerability_id }}&page={{ page_obj.next_page_number }}"
124+
<a href="?search={{ search }}&page={{ page_obj.next_page_number }}"
134125
class="pagination-next">
135126
Next
136127
</a>
@@ -142,7 +133,7 @@
142133
{% if page_obj.number != 1 %}
143134
<li>
144135
<a
145-
href="?vulnerability_id={{ vulnerability_id }}&page=1{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
136+
href="?search={{ search }}&page=1{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
146137
class="pagination-link"
147138
aria-label="Goto page 1">
148139
1
@@ -171,7 +162,7 @@
171162
{% endif %}
172163
<li>
173164
<a
174-
href="?vulnerability_id={{ vulnerability_id }}&page={{ page_obj.paginator.num_pages }}{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
165+
href="?search={{ search }}&page={{ page_obj.paginator.num_pages }}{% if url_params_without_page %}&{{ url_params_without_page }}{% endif %}"
175166
class="pagination-link"
176167
aria-label="Goto page {{ page_obj.paginator.num_pages }}">
177168
{{ page_obj.paginator.num_pages|intcomma }}
@@ -186,8 +177,6 @@
186177
{% endblock %}
187178

188179
{% block scripts %}
189-
{% include "validate_form_scripts.html" %}
190-
191180
<script>
192181
let $showClippedButton = getAll("button.show-clipped");
193182

0 commit comments

Comments
 (0)