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

View File

@ -94,3 +94,10 @@ def add_relay(net, num):
payload = {} payload = {}
created = threshold_request(url, payload, method="PUT") created = threshold_request(url, payload, method="PUT")
return created 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> </span>
</button> </button>
{% endif %} {% 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>
<td> <td>
{{ relay.chans }} {{ relay.chans }}

View File

@ -80,6 +80,31 @@ class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
return render(request, self.template_name, context) 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): class ThresholdIRCNetworkRelayStatus(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/relays.html" template_name = "manage/threshold/irc/network/relays.html"
@ -159,7 +184,6 @@ class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, APIView):
else: else:
channel = request.data["channel"] channel = request.data["channel"]
joined = threshold.join_channel(net, channel) joined = threshold.join_channel(net, channel)
print("JOINED", joined)
if joined["success"]: 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"
@ -202,7 +226,7 @@ class ThresholdIRCNetworkActions(SuperUserRequiredMixin, View):
return render(request, self.template_name, context) return render(request, self.template_name, context)
class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView): class ThresholdIRCNetworkActionsRelay(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/actions.html" template_name = "manage/threshold/irc/network/actions.html"
parser_classes = [FormParser] parser_classes = [FormParser]
@ -210,7 +234,6 @@ class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
""" """
Create a relay Create a relay
""" """
print("ACTION PUT", request.data, net)
if "num" not in request.data: if "num" not in request.data:
message = "No num specified" message = "No num specified"
message_class = "danger" message_class = "danger"
@ -222,7 +245,6 @@ class ThresholdIRCNetworkActionsAddRelay(SuperUserRequiredMixin, APIView):
else: else:
num = int(num) num = int(num)
created = threshold.add_relay(net, num) created = threshold.add_relay(net, num)
print("CREATED", created)
if created["success"]: if created["success"]:
id = created["id"] id = created["id"]
alias = created["alias"] alias = created["alias"]