Implement deleting relays

This commit is contained in:
Mark Veidemanis 2022-07-29 22:11:34 +01:00
parent 654c9960ba
commit 7b97c96be3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 51 additions and 6 deletions

View File

@ -26,10 +26,11 @@ from core.views.callbacks import Callback
from core.views.manage.threshold.irc import (
ThresholdIRCAliases,
ThresholdIRCNetworkActions,
ThresholdIRCNetworkActionsAddRelay,
ThresholdIRCNetworkActionsRelay,
ThresholdIRCNetworkChannels,
ThresholdIRCNetworkInfo,
ThresholdIRCNetworkInfoEdit,
ThresholdIRCNetworkRelayDel,
ThresholdIRCNetworkRelays,
ThresholdIRCNetworkRelayStatus,
ThresholdIRCNetworks,
@ -123,6 +124,11 @@ urlpatterns = [
ThresholdIRCNetworkRelays.as_view(),
name="threshold_irc_network_relays",
),
path(
"manage/threshold/irc/network/<str:net>/<int:num>/",
ThresholdIRCNetworkRelayDel.as_view(),
name="threshold_irc_network_relay_del",
),
path(
"manage/threshold/irc/network/<str:net>/<int:num>/<int:status>/",
ThresholdIRCNetworkRelayStatus.as_view(),
@ -156,7 +162,7 @@ urlpatterns = [
),
path(
"manage/threshold/irc/network/actions/<str:net>/",
ThresholdIRCNetworkActionsAddRelay.as_view(),
ThresholdIRCNetworkActionsRelay.as_view(),
name="threshold_irc_network_actions_add_relay",
),
##

View File

@ -94,3 +94,10 @@ def add_relay(net, num):
payload = {}
created = threshold_request(url, payload, method="PUT")
return created
def del_relay(net, num):
url = f"irc/network/{net}/{num}"
payload = {}
deleted = threshold_request(url, payload, method="DELETE")
return deleted

View File

@ -65,6 +65,16 @@
</span>
</button>
{% endif %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'threshold_irc_network_relay_del' relay|index:'net' relay|index:'id' %}"
hx-target="#relays"
hx-swap="outerHTML"
class="button is-danger is-small">
<span class="icon" data-tooltip="Delete">
<i class="fa-solid fa-xmark" aria-hidden="true"></i>
</span>
</button>
</td>
<td>
{{ relay.chans }}

View File

@ -80,6 +80,31 @@ class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
return render(request, self.template_name, context)
class ThresholdIRCNetworkRelayDel(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/relays.html"
def delete(self, request, net, num):
"""
Delete a relay
"""
deleted = threshold.del_relay(net, num)
if deleted["success"]:
message = f"Deleted relay {num}"
message_class = "success"
else:
message = deleted["reason"]
message_class = "danger"
relays = threshold.get_irc_relays(net)
context = {
"net": net,
"message": message,
"class": message_class,
"relays": relays["relays"],
}
return render(request, self.template_name, context)
class ThresholdIRCNetworkRelayStatus(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/relays.html"
@ -159,7 +184,6 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
else:
channel = request.data["channel"]
joined = threshold.join_channel(net, channel)
print("JOINED", joined)
if joined["success"]:
message = f"Requested join on relay: {joined['relays']}"
message_class = "success"
@ -202,7 +226,7 @@ class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
return render(request, self.template_name, context)
class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
class ThresholdIRCNetworkActionsRelay(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/actions.html"
parser_classes = [FormParser]
@ -210,7 +234,6 @@ class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
"""
Create a relay
"""
print("ACTION PUT", request.data, net)
if "num" not in request.data:
message = "No num specified"
message_class = "danger"
@ -222,7 +245,6 @@ class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
else:
num = int(num)
created = threshold.add_relay(net, num)
print("CREATED", created)
if created["success"]:
id = created["id"]
alias = created["alias"]