Implement adding networks
This commit is contained in:
parent
fa53e11ff0
commit
c7e5ac5aac
12
app/urls.py
12
app/urls.py
|
@ -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.callbacks import Callback
|
||||
from core.views.manage.threshold.irc import (
|
||||
ThresholdIRCActions,
|
||||
ThresholdIRCActionsAddNetwork,
|
||||
ThresholdIRCAliases,
|
||||
ThresholdIRCAliasesEdit,
|
||||
ThresholdIRCNetworkActions,
|
||||
|
@ -102,6 +104,16 @@ urlpatterns = [
|
|||
ThresholdIRCNetworks.as_view(),
|
||||
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(
|
||||
"manage/threshold/irc/network/<str:net>/",
|
||||
ThresholdIRCNetwork.as_view(),
|
||||
|
|
|
@ -125,3 +125,10 @@ def run_list(net):
|
|||
payload = {}
|
||||
ran = threshold_request(url, payload, method="POST")
|
||||
return ran
|
||||
|
||||
|
||||
def create_network(data):
|
||||
url = "irc/network/create"
|
||||
payload = data
|
||||
ran = threshold_request(url, payload, method="PUT")
|
||||
return ran
|
||||
|
|
|
@ -71,7 +71,6 @@ def threshold_request(url, data, method="POST", esc=False):
|
|||
else:
|
||||
logger.error("Invalid method specified")
|
||||
method = requests.get
|
||||
print("SENDING TO", url)
|
||||
|
||||
r = method(
|
||||
f"{settings.THRESHOLD_ENDPOINT}/{url}/", data=dumps(data), headers=headers
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
<div id="actions">
|
||||
{% if message is not None %}
|
||||
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'manage/threshold/partials/notify.html' %}
|
||||
<div class="buttons">
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
|
@ -47,16 +43,6 @@
|
|||
<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>
|
||||
</button>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<div class="field has-addons">
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
<div id="channels">
|
||||
{% if message is not None %}
|
||||
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'manage/threshold/partials/notify.html' %}
|
||||
{% if channels is not None %}
|
||||
<div class="content" style="max-height: 30em; overflow: auto;">
|
||||
<div class="table-container">
|
||||
|
|
|
@ -63,12 +63,13 @@
|
|||
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="button is-primary">Submit</button>
|
||||
<button
|
||||
class="button is-primary"
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-get="{% url 'threshold_irc_network_info' net %}">
|
||||
Cancel
|
||||
</button>
|
||||
<button class="button is-primary">Submit</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
<div id="info">
|
||||
{% if message is not None %}
|
||||
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'manage/threshold/partials/notify.html' %}
|
||||
{% if network is not None %}
|
||||
<div class="content" style="max-height: 30em; overflow: auto;">
|
||||
<div class="table-container">
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
{% load index %}
|
||||
<div id="relays">
|
||||
{% if message is not None %}
|
||||
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'manage/threshold/partials/notify.html' %}
|
||||
{% if relays is not None %}
|
||||
<div class="content" style="max-height: 30em; overflow: auto;">
|
||||
<div class="table-container">
|
||||
|
|
|
@ -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>
|
|
@ -1,11 +1,7 @@
|
|||
{% load joinsep %}
|
||||
|
||||
<div id="aliases">
|
||||
{% if message is not None %}
|
||||
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'manage/threshold/partials/notify.html' %}
|
||||
{% if aliases is not None %}
|
||||
<div class="content" style="max-height: 30em; overflow: auto;">
|
||||
<div class="table-container">
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<div id="networks">
|
||||
{% include 'manage/threshold/partials/notify.html' %}
|
||||
<div class="content" style="max-height: 30em; overflow: auto;">
|
||||
<table class="table is-fullwidth is-hoverable">
|
||||
<thead>
|
||||
|
@ -32,4 +33,6 @@
|
|||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
<div id="modals-here-actions">
|
||||
</div>
|
||||
</div>
|
|
@ -28,6 +28,15 @@
|
|||
hx-swap="outerHTML">
|
||||
</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="column">
|
||||
<div class="box">
|
||||
|
@ -53,8 +62,20 @@
|
|||
<div class="column">
|
||||
<div class="box">
|
||||
<div id="alerts">
|
||||
Alerts here
|
||||
</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 %}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{% if message is not None %}
|
||||
<div class="notification is-{{ class }}" hx-ext="remove-me" remove-me="3s">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endif %}
|
|
@ -215,6 +215,49 @@ class ThresholdIRCAliases(SuperUserRequiredMixin, APIView):
|
|||
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):
|
||||
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
|
||||
parser_classes = [FormParser]
|
||||
|
|
Loading…
Reference in New Issue