Implement button to enable authentication for relay

This commit is contained in:
Mark Veidemanis 2022-08-13 22:25:42 +01:00
parent d3dd070db0
commit 985705dfa4
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 50 additions and 0 deletions

View File

@ -39,6 +39,7 @@ from core.views.manage.threshold.irc import (
ThresholdIRCNetworkDel,
ThresholdIRCNetworkInfo,
ThresholdIRCNetworkInfoEdit,
ThresholdIRCNetworkRelayAuth,
ThresholdIRCNetworkRelayDel,
ThresholdIRCNetworkRelayProvision,
ThresholdIRCNetworkRelays,
@ -143,6 +144,11 @@ urlpatterns = [
ThresholdIRCNetworkRelayProvision.as_view(),
name="threshold_irc_network_relay_provision",
),
path(
"manage/threshold/irc/network/<str:net>/<int:num>/auth/",
ThresholdIRCNetworkRelayAuth.as_view(),
name="threshold_irc_network_relay_auth",
),
path(
"manage/threshold/irc/actions/registration/",
ThresholdIRCActionsRegistration.as_view(),

View File

@ -241,3 +241,10 @@ def irc_provision_relay(net, num):
payload = {}
provisioned = threshold_request(url, payload, method="POST")
return provisioned
def irc_enable_auth(net, num):
url = f"irc/network/{net}/{num}/auth"
payload = {}
enabled = threshold_request(url, payload, method="POST")
return enabled

View File

@ -123,6 +123,18 @@
</span>
</button>
</div>
<div class="nowrap-child">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_relay_auth' relay|index:'net' relay|index:'id' %}"
hx-target="#relays"
hx-swap="outerHTML"
class="button is-info">
<span class="icon" data-tooltip="Enable authentication">
<i class="fa-solid fa-passport" aria-hidden="true"></i>
</span>
</button>
</div>
</div>
</div>
</td>

View File

@ -158,6 +158,31 @@ class ThresholdIRCNetworkRelayProvision(SuperUserRequiredMixin, APIView):
return render(request, self.template_name, context)
class ThresholdIRCNetworkRelayAuth(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/relays.html"
def post(self, request, net, num):
"""
Provision a relay
"""
provisioned = threshold.irc_enable_auth(net, num)
if provisioned["success"]:
message = f"Enabled authentication on relay {num}"
message_class = "success"
else:
message = provisioned["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"