Enable sending IRC messages from context modal
This commit is contained in:
parent
c012792c42
commit
c9a17a6fa4
|
@ -41,6 +41,7 @@ from core.views.manage.threshold.irc import (
|
||||||
ThresholdIRCNetworkRelayStatus,
|
ThresholdIRCNetworkRelayStatus,
|
||||||
ThresholdIRCNetworks,
|
ThresholdIRCNetworks,
|
||||||
ThresholdIRCOverviewAlerts,
|
ThresholdIRCOverviewAlerts,
|
||||||
|
ThresholdIRCSendMessage,
|
||||||
ThresholdIRCStats,
|
ThresholdIRCStats,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -214,6 +215,11 @@ urlpatterns = [
|
||||||
ThresholdIRCNetworkActionsList.as_view(),
|
ThresholdIRCNetworkActionsList.as_view(),
|
||||||
name="threshold_irc_network_actions_list",
|
name="threshold_irc_network_actions_list",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"manage/threshold/irc/msg/<str:net>/<int:num>/<str:channel>/",
|
||||||
|
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"),
|
||||||
|
|
|
@ -42,4 +42,5 @@ def construct_query(index, net, channel, src, num, size):
|
||||||
"fields": fields,
|
"fields": fields,
|
||||||
"_source": False,
|
"_source": False,
|
||||||
}
|
}
|
||||||
|
print("QUERY", query)
|
||||||
return query
|
return query
|
||||||
|
|
|
@ -193,3 +193,11 @@ def get_irc_alerts(user):
|
||||||
element["time"] = time
|
element["time"] = time
|
||||||
results_parsed.append(element)
|
results_parsed.append(element)
|
||||||
return results_parsed
|
return results_parsed
|
||||||
|
|
||||||
|
|
||||||
|
def send_irc_message(net, num, channel, msg):
|
||||||
|
channel = urllib.parse.quote(channel, safe="")
|
||||||
|
url = f"irc/msg/{net}/{num}/{channel}"
|
||||||
|
payload = {"msg": msg}
|
||||||
|
messaged = threshold_request(url, payload, method="PUT")
|
||||||
|
return messaged
|
||||||
|
|
|
@ -65,31 +65,32 @@
|
||||||
<div class="is-active" data-content="1">
|
<div class="is-active" data-content="1">
|
||||||
<h4 class="subtitle is-4">Scrollback of {{ channel }} on {{ net }}{{ num }}</h4>
|
<h4 class="subtitle is-4">Scrollback of {{ channel }} on {{ net }}{{ num }}</h4>
|
||||||
{% include 'modals/context_table.html' %}
|
{% include 'modals/context_table.html' %}
|
||||||
<div class="field has-addons">
|
{% if user.is_superuser and src == 'irc' %}
|
||||||
<div class="control is-expanded has-icons-left">
|
<form method="PUT">
|
||||||
<input
|
<article class="field has-addons">
|
||||||
hx-post="{% url 'search' %}"
|
<article class="control is-expanded has-icons-left">
|
||||||
hx-trigger="keyup changed delay:200ms"
|
<input id="context-input" name="msg" class="input" type="text" placeholder="Type your message here">
|
||||||
hx-target="#results"
|
<span class="icon is-small is-left">
|
||||||
hx-swap="innerHTML" id="query" name="query" value="{{ params.query }}" class="input" type="text" placeholder="msg: science AND nick: BillNye AND channel: #science">
|
<i class="fas fa-magnifying-glass"></i>
|
||||||
<span class="icon is-small is-left">
|
</span>
|
||||||
<i class="fas fa-magnifying-glass"></i>
|
</article>
|
||||||
</span>
|
<article class="control">
|
||||||
</div>
|
<article class="field">
|
||||||
<div class="control">
|
<button
|
||||||
<div class="field">
|
id="search"
|
||||||
<button
|
class="button is-info is-fullwidth"
|
||||||
id="search"
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
class="button is-info is-fullwidth"
|
hx-put="{% url 'threshold_irc_msg' net num channel %}"
|
||||||
hx-post="{% url 'search' %}"
|
hx-trigger="click"
|
||||||
hx-trigger="click"
|
hx-target="#context-input"
|
||||||
hx-target="#results"
|
hx-swap="outerHTML">
|
||||||
hx-swap="innerHTML">
|
Send
|
||||||
Search
|
</button>
|
||||||
</button>
|
</article>
|
||||||
</div>
|
</article>
|
||||||
</div>
|
</article>
|
||||||
</div>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div data-content="2">
|
<div data-content="2">
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<input id="context-input" name="msg" class="input is-{{ class }}" type="text" placeholder="Type your message here">
|
|
@ -0,0 +1,5 @@
|
||||||
|
{% if message is not None %}
|
||||||
|
<main class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||||
|
{{ message }}
|
||||||
|
</main>
|
||||||
|
{% endif %}
|
|
@ -442,3 +442,39 @@ class ThresholdIRCNetworkActionsRelay(SuperUserRequiredMixin, APIView):
|
||||||
"class": message_class,
|
"class": message_class,
|
||||||
}
|
}
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
|
class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
|
parser_classes = [FormParser]
|
||||||
|
template_name = "partials/context-input.html"
|
||||||
|
|
||||||
|
def put(self, request, net, num, channel):
|
||||||
|
"""
|
||||||
|
Send a message
|
||||||
|
"""
|
||||||
|
if "msg" not in request.data:
|
||||||
|
message = "No message to send"
|
||||||
|
message_class = "danger"
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
self.template_name,
|
||||||
|
{"message": message, "class": message_class},
|
||||||
|
)
|
||||||
|
|
||||||
|
messaged = threshold.send_irc_message(net, num, channel, request.data["msg"])
|
||||||
|
if not messaged:
|
||||||
|
message = "Failed to send message"
|
||||||
|
message_class = "danger"
|
||||||
|
elif messaged["success"]:
|
||||||
|
message = "Send message"
|
||||||
|
message_class = "success"
|
||||||
|
else:
|
||||||
|
message = messaged["reason"]
|
||||||
|
message_class = "danger"
|
||||||
|
|
||||||
|
context = {
|
||||||
|
"net": net,
|
||||||
|
"message": message,
|
||||||
|
"class": message_class,
|
||||||
|
}
|
||||||
|
return render(request, self.template_name, context)
|
||||||
|
|
Loading…
Reference in New Issue