Fix ZNC queries

This commit is contained in:
Mark Veidemanis 2022-08-15 17:59:09 +01:00
parent c9fe1f0b73
commit 4be21cb488
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 41 additions and 23 deletions

View File

@ -1,4 +1,4 @@
def construct_query(index, net, channel, src, num, size, nicks=None): def construct_query(index, net, channel, src, num, size, type=None, nicks=None):
# Get the initial query # Get the initial query
extra_must = [] extra_must = []
extra_should = [] extra_should = []
@ -26,8 +26,14 @@ def construct_query(index, net, channel, src, num, size, nicks=None):
] ]
if index == "int": if index == "int":
fields.append("mtype") fields.append("mtype")
for ctype in types: if channel == "*status" or type == "znc":
extra_should.append({"match": {"mtype": ctype}}) if {"match": {"channel": channel}} in extra_must:
extra_must.remove({"match": {"channel": channel}})
extra_should2 = []
extra_must.append({"match": {"type": "znc"}})
else:
for ctype in types:
extra_should.append({"match": {"mtype": ctype}})
else: else:
for ctype in types: for ctype in types:
extra_should.append({"match": {"type": ctype}}) extra_should.append({"match": {"type": ctype}})
@ -54,5 +60,4 @@ def construct_query(index, net, channel, src, num, size, nicks=None):
"fields": fields, "fields": fields,
"_source": False, "_source": False,
} }
return query return query

View File

@ -104,15 +104,15 @@
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context' %}" hx-post="{% url 'modal_context' %}"
hx-vals='{"net": "{{ net }}", hx-vals='{"net": "{{ net }}",
"num": "{{ relay.id }}", "num": "{{ relay.id }}",
"src": "irc", "src": "irc",
"channel": "None", "channel": "*status",
"time": "None", "time": "None",
"date": "None", "date": "None",
"index": "int", "index": "int",
"type": "znc", "type": "znc",
"mtype": "None", "mtype": "None",
"nick": "None"}' "nick": "*status"}'
hx-target="#modals-here" hx-target="#modals-here"
hx-trigger="click" hx-trigger="click"
class="button is-small has-background-info has-text-white"> class="button is-small has-background-info has-text-white">
@ -120,7 +120,7 @@
<i class="fa-brands fa-unity" aria-hidden="true"></i> <i class="fa-brands fa-unity" aria-hidden="true"></i>
</span> </span>
</a> </a>
</td> {# actions-top #} </td>
</tr> </tr>
<tr> <tr>
<td> <td>
@ -134,7 +134,7 @@
<i class="fa-solid fa-xmark" aria-hidden="true"></i> <i class="fa-solid fa-xmark" aria-hidden="true"></i>
</span> </span>
</a> </a>
</td> {# id #} </td>
<td> <td>
<a <a
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
@ -146,7 +146,7 @@
<i class="fa-solid fa-wrench" aria-hidden="true"></i> <i class="fa-solid fa-wrench" aria-hidden="true"></i>
</span> </span>
</a> </a>
</td> {# reg #} </td>
<td> <td>
<a <a
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
@ -158,8 +158,8 @@
<i class="fa-solid fa-passport" aria-hidden="true"></i> <i class="fa-solid fa-passport" aria-hidden="true"></i>
</span> </span>
</a> </a>
</td> {# auth #} </td>
<td></td> {# conn #} <td></td>
<td> <td>
{% if relay.enabled %} {% if relay.enabled %}
<a <a
@ -184,7 +184,7 @@
</span> </span>
</a> </a>
{% endif %} {% endif %}
</td> {# on #} </td>
<td></td> <td></td>
<td></td> <td></td>
<td></td> <td></td>
@ -199,7 +199,7 @@
<i class="fa-solid fa-signature" aria-hidden="true"></i> <i class="fa-solid fa-signature" aria-hidden="true"></i>
</span> </span>
</a> </a>
</td> {# actions-bottom #} </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -104,7 +104,7 @@ class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
def get(self, request, net): def get(self, request, net):
relays = threshold.get_irc_relays(net) relays = threshold.get_irc_relays(net)
context = {"relays": relays["relays"]} context = {"net": net, "relays": relays["relays"]}
return render(request, self.template_name, context) return render(request, self.template_name, context)

View File

@ -253,7 +253,7 @@ class DrilldownContextModal(APIView):
size = 20 size = 20
nicks = None nicks = None
# Create the query params from the POST arguments # Create the query params from the POST arguments
mandatory = ["net", "channel", "num", "src", "index", "nick"] mandatory = ["net", "channel", "num", "src", "index", "nick", "type"]
invalid = [None, False, "", "None"] invalid = [None, False, "", "None"]
query_params = {k: v for k, v in request.data.items() if v} query_params = {k: v for k, v in request.data.items() if v}
for key in query_params: for key in query_params:
@ -275,6 +275,13 @@ class DrilldownContextModal(APIView):
and not query_params["type"] == "query" and not query_params["type"] == "query"
): ):
query_params["index"] = "main" query_params["index"] = "main"
type = None
if "type" in query_params:
type = query_params["type"]
if type == "znc":
query_params["channel"] = "*status"
# Create the query with the context helper # Create the query with the context helper
search_query = construct_query( search_query = construct_query(
query_params["index"], query_params["index"],
@ -283,10 +290,16 @@ class DrilldownContextModal(APIView):
query_params["src"], query_params["src"],
query_params["num"], query_params["num"],
size, size,
type=type,
nicks=nicks, nicks=nicks,
) )
annotate = False
if query_params["src"] == "irc":
if query_params["type"] in ["query", "notice", "msg", "highlight"]:
annotate = True
results = query_results( results = query_results(
request, query_params, annotate=True, custom_query=search_query request, query_params, annotate=annotate, custom_query=search_query
) )
if "message" in results: if "message" in results:
return render(request, self.template_name, results) return render(request, self.template_name, results)