Skip to content

Commit 59560df

Browse files
authored
feat(admin): sort malware reports by count (#19540)
In order to identify corroborated reports more easily, add the count to the data table as a hidden column, and then sort by it. This way, any corroborated reports float to the top, making them more prominently found for reviews. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
1 parent 031d585 commit 59560df

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

tests/unit/admin/views/test_malware_reports.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@
2020

2121
class TestMalwareReportsList:
2222
def test_malware_reports_list(self, db_request):
23-
assert views.malware_reports_list(db_request) == {"malware_reports": []}
23+
result = views.malware_reports_list(db_request)
24+
assert result["malware_reports"] == []
25+
assert result["report_counts"] == {}
2426

2527
def test_malware_reports_list_with_observations(self, db_request):
2628
ProjectObservationFactory.create(kind="is_spam")
2729
ProjectObservationFactory.create(kind="is_malware", actions={"foo": "bar"})
2830
ProjectObservationFactory.create(kind="is_malware", related=None)
29-
malware = ProjectObservationFactory.create_batch(size=3, kind="is_malware")
31+
project = ProjectFactory.create()
32+
malware = ProjectObservationFactory.create_batch(
33+
size=3, kind="is_malware", related=project
34+
)
3035

31-
malware_reports = views.malware_reports_list(db_request)["malware_reports"]
32-
assert {m.id for m in malware_reports} == {m.id for m in malware}
36+
result = views.malware_reports_list(db_request)
37+
assert {m.id for m in result["malware_reports"]} == {m.id for m in malware}
38+
assert result["report_counts"][project.id] == 3
3339

3440

3541
class TestMalwareReportsProjectList:

warehouse/admin/static/js/warehouse.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ if (malwareReportsTable.length) {
175175
let table = malwareReportsTable.DataTable({
176176
displayLength: 25,
177177
lengthChange: false,
178-
order: [[0, "asc"], [2, "desc"]], // alpha name, recent date
178+
order: [[1, "desc"], [0, "asc"], [3, "desc"]], // report count, alpha name, recent date
179179
responsive: true,
180180
rowGroup: {
181181
dataSrc: 0,
@@ -185,8 +185,8 @@ if (malwareReportsTable.length) {
185185
},
186186
},
187187
});
188-
// hide the project name, since it's in the group title
189-
table.columns([0]).visible(false);
188+
// hide the project name and count, since they're in the group title
189+
table.columns([0, 1]).visible(false);
190190
new $.fn.dataTable.Buttons(table, {buttons: ["copy", "csv", "colvis"]});
191191
table.buttons().container().appendTo($(".col-md-6:eq(0)", table.table().container()));
192192
}

warehouse/admin/templates/admin/malware_reports/list.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ <h3 class="card-title">Malware Reports</h3>
2323
<thead>
2424
<tr>
2525
<th>Project Name</th>
26+
<th>Reports</th>
2627
<th>Summary</th>
2728
<th>Created</th>
2829
<th>Reported By</th>
@@ -37,6 +38,7 @@ <h3 class="card-title">Malware Reports</h3>
3738
{{ report.related.name }}
3839
</a>
3940
</td>
41+
<td>{{ report_counts[report.related_id] }}</td>
4042
<td>{{ report.summary }}</td>
4143
<td>
4244
<time datetime="{{ report.created }}">{{ report.created }}</time>

warehouse/admin/views/malware_reports.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import re
88

9+
from collections import Counter
910
from datetime import datetime, timezone
1011
from typing import TYPE_CHECKING
1112

@@ -54,7 +55,9 @@ def malware_reports_list(request):
5455
.all()
5556
)
5657

57-
return {"malware_reports": malware_observations}
58+
report_counts = Counter(obs.related_id for obs in malware_observations)
59+
60+
return {"malware_reports": malware_observations, "report_counts": report_counts}
5861

5962

6063
@view_config(

0 commit comments

Comments
 (0)