Limit organizations visible to superusers, fixing #10
This commit is contained in:
parent
1eec406efd
commit
d0348ee317
5 changed files with 15 additions and 6 deletions
|
@ -8,6 +8,10 @@ class NetworkForm(forms.Form):
|
||||||
extip = forms.GenericIPAddressField(label="External IP Address", protocol="ipv4")
|
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()])
|
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):
|
class OrgaForm(forms.Form):
|
||||||
name = forms.CharField(label="Common Name", max_length=64)
|
name = forms.CharField(label="Common Name", max_length=64)
|
||||||
users = forms.IntegerField(label="User Limit", required=False)
|
users = forms.IntegerField(label="User Limit", required=False)
|
||||||
|
|
|
@ -433,7 +433,7 @@ def makenetwork(request):
|
||||||
return redirect("/networks/")
|
return redirect("/networks/")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
form = NetworkForm()
|
form = NetworkForm(request.user)
|
||||||
|
|
||||||
return render(request, "manager/form.html", { "title": "Add Network", "form": form })
|
return render(request, "manager/form.html", { "title": "Add Network", "form": form })
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,11 @@ function urlStatus(url, cb){
|
||||||
function checkDownload(url){
|
function checkDownload(url){
|
||||||
urlStatus(url, function(status) {
|
urlStatus(url, function(status) {
|
||||||
if (status === 200){
|
if (status === 200){
|
||||||
|
var working = false;
|
||||||
document.getElementById("download").src=url;
|
document.getElementById("download").src=url;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
var working = true;
|
||||||
checkDownload(url);
|
checkDownload(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -99,8 +101,10 @@ function askreboot(device_id) {
|
||||||
};
|
};
|
||||||
|
|
||||||
function downloadnotice(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.");
|
if (!working) {
|
||||||
checkDownload('/devices/' + device_id + '/download/');
|
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() {
|
function showdevices() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load manager %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<form action="#" method="post">
|
<form action="#" method="post">
|
||||||
|
@ -15,7 +15,8 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="organization">Organization</label>
|
<label for="organization">Organization</label>
|
||||||
<select required class="custom-select mr-sm-2" id="organization" name="organization">
|
<select required class="custom-select mr-sm-2" id="organization" name="organization">
|
||||||
{% for choice in organizations %}
|
{% userOrgas as orgas %}
|
||||||
|
{% for choice in orgas %}
|
||||||
<option value="{{ choice.id }}">{{ choice.name }}</option>
|
<option value="{{ choice.id }}">{{ choice.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -143,7 +143,7 @@
|
||||||
<th>Options <a href="/makeorga/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add Organization"></i></a></th>
|
<th>Options <a href="/makeorga/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add Organization"></i></a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% allOrgas as organizations %}
|
{% userOrgas as organizations %}
|
||||||
{% for orga in organizations %}
|
{% for orga in organizations %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div style="display:inline;">{{ orga.name }}</div></td>
|
<td><div style="display:inline;">{{ orga.name }}</div></td>
|
||||||
|
|
Loading…
Reference in a new issue