Fix send message logic and tweak context queries for private messages
This commit is contained in:
parent
4be21cb488
commit
a38cfa4ef8
|
@ -257,11 +257,6 @@ urlpatterns = [
|
||||||
ThresholdIRCSendMessage.as_view(),
|
ThresholdIRCSendMessage.as_view(),
|
||||||
name="threshold_irc_msg",
|
name="threshold_irc_msg",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"manage/threshold/irc/msg/<str:net>/<int:num>/<str:nick>/",
|
|
||||||
ThresholdIRCSendMessage.as_view(),
|
|
||||||
name="threshold_irc_msg",
|
|
||||||
),
|
|
||||||
##
|
##
|
||||||
path("api/chans/", ThresholdChans.as_view(), name="chans"),
|
path("api/chans/", ThresholdChans.as_view(), name="chans"),
|
||||||
path("api/users/", ThresholdUsers.as_view(), name="users"),
|
path("api/users/", ThresholdUsers.as_view(), name="users"),
|
||||||
|
|
|
@ -30,7 +30,25 @@ def construct_query(index, net, channel, src, num, size, type=None, nicks=None):
|
||||||
if {"match": {"channel": channel}} in extra_must:
|
if {"match": {"channel": channel}} in extra_must:
|
||||||
extra_must.remove({"match": {"channel": channel}})
|
extra_must.remove({"match": {"channel": channel}})
|
||||||
extra_should2 = []
|
extra_should2 = []
|
||||||
extra_must.append({"match": {"type": "znc"}})
|
# Type is one of msg or notice
|
||||||
|
#extra_should.append({"match": {"mtype": "msg"}})
|
||||||
|
#extra_should.append({"match": {"mtype": "notice"}})
|
||||||
|
extra_should.append({"match": {"type": "znc"}})
|
||||||
|
extra_should.append({"match": {"type": "self"}})
|
||||||
|
|
||||||
|
extra_should2.append({"match": {"type": "znc"}})
|
||||||
|
#extra_should2.append({"match": {"channel": channel}})
|
||||||
|
elif type == "auth":
|
||||||
|
if {"match": {"channel": channel}} in extra_must:
|
||||||
|
extra_must.remove({"match": {"channel": channel}})
|
||||||
|
extra_should2 = []
|
||||||
|
extra_should2.append({"match": {"nick": channel}})
|
||||||
|
#extra_should2.append({"match": {"mtype": "msg"}})
|
||||||
|
#extra_should2.append({"match": {"mtype": "notice"}})
|
||||||
|
|
||||||
|
extra_should.append({"match": {"type": "query"}})
|
||||||
|
extra_should2.append({"match": {"type": "self"}})
|
||||||
|
extra_should.append({"match": {"nick": channel}})
|
||||||
else:
|
else:
|
||||||
for ctype in types:
|
for ctype in types:
|
||||||
extra_should.append({"match": {"mtype": ctype}})
|
extra_should.append({"match": {"mtype": ctype}})
|
||||||
|
|
|
@ -196,6 +196,7 @@ def send_irc_message(net, num, channel, msg, nick=None):
|
||||||
payload = {"msg": msg, "channel": channel}
|
payload = {"msg": msg, "channel": channel}
|
||||||
if nick:
|
if nick:
|
||||||
payload["nick"] = nick
|
payload["nick"] = nick
|
||||||
|
print("SEND", payload)
|
||||||
messaged = threshold_request(url, payload, method="PUT")
|
messaged = threshold_request(url, payload, method="PUT")
|
||||||
return messaged
|
return messaged
|
||||||
|
|
||||||
|
@ -250,3 +251,10 @@ def irc_check_auth(data):
|
||||||
payload = data
|
payload = data
|
||||||
updated = threshold_request(url, payload, method="POST")
|
updated = threshold_request(url, payload, method="POST")
|
||||||
return updated
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
def get_irc_sinst(net):
|
||||||
|
url = f"irc/sinst/{net}"
|
||||||
|
payload = {}
|
||||||
|
authentity = threshold_request(url, payload, method="GET")
|
||||||
|
return authentity
|
||||||
|
|
|
@ -191,11 +191,21 @@
|
||||||
<td>
|
<td>
|
||||||
<a
|
<a
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-post="{% url 'threshold_irc_network_relay_auth' relay|index:'net' relay|index:'id' %}"
|
hx-post="{% url 'modal_context' %}"
|
||||||
hx-target="#relays"
|
hx-vals='{"net": "{{ net }}",
|
||||||
hx-swap="outerHTML"
|
"num": "{{ relay.id }}",
|
||||||
|
"src": "irc",
|
||||||
|
"channel": "{{ sinst.entity }}",
|
||||||
|
"time": "None",
|
||||||
|
"date": "None",
|
||||||
|
"index": "int",
|
||||||
|
"type": "auth",
|
||||||
|
"mtype": "None",
|
||||||
|
"nick": "{{ sinst.entity }}"}'
|
||||||
|
hx-target="#modals-here"
|
||||||
|
hx-trigger="click"
|
||||||
class="button is-small has-background-info has-text-white">
|
class="button is-small has-background-info has-text-white">
|
||||||
<span class="icon has-tooltip-left" data-tooltip="Auth entity context">
|
<span class="icon has-tooltip-left" data-tooltip="Auth ({{ sinst.entity }})">
|
||||||
<i class="fa-solid fa-signature" aria-hidden="true"></i>
|
<i class="fa-solid fa-signature" aria-hidden="true"></i>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -104,7 +104,11 @@ 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)
|
||||||
|
sinst = threshold.get_irc_sinst(net)
|
||||||
context = {"net": net, "relays": relays["relays"]}
|
context = {"net": net, "relays": relays["relays"]}
|
||||||
|
if sinst:
|
||||||
|
if sinst["success"]:
|
||||||
|
context["sinst"] = sinst["sinst"]
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -693,7 +697,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
parser_classes = [FormParser]
|
parser_classes = [FormParser]
|
||||||
template_name = "partials/context-input.html"
|
template_name = "partials/context-input.html"
|
||||||
|
|
||||||
def put(self, request, net, num, nick=None):
|
def put(self, request, net, num):
|
||||||
"""
|
"""
|
||||||
Send a message
|
Send a message
|
||||||
"""
|
"""
|
||||||
|
@ -713,6 +717,9 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
self.template_name,
|
self.template_name,
|
||||||
{"message": message, "class": message_class},
|
{"message": message, "class": message_class},
|
||||||
)
|
)
|
||||||
|
nick = None
|
||||||
|
if "nick" in request.data:
|
||||||
|
nick = request.data["nick"]
|
||||||
if nick:
|
if nick:
|
||||||
messaged = threshold.send_irc_message(
|
messaged = threshold.send_irc_message(
|
||||||
net, num, request.data["channel"], request.data["msg"], nick=nick
|
net, num, request.data["channel"], request.data["msg"], nick=nick
|
||||||
|
|
|
@ -255,26 +255,18 @@ class DrilldownContextModal(APIView):
|
||||||
# Create the query params from the POST arguments
|
# Create the query params from the POST arguments
|
||||||
mandatory = ["net", "channel", "num", "src", "index", "nick", "type"]
|
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}
|
||||||
|
|
||||||
|
if query_params["index"] == "int":
|
||||||
|
mandatory.append("mtype")
|
||||||
|
|
||||||
for key in query_params:
|
for key in query_params:
|
||||||
if query_params[key] in invalid:
|
if query_params[key] in invalid:
|
||||||
query_params[key] = None
|
query_params[key] = None
|
||||||
for key in mandatory:
|
for key in mandatory:
|
||||||
if key not in query_params:
|
if key not in query_params:
|
||||||
query_params[key] = None
|
query_params[key] = None
|
||||||
if query_params["index"] == "int":
|
|
||||||
if "mtype" not in query_params:
|
|
||||||
query_params["mtype"] = None
|
|
||||||
if request.user.is_superuser:
|
|
||||||
if query_params["type"] in ["query", "notice"]:
|
|
||||||
nicks = [query_params["channel"], query_params["nick"]]
|
|
||||||
query_params["sorting"] = "desc"
|
|
||||||
if (
|
|
||||||
query_params["index"] == "int"
|
|
||||||
and query_params["mtype"] == "msg"
|
|
||||||
and not query_params["type"] == "query"
|
|
||||||
):
|
|
||||||
query_params["index"] = "main"
|
|
||||||
|
|
||||||
type = None
|
type = None
|
||||||
if "type" in query_params:
|
if "type" in query_params:
|
||||||
|
@ -282,6 +274,17 @@ class DrilldownContextModal(APIView):
|
||||||
if type == "znc":
|
if type == "znc":
|
||||||
query_params["channel"] = "*status"
|
query_params["channel"] = "*status"
|
||||||
|
|
||||||
|
if request.user.is_superuser:
|
||||||
|
if type in ["query", "notice"]:
|
||||||
|
nicks = [query_params["channel"], query_params["nick"]]
|
||||||
|
query_params["sorting"] = "desc"
|
||||||
|
if (
|
||||||
|
query_params["index"] == "int"
|
||||||
|
and query_params["mtype"] == "msg"
|
||||||
|
and not type == "query"
|
||||||
|
):
|
||||||
|
query_params["index"] = "main"
|
||||||
|
|
||||||
# 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"],
|
||||||
|
|
Loading…
Reference in New Issue