Limit organizations visible to superusers, fixing #10

This commit is contained in:
Kumi 2019-02-13 19:10:36 +00:00
parent 1eec406efd
commit d0348ee317
5 changed files with 15 additions and 6 deletions

View file

@ -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)

View file

@ -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 })

View file

@ -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() {

View file

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% load manager %}
{% block content %}
<form action="#" method="post">
@ -15,7 +15,8 @@
<div class="form-group">
<label for="organization">Organization</label>
<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>
{% endfor %}
</select>

View file

@ -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>
</tr>
</thead>
{% allOrgas as organizations %}
{% userOrgas as organizations %}
{% for orga in organizations %}
<tr>
<td><div style="display:inline;">{{ orga.name }}</div></td>