diff --git a/app/urls.py b/app/urls.py index a74fc79..b5c0934 100644 --- a/app/urls.py +++ b/app/urls.py @@ -220,6 +220,11 @@ urlpatterns = [ ThresholdIRCSendMessage.as_view(), name="threshold_irc_msg", ), + path( + "manage/threshold/irc/msg/////", + ThresholdIRCSendMessage.as_view(), + name="threshold_irc_msg", + ), ## path("api/chans/", ThresholdChans.as_view(), name="chans"), path("api/users/", ThresholdUsers.as_view(), name="users"), diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 75792f8..4a98b5c 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -195,9 +195,11 @@ def get_irc_alerts(user): return results_parsed -def send_irc_message(net, num, channel, msg): +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} + if nick: + payload["nick"] = nick messaged = threshold_request(url, payload, method="PUT") return messaged diff --git a/core/templates/modals/context.html b/core/templates/modals/context.html index 2ca4cda..eaea11e 100644 --- a/core/templates/modals/context.html +++ b/core/templates/modals/context.html @@ -80,7 +80,7 @@ id="search" class="button is-info is-fullwidth" hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' - hx-put="{% url 'threshold_irc_msg' net num channel %}" + hx-put="{% url 'threshold_irc_msg' net num channel nick %}" hx-trigger="click" hx-target="#context-input" hx-swap="outerHTML"> diff --git a/core/templates/modals/context_table.html b/core/templates/modals/context_table.html index 21fd832..f95f2d2 100644 --- a/core/templates/modals/context_table.html +++ b/core/templates/modals/context_table.html @@ -30,7 +30,8 @@ "date": "{{ date }}", "index": "{{ index }}", "type": "{{ type }}", - "mtype": "{{ mtype }}"}' + "mtype": "{{ mtype }}", + "nick": "{{ nick }}"}' hx-target="#modal-context-table" hx-trigger="every 5s"> diff --git a/core/templates/ui/drilldown/table_results_partial.html b/core/templates/ui/drilldown/table_results_partial.html index c0ced6f..e96b56a 100644 --- a/core/templates/ui/drilldown/table_results_partial.html +++ b/core/templates/ui/drilldown/table_results_partial.html @@ -225,7 +225,8 @@ "date": "{{ row.cells.date|escapejs }}", "index": "{{ params.index }}", "type": "{{ row.cells.type }}", - "mtype": "{{ row.cells.mtype }}"}' + "mtype": "{{ row.cells.mtype }}", + "nick": "{{ row.cells.nick|escapejs }}"}' hx-target="#modals-here" hx-trigger="click"> {{ row.cells.msg }} diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index 24a4add..4810905 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -448,7 +448,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView): parser_classes = [FormParser] template_name = "partials/context-input.html" - def put(self, request, net, num, channel): + def put(self, request, net, num, channel, nick=None): """ Send a message """ @@ -460,8 +460,15 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView): self.template_name, {"message": message, "class": message_class}, ) - - messaged = threshold.send_irc_message(net, num, channel, request.data["msg"]) + print("IRC", nick) + if nick: + messaged = threshold.send_irc_message( + net, num, channel, request.data["msg"], nick=nick + ) + else: + messaged = threshold.send_irc_message( + net, num, channel, request.data["msg"] + ) if not messaged: message = "Failed to send message" message_class = "danger" @@ -471,6 +478,7 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView): else: message = messaged["reason"] message_class = "danger" + print("ERROR", message) context = { "net": net, diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index bf639a6..923ba21 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -245,7 +245,7 @@ class DrilldownContextModal(APIView): size = 20 # Create the query params from the POST arguments - mandatory = ["net", "channel", "num", "src", "index"] + mandatory = ["net", "channel", "num", "src", "index", "nick"] invalid = [None, False, "—", "None"] query_params = {k: v for k, v in request.data.items() if v} for key in query_params: @@ -258,7 +258,11 @@ class DrilldownContextModal(APIView): if "mtype" not in query_params: query_params["mtype"] = None query_params["sorting"] = "desc" - if query_params["index"] == "int" and query_params["mtype"] == "msg": + if ( + query_params["index"] == "int" + and query_params["mtype"] == "msg" + and not query_params["type"] == "query" + ): query_params["index"] = "main" # Create the query with the context helper search_query = construct_query( @@ -292,6 +296,7 @@ class DrilldownContextModal(APIView): "num": query_params["num"], "type": query_params["type"], "mtype": query_params["mtype"], + "nick": query_params["nick"], } return render(request, self.template_name, context)