Implement adding networks

This commit is contained in:
Mark Veidemanis 2022-08-01 23:02:35 +01:00
parent fa53e11ff0
commit c7e5ac5aac
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
15 changed files with 225 additions and 37 deletions

View File

@ -24,6 +24,8 @@ 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 (
ThresholdIRCActions,
ThresholdIRCActionsAddNetwork,
ThresholdIRCAliases, ThresholdIRCAliases,
ThresholdIRCAliasesEdit, ThresholdIRCAliasesEdit,
ThresholdIRCNetworkActions, ThresholdIRCNetworkActions,
@ -102,6 +104,16 @@ urlpatterns = [
ThresholdIRCNetworks.as_view(), ThresholdIRCNetworks.as_view(),
name="threshold_irc_networks", name="threshold_irc_networks",
), ),
path(
"manage/threshold/irc/overview/actions/",
ThresholdIRCActions.as_view(),
name="threshold_irc_actions",
),
path(
"manage/threshold/irc/overview/actions/add-network/",
ThresholdIRCActionsAddNetwork.as_view(),
name="threshold_irc_actions_add-network",
),
path( path(
"manage/threshold/irc/network/<str:net>/", "manage/threshold/irc/network/<str:net>/",
ThresholdIRCNetwork.as_view(), ThresholdIRCNetwork.as_view(),

View File

@ -125,3 +125,10 @@ def run_list(net):
payload = {} payload = {}
ran = threshold_request(url, payload, method="POST") ran = threshold_request(url, payload, method="POST")
return ran return ran
def create_network(data):
url = "irc/network/create"
payload = data
ran = threshold_request(url, payload, method="PUT")
return ran

View File

@ -71,7 +71,6 @@ def threshold_request(url, data, method="POST", esc=False):
else: else:
logger.error("Invalid method specified") logger.error("Invalid method specified")
method = requests.get method = requests.get
print("SENDING TO", url)
r = method( r = method(
f"{settings.THRESHOLD_ENDPOINT}/{url}/", data=dumps(data), headers=headers f"{settings.THRESHOLD_ENDPOINT}/{url}/", data=dumps(data), headers=headers

View File

@ -1,9 +1,5 @@
<div id="actions"> <div id="actions">
{% if message is not None %} {% include 'manage/threshold/partials/notify.html' %}
<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 }}"}'
@ -47,16 +43,6 @@
<span>List</span> <span>List</span>
</span> </span>
</button> </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>
</button>
</div> </div>
<form method="POST"> <form method="POST">
<div class="field has-addons"> <div class="field has-addons">

View File

@ -1,9 +1,5 @@
<div id="channels"> <div id="channels">
{% if message is not None %} {% include 'manage/threshold/partials/notify.html' %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
{% if channels is not None %} {% if channels is not None %}
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">

View File

@ -63,12 +63,13 @@
</tbody> </tbody>
</table> </table>
<button class="button is-primary">Submit</button>
<button <button
class="button is-primary" class="button is-primary"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_network_info' net %}"> hx-get="{% url 'threshold_irc_network_info' net %}">
Cancel Cancel
</button> </button>
<button class="button is-primary">Submit</button>
</div> </div>
</form> </form>

View File

@ -1,9 +1,5 @@
<div id="info"> <div id="info">
{% if message is not None %} {% include 'manage/threshold/partials/notify.html' %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
{% if network is not None %} {% if network is not None %}
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">

View File

@ -1,10 +1,6 @@
{% load index %} {% load index %}
<div id="relays"> <div id="relays">
{% if message is not None %} {% include 'manage/threshold/partials/notify.html' %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
{% if relays is not None %} {% if relays is not None %}
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">

View File

@ -0,0 +1,42 @@
<div id="actions">
{% include 'manage/threshold/partials/notify.html' %}
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_actions_add-network' %}"
hx-trigger="click"
hx-target="#modals-here-actions"
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Network</span>
</span>
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="% url 'threshold_irc_actions_auto' %"
hx-trigger="click"
hx-target="#actions"
hx-swap="outerHTML"
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-wrench"></i>
</span>
<span>Auto</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>
</button>
</div>
</div>

View File

@ -1,11 +1,7 @@
{% load joinsep %} {% load joinsep %}
<div id="aliases"> <div id="aliases">
{% if message is not None %} {% include 'manage/threshold/partials/notify.html' %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}
{% if aliases is not None %} {% if aliases is not None %}
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">

View File

@ -0,0 +1,85 @@
{% load index %}
{% load static %}
<script src="{% static 'modal.js' %}"></script>
<div class="modal is-active is-clipped">
<div class="modal-background"></div>
<div class="modal-content">
<div class="box">
<h4 class="subtitle is-4">Add network</h4>
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-put="{% url 'threshold_irc_actions_add-network' %}"
hx-target="#networks"
hx-swap="outerHTML">
<div class="content">
<div class="field">
<label class="label">Network name</label>
<div class="control">
<input class="input" type="text" name="net" placeholder="freenode">
</div>
</div>
<div class="field">
<label class="label">Host</label>
<div class="control">
<input class="input" type="text" name="host" placeholder="irc.freenode.net">
</div>
</div>
<div class="field">
<label class="label">Port</label>
<div class="control">
<input class="input" type="text" name="port" placeholder="6697">
</div>
</div>
<div class="columns">
<div class="column">
<div class="field">
<label class="label">Security</label>
<div class="control">
<div class="select">
<select name="security">
<option>ssl</option>
<option>plain</option>
</select>
</div>
</div>
</div>
</div>
<div class="column">
<div class="field">
<label class="label">Authentication</label>
<div class="control">
<div class="select">
<select name="auth">
<option>sasl</option>
<option>ns</option>
<option>none</option>
</select>
</div>
</div>
</div>
</div>
</div>
<button
class="button is-primary modal-close-button">
Cancel
</button>
<button class="button is-primary modal-close-button">Submit</button>
</form>
</div>
<button class="modal-close is-large" aria-label="close"></button>
</div>
</div>

View File

@ -1,4 +1,5 @@
<div id="networks"> <div id="networks">
{% include 'manage/threshold/partials/notify.html' %}
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<table class="table is-fullwidth is-hoverable"> <table class="table is-fullwidth is-hoverable">
<thead> <thead>
@ -32,4 +33,6 @@
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
<div id="modals-here-actions">
</div>
</div> </div>

View File

@ -28,6 +28,15 @@
hx-swap="outerHTML"> hx-swap="outerHTML">
</div> </div>
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'threshold_irc_actions' %}"
hx-trigger="load"
hx-target="#actions"
hx-swap="outerHTML">
</div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<div class="box"> <div class="box">
@ -53,8 +62,20 @@
<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="column"></div>
<div class="column is-half">
<div class="box">
<div id="actions">
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,5 @@
{% if message is not None %}
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
{{ message }}
</div>
{% endif %}

View File

@ -215,6 +215,49 @@ class ThresholdIRCAliases(SuperUserRequiredMixin, APIView):
return render(request, self.template_name, context) return render(request, self.template_name, context)
class ThresholdIRCActions(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/overview/actions.html"
def get(self, request):
"""
Get actions pane.
"""
return render(request, self.template_name)
class ThresholdIRCActionsAddNetwork(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/overview/modals/add-network.html"
parser_classes = [FormParser]
def get(self, request):
"""
Get actions pane.
"""
return render(request, self.template_name)
def put(self, request):
"""
Create a network.
"""
template_name = "manage/threshold/irc/overview/networks.html"
created = threshold.create_network(request.data)
message = "Network created successfully."
message_class = "success"
if not created["success"]:
message = created["reason"]
message_class = "danger"
networks = threshold.get_irc_networks()
context = {
"networks": networks,
"message": message,
"class": message_class,
}
return render(request, template_name, context)
class ThresholdIRCAliasesEdit(SuperUserRequiredMixin, APIView): class ThresholdIRCAliasesEdit(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html" template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
parser_classes = [FormParser] parser_classes = [FormParser]