diff --git a/app/urls.py b/app/urls.py index 2d3ebb3..1745178 100644 --- a/app/urls.py +++ b/app/urls.py @@ -253,12 +253,12 @@ urlpatterns = [ name="threshold_irc_network_list", ), path( - "manage/threshold/irc/msg////", + "manage/threshold/irc/msg///", ThresholdIRCSendMessage.as_view(), name="threshold_irc_msg", ), path( - "manage/threshold/irc/msg/////", + "manage/threshold/irc/msg////", ThresholdIRCSendMessage.as_view(), name="threshold_irc_msg", ), diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 5f4d2fc..c8d3130 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -1,5 +1,3 @@ -import urllib.parse - from django.conf import settings from core.lib.opensearch import client, run_main_query @@ -194,9 +192,8 @@ def get_irc_alerts(user): def send_irc_message(net, num, channel, msg, nick=None): - channel = urllib.parse.quote(channel, safe="") - url = f"irc/msg/{net}/{num}/{channel}" - payload = {"msg": msg} + url = f"irc/msg/{net}/{num}" + payload = {"msg": msg, "channel": channel} if nick: payload["nick"] = nick messaged = threshold_request(url, payload, method="PUT") diff --git a/core/templates/modals/context.html b/core/templates/modals/context.html index eaea11e..2db476c 100644 --- a/core/templates/modals/context.html +++ b/core/templates/modals/context.html @@ -80,7 +80,8 @@ id="search" class="button is-info is-fullwidth" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' - hx-put="{% url 'threshold_irc_msg' net num channel nick %}" + hx-put="{% url 'threshold_irc_msg' net num %}" + hx-vals='{"channel": "{{ channel }}", "nick": "{{ nick }}"}' hx-trigger="click" hx-target="#context-input" hx-swap="outerHTML"> diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index 3a348eb..3f854cc 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -657,7 +657,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView): parser_classes = [FormParser] template_name = "partials/context-input.html" - def put(self, request, net, num, channel, nick=None): + def put(self, request, net, num, nick=None): """ Send a message """ @@ -669,13 +669,21 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView): self.template_name, {"message": message, "class": message_class}, ) + if "channel" not in request.data: + message = "No channel" + message_class = "danger" + return render( + request, + self.template_name, + {"message": message, "class": message_class}, + ) if nick: messaged = threshold.send_irc_message( - net, num, channel, request.data["msg"], nick=nick + net, num, request.data["channel"], request.data["msg"], nick=nick ) else: messaged = threshold.send_irc_message( - net, num, channel, request.data["msg"] + net, num, request.data["channel"], request.data["msg"] ) if not messaged: message = "Failed to send message"