From d0348ee3173812a3d61dd5336ee88f2670832f24 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 13 Feb 2019 19:10:36 +0000 Subject: [PATCH] Limit organizations visible to superusers, fixing #10 --- manager/forms.py | 4 ++++ manager/views.py | 2 +- static/js/devices.js | 8 ++++++-- templates/manager/add.html | 5 +++-- templates/manager/index.html | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/manager/forms.py b/manager/forms.py index ff3cde0..d3044d8 100644 --- a/manager/forms.py +++ b/manager/forms.py @@ -8,6 +8,10 @@ class NetworkForm(forms.Form): extip = forms.GenericIPAddressField(label="External IP Address", protocol="ipv4") orgas = forms.MultipleChoiceField(label="Assigned Organizations", choices=[(orga.id, str(orga)) for orga in Organization.objects.all()]) + def __init__(self, user, *args, **kwargs): + super(NetworkForm, self).__init__(*args, **kwargs) + self.fields['orgas'].choices = [(orga.id, str(orga)) for orga in user.organization_set.all()] + class OrgaForm(forms.Form): name = forms.CharField(label="Common Name", max_length=64) users = forms.IntegerField(label="User Limit", required=False) diff --git a/manager/views.py b/manager/views.py index e4bbf12..6670997 100644 --- a/manager/views.py +++ b/manager/views.py @@ -433,7 +433,7 @@ def makenetwork(request): return redirect("/networks/") else: - form = NetworkForm() + form = NetworkForm(request.user) return render(request, "manager/form.html", { "title": "Add Network", "form": form }) diff --git a/static/js/devices.js b/static/js/devices.js index ffdb820..16729b9 100644 --- a/static/js/devices.js +++ b/static/js/devices.js @@ -13,9 +13,11 @@ function urlStatus(url, cb){ function checkDownload(url){ urlStatus(url, function(status) { if (status === 200){ + var working = false; document.getElementById("download").src=url; } else { + var working = true; checkDownload(url); } }); @@ -99,8 +101,10 @@ function askreboot(device_id) { }; function downloadnotice(device_id) { - alert("Your file is being prepared. This might take a minute or two, the download will start automatically when the file is ready. You may close this page and click the download button again later to pick the file up – we will store it for you."); - checkDownload('/devices/' + device_id + '/download/'); + if (!working) { + alert("Your file is being prepared. This might take a minute or two, the download will start automatically when the file is ready. You may close this page and click the download button again later to pick the file up – we will store it for you."); + checkDownload('/devices/' + device_id + '/download/'); + }; }; function showdevices() { diff --git a/templates/manager/add.html b/templates/manager/add.html index 643ae5b..85e6096 100644 --- a/templates/manager/add.html +++ b/templates/manager/add.html @@ -1,5 +1,5 @@ {% extends "base.html" %} - +{% load manager %} {% block content %}
@@ -15,7 +15,8 @@
diff --git a/templates/manager/index.html b/templates/manager/index.html index 731fdd8..30e5110 100644 --- a/templates/manager/index.html +++ b/templates/manager/index.html @@ -143,7 +143,7 @@ Options - {% allOrgas as organizations %} + {% userOrgas as organizations %} {% for orga in organizations %}
{{ orga.name }}