diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index ff8a316..bd8570b 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -392,19 +392,27 @@ def query_results( if index == "main": index = settings.OPENSEARCH_INDEX_MAIN else: - if request.user.is_superuser: - if index == "meta": - index = settings.OPENSEARCH_INDEX_META - elif index == "int": - index = settings.OPENSEARCH_INDEX_INT - else: - message = "Index is not valid." - message_class = "danger" - return {"message": message, "class": message_class} - else: + if not request.user.has_perm(f"index_{index}"): message = "Not permitted to search by this index" message_class = "danger" - return {"message": message, "class": message_class} + return { + "message": message, + "class": message_class, + "params": query_params, + } + if index == "meta": + index = settings.OPENSEARCH_INDEX_META + elif index == "int": + index = settings.OPENSEARCH_INDEX_INT + else: + message = "Index is not valid." + message_class = "danger" + return { + "message": message, + "class": message_class, + "params": query_params, + } + else: index = settings.OPENSEARCH_INDEX_MAIN diff --git a/core/models.py b/core/models.py index f647fee..0977534 100644 --- a/core/models.py +++ b/core/models.py @@ -113,4 +113,6 @@ class Perms(models.Model): ("post_irc", "Can post to IRC"), ("post_discord", "Can post to Discord"), ("query_search", "Can search with query strings"), + ("index_int", "Can use the internal index"), + ("index_meta", "Can use the meta index"), ) diff --git a/core/templates/ui/drilldown/drilldown.html b/core/templates/ui/drilldown/drilldown.html index ef2bf9b..30eea32 100644 --- a/core/templates/ui/drilldown/drilldown.html +++ b/core/templates/ui/drilldown/drilldown.html @@ -60,16 +60,12 @@ `${field}:${value}`, `${field}:"${value}"`]; var toAppend = ` AND ${field}: "${value}"`; - // var toRemove = `${field}: "${value}"`; - // var tagText = `${field}: ${value}`; } else { var combinations = [`NOT ${field}: "${value}"`, `NOT ${field}: "${value}"`, `NOT ${field}: ${value}`, `NOT ${field}:${value}`, `NOT ${field}:"${value}"`]; - // var toAppend = ` AND NOT ${field}: "${value}"`; - // var toRemove = `NOT ${field}: "${value}"`; } var contains = combinations.some(elem => queryElement.value.includes(elem)); if (!contains) { @@ -80,17 +76,8 @@ queryElement.value = queryElement.value.replaceAll("AND "+combination, ""); queryElement.value = queryElement.value.replaceAll(combination, ""); } - // queryElement.value = queryElement.value.replaceAll(toAppend, ""); - // queryElement.value = queryElement.value.replaceAll(toRemove, ""); - } - // if (!queryElement.value.includes(toAppend) && !queryElement.value.includes(toRemove)) { - // queryElement.value+=toAppend; - // } else { - // queryElement.value = queryElement.value.replaceAll(toAppend, ""); - // queryElement.value = queryElement.value.replaceAll(toRemove, ""); - // } if (field == "src") { document.getElementById("source").selectedIndex = 2; } @@ -104,6 +91,7 @@ }