From b2c009080dedfadd88a9345496a32418d0e946be Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 3 Aug 2022 07:20:30 +0100 Subject: [PATCH] Properly handle redactions --- core/lib/opensearch.py | 8 ++++++-- core/templates/ui/drilldown/results.html | 18 +++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 6dfa918..64bd8b4 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -104,15 +104,19 @@ def filter_blacklisted(user, response): response["redacted"] += 1 # Anonymous if user.is_anonymous: - response["hits"]["hits"].remove(item) + # Just set it to none so the index is not off + response["hits"]["hits"][index] = None else: if not user.is_superuser: - response["hits"]["hits"].remove(item) + response["hits"]["hits"][index] = None else: response["hits"]["hits"][index]["_source"][ "exemption" ] = True + # Actually get rid of all the things we set to None + response["hits"]["hits"] = [hit for hit in response["hits"]["hits"] if hit] + def run_main_query(client, user, query, custom_query=False, index=None, size=None): """ diff --git a/core/templates/ui/drilldown/results.html b/core/templates/ui/drilldown/results.html index 207c751..d31648f 100644 --- a/core/templates/ui/drilldown/results.html +++ b/core/templates/ui/drilldown/results.html @@ -10,22 +10,18 @@
-

{{ card }} hits

-
- {% if redacted != 0 %} -
-

{{ redacted }} redacted

-
- {% endif %} - - -
-

{{ took }}ms

+

fetched {{ results|length }} of {{ card }} hits in {{ took }}ms

{% if exemption is not None %}
+ {% else %} + {% if redacted != 0 %} +
+

{{ redacted }} redacted

+
+ {% endif %} {% endif %}