From c7e5ac5aacdee5c93700acc49aed123cb48c9855 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 1 Aug 2022 23:02:35 +0100 Subject: [PATCH] Implement adding networks --- app/urls.py | 12 +++ core/lib/manage/threshold.py | 7 ++ core/lib/threshold.py | 1 - .../manage/threshold/irc/network/actions.html | 16 +--- .../threshold/irc/network/channels.html | 6 +- .../threshold/irc/network/edit-network.html | 3 +- .../manage/threshold/irc/network/info.html | 6 +- .../manage/threshold/irc/network/relays.html | 6 +- .../threshold/irc/overview/actions.html | 42 +++++++++ .../threshold/irc/overview/aliases.html | 6 +- .../irc/overview/modals/add-network.html | 85 +++++++++++++++++++ .../threshold/irc/overview/networks.html | 3 + .../threshold/irc/overview/overview.html | 21 +++++ .../manage/threshold/partials/notify.html | 5 ++ core/views/manage/threshold/irc.py | 43 ++++++++++ 15 files changed, 225 insertions(+), 37 deletions(-) create mode 100644 core/templates/manage/threshold/irc/overview/actions.html create mode 100644 core/templates/manage/threshold/irc/overview/modals/add-network.html create mode 100644 core/templates/manage/threshold/partials/notify.html diff --git a/app/urls.py b/app/urls.py index 91e2ef0..b03cb93 100644 --- a/app/urls.py +++ b/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//", ThresholdIRCNetwork.as_view(), diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 2b2f483..826dc6c 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -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 diff --git a/core/lib/threshold.py b/core/lib/threshold.py index a885ddb..4c1cfdc 100644 --- a/core/lib/threshold.py +++ b/core/lib/threshold.py @@ -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 diff --git a/core/templates/manage/threshold/irc/network/actions.html b/core/templates/manage/threshold/irc/network/actions.html index 6154f80..accd20e 100644 --- a/core/templates/manage/threshold/irc/network/actions.html +++ b/core/templates/manage/threshold/irc/network/actions.html @@ -1,9 +1,5 @@
- {% if message is not None %} -
- {{ message }} -
- {% endif %} + {% include 'manage/threshold/partials/notify.html' %}
-
diff --git a/core/templates/manage/threshold/irc/network/channels.html b/core/templates/manage/threshold/irc/network/channels.html index 32d751c..1096b62 100644 --- a/core/templates/manage/threshold/irc/network/channels.html +++ b/core/templates/manage/threshold/irc/network/channels.html @@ -1,9 +1,5 @@
- {% if message is not None %} -
- {{ message }} -
- {% endif %} + {% include 'manage/threshold/partials/notify.html' %} {% if channels is not None %}
diff --git a/core/templates/manage/threshold/irc/network/edit-network.html b/core/templates/manage/threshold/irc/network/edit-network.html index e88daf4..ce8eb25 100644 --- a/core/templates/manage/threshold/irc/network/edit-network.html +++ b/core/templates/manage/threshold/irc/network/edit-network.html @@ -63,12 +63,13 @@ - + +
diff --git a/core/templates/manage/threshold/irc/network/info.html b/core/templates/manage/threshold/irc/network/info.html index 2737842..14bbea8 100644 --- a/core/templates/manage/threshold/irc/network/info.html +++ b/core/templates/manage/threshold/irc/network/info.html @@ -1,9 +1,5 @@
- {% if message is not None %} -
- {{ message }} -
- {% endif %} + {% include 'manage/threshold/partials/notify.html' %} {% if network is not None %}
diff --git a/core/templates/manage/threshold/irc/network/relays.html b/core/templates/manage/threshold/irc/network/relays.html index ff55933..79188e0 100644 --- a/core/templates/manage/threshold/irc/network/relays.html +++ b/core/templates/manage/threshold/irc/network/relays.html @@ -1,10 +1,6 @@ {% load index %}
- {% if message is not None %} -
- {{ message }} -
- {% endif %} + {% include 'manage/threshold/partials/notify.html' %} {% if relays is not None %}
diff --git a/core/templates/manage/threshold/irc/overview/actions.html b/core/templates/manage/threshold/irc/overview/actions.html new file mode 100644 index 0000000..b71b875 --- /dev/null +++ b/core/templates/manage/threshold/irc/overview/actions.html @@ -0,0 +1,42 @@ +
+ {% include 'manage/threshold/partials/notify.html' %} +
+ + + +
+
\ No newline at end of file diff --git a/core/templates/manage/threshold/irc/overview/aliases.html b/core/templates/manage/threshold/irc/overview/aliases.html index 8bd9752..45fc8b2 100644 --- a/core/templates/manage/threshold/irc/overview/aliases.html +++ b/core/templates/manage/threshold/irc/overview/aliases.html @@ -1,11 +1,7 @@ {% load joinsep %}
- {% if message is not None %} -
- {{ message }} -
- {% endif %} + {% include 'manage/threshold/partials/notify.html' %} {% if aliases is not None %}
diff --git a/core/templates/manage/threshold/irc/overview/modals/add-network.html b/core/templates/manage/threshold/irc/overview/modals/add-network.html new file mode 100644 index 0000000..4d7d9ff --- /dev/null +++ b/core/templates/manage/threshold/irc/overview/modals/add-network.html @@ -0,0 +1,85 @@ +{% load index %} +{% load static %} + + + +
+
+
@@ -53,8 +62,20 @@
+ Alerts here
+ +
+
+
+
+
+
+
+
+
+ {% endblock %} diff --git a/core/templates/manage/threshold/partials/notify.html b/core/templates/manage/threshold/partials/notify.html new file mode 100644 index 0000000..6cdaccb --- /dev/null +++ b/core/templates/manage/threshold/partials/notify.html @@ -0,0 +1,5 @@ +{% if message is not None %} +
+ {{ message }} +
+{% endif %} \ No newline at end of file diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index b5b27b5..a5dfaa1 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -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]