Implement adding relays by number

This commit is contained in:
Mark Veidemanis 2022-07-29 17:28:41 +01:00
parent dc293b0dbc
commit 0457cfbbed
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
6 changed files with 124 additions and 36 deletions

View File

@ -24,6 +24,9 @@ from core.api.views.threshold import ThresholdChans, ThresholdOnline, ThresholdU
from core.views import Billing, Cancel, Home, Order, Portal, Signup from core.views import Billing, Cancel, Home, Order, Portal, Signup
from core.views.callbacks import Callback from core.views.callbacks import Callback
from core.views.manage.threshold.irc import ( from core.views.manage.threshold.irc import (
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
ThresholdIRCNetworkActionsAddRelay,
ThresholdIRCNetworkChannels, ThresholdIRCNetworkChannels,
ThresholdIRCNetworkInfo, ThresholdIRCNetworkInfo,
ThresholdIRCNetworkInfoEdit, ThresholdIRCNetworkInfoEdit,
@ -31,8 +34,6 @@ from core.views.manage.threshold.irc import (
ThresholdIRCNetworkRelayStatus, ThresholdIRCNetworkRelayStatus,
ThresholdIRCNetworks, ThresholdIRCNetworks,
ThresholdIRCStats, ThresholdIRCStats,
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
) )
# Management stuff # Management stuff
@ -153,6 +154,11 @@ urlpatterns = [
ThresholdIRCNetworkActions.as_view(), ThresholdIRCNetworkActions.as_view(),
name="threshold_irc_network_actions", name="threshold_irc_network_actions",
), ),
path(
"manage/threshold/irc/network/actions/<str:net>/",
ThresholdIRCNetworkActionsAddRelay.as_view(),
name="threshold_irc_network_actions_add_relay",
),
## ##
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"),

View File

@ -81,9 +81,16 @@ def join_channel(net, channel):
return {} return {}
return joined return joined
def get_aliases(): def get_aliases():
url = "aliases" url = "aliases"
payload = {} payload = {}
aliases = threshold_request(url, payload, method="GET") aliases = threshold_request(url, payload, method="GET")
print("Aliases", aliases)
return aliases return aliases
def add_relay(net, num):
url = f"irc/network/{net}/{num}"
payload = {}
created = threshold_request(url, payload, method="PUT")
return created

View File

@ -1,13 +1,21 @@
<div id="actions"> <div id="actions">
{% if message is not None %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
<div class="buttons"> <div class="buttons">
<button <button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-trigger="click"
hx-target="#channels"
hx-swap="outerHTML"
class="button is-success"> class="button is-success">
<span class="icon-text"> <span class="icon-text">
<span class="icon"> <span class="icon">
<i class="fa-solid fa-plus"></i> <i class="fa-solid fa-plus"></i>
</span> </span>
<span>Add relay</span> <span>Relay</span>
</span> </span>
</button> </button>
<button <button
@ -17,7 +25,7 @@
<span class="icon"> <span class="icon">
<i class="fa-solid fa-wrench"></i> <i class="fa-solid fa-wrench"></i>
</span> </span>
<span>Run auto</span> <span>Auto</span>
</span> </span>
</button> </button>
<button <button
@ -27,8 +35,40 @@
<span class="icon"> <span class="icon">
<i class="fa-solid fa-list"></i> <i class="fa-solid fa-list"></i>
</span> </span>
<span>Request list</span> <span>List</span>
</span>
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-list"></i>
</span>
<span>Registration</span>
</span> </span>
</button> </button>
</div> </div>
<form method="POST">
<div class="field has-addons">
<div class="control is-expanded has-icons-left">
<input class="input" name="num" type="text" placeholder="Relay number">
<span class="icon is-small is-left">
<i class="fa-brands fa-unity"></i>
</span>
</div>
<div class="control">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="button is-primary is-fullwidth"
hx-put="{% url 'threshold_irc_network_actions_add_relay' net %}"
hx-trigger="click"
hx-target="#actions"
hx-swap="outerHTML">
Add
</button>
</div>
</div>
</form>
</div> </div>

View File

@ -62,27 +62,24 @@
<div class="column"> <div class="column">
<div class="box"> <div class="box">
<div id="alerts"> <div id="alerts">
Alerts here
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
{# This is the only thing included without HTMX because it isn't interactive #}
{# It needs no dynamic message element because it posts messages to chanels #}
<div class="box"> <div class="box">
<form method="POST"> <form method="POST">
<div class="field"> <div class="field has-addons">
<div class="field-body">
<div class="field">
<div class="control is-expanded has-icons-left"> <div class="control is-expanded has-icons-left">
<input id="query" name="channel" class="input" type="text" placeholder="channel"> <input id="query" name="channel" class="input" type="text" placeholder="channel">
<span class="icon is-small is-left"> <span class="icon is-small is-left">
<i class="fa-solid fa-hashtag"></i> <i class="fa-solid fa-hashtag"></i>
</span> </span>
</div> </div>
</div>
</div>
</div>
<div class="field">
<div class="control"> <div class="control">
<button <button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'

View File

@ -132,7 +132,7 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
:param channel: channel name :param channel: channel name
""" """
parted = threshold.part_channel(net, channel) parted = threshold.part_channel(net, channel)
if parted: if parted["success"]:
message = f"Requested part on relays: {', '.join(parted['relays'])}" message = f"Requested part on relays: {', '.join(parted['relays'])}"
message_class = "success" message_class = "success"
else: else:
@ -158,10 +158,9 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
message_class = "danger" message_class = "danger"
else: else:
channel = request.data["channel"] channel = request.data["channel"]
print("CHANNEL", channel)
joined = threshold.join_channel(net, channel) joined = threshold.join_channel(net, channel)
print("JOINED", joined) print("JOINED", joined)
if joined: if joined["success"]:
message = f"Requested join on relay: {joined['relays']}" message = f"Requested join on relay: {joined['relays']}"
message_class = "success" message_class = "success"
else: else:
@ -191,6 +190,7 @@ class ThresholdIRCAliases(SuperUserRequiredMixin, APIView):
} }
return render(request, self.template_name, context) return render(request, self.template_name, context)
class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View): class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
template_name = "manage/threshold/irc/network/actions.html" template_name = "manage/threshold/irc/network/actions.html"
@ -198,5 +198,43 @@ class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
""" """
Get actions page. Get actions page.
""" """
context = {"net": net}
return render(request, self.template_name, context)
return render(request, self.template_name)
class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/actions.html"
parser_classes = [FormParser]
def put(self, request, net):
"""
Create a relay
"""
print("ACTION PUT", request.data, net)
if "num" not in request.data:
message = "No num specified"
message_class = "danger"
else:
num = request.data["num"]
if not num.isdigit():
message = "Num is not an integer"
message_class = "danger"
else:
num = int(num)
created = threshold.add_relay(net, num)
print("CREATED", created)
if created["success"]:
id = created["id"]
alias = created["alias"]
message = f"Created new relay {id} with alias {alias}"
message_class = "success"
else:
message = created["reason"]
message_class = "danger"
context = {
"net": net,
"message": message,
"class": message_class,
}
return render(request, self.template_name, context)