From 1de35ba16c2b2c6ce776285d5da95e114f51b4cb Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 19 Nov 2016 23:19:44 +0100 Subject: [PATCH] =?UTF-8?q?Ajoute=20des=20acl=20sur=20les=20extensions=20a?= =?UTF-8?q?utoris=C3=A9es=20en=20alias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/forms.py | 10 ++++++++-- .../migrations/0033_extension_need_infra.py | 19 +++++++++++++++++++ machines/models.py | 1 + .../templates/machines/aff_extension.html | 6 ++++-- machines/views.py | 4 ++-- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 machines/migrations/0033_extension_need_infra.py diff --git a/machines/forms.py b/machines/forms.py index 8ea1b469..6a8d8d27 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -64,6 +64,12 @@ class AliasForm(ModelForm): model = Alias fields = ['alias','extension'] + def __init__(self, *args, **kwargs): + infra = kwargs.pop('infra') + super(AliasForm, self).__init__(*args, **kwargs) + if not infra: + self.fields['extension'].queryset = Extension.objects.filter(need_infra=False) + class DelAliasForm(ModelForm): alias = forms.ModelMultipleChoiceField(queryset=Alias.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple) @@ -113,7 +119,7 @@ class DelIpTypeForm(ModelForm): class ExtensionForm(ModelForm): class Meta: model = Extension - fields = ['name', 'origin'] + fields = ['name', 'need_infra', 'origin'] def __init__(self, *args, **kwargs): super(ExtensionForm, self).__init__(*args, **kwargs) @@ -124,7 +130,7 @@ class DelExtensionForm(ModelForm): extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple) class Meta: - exclude = ['name', 'origin'] + exclude = ['name', 'need_infra', 'origin'] model = Extension class MxForm(ModelForm): diff --git a/machines/migrations/0033_extension_need_infra.py b/machines/migrations/0033_extension_need_infra.py new file mode 100644 index 00000000..f603240c --- /dev/null +++ b/machines/migrations/0033_extension_need_infra.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0032_auto_20161119_1850'), + ] + + operations = [ + migrations.AddField( + model_name='extension', + name='need_infra', + field=models.BooleanField(default=False), + ), + ] diff --git a/machines/models.py b/machines/models.py index e094460c..764247ab 100644 --- a/machines/models.py +++ b/machines/models.py @@ -44,6 +44,7 @@ class Extension(models.Model): PRETTY_NAME = "Extensions dns" name = models.CharField(max_length=255, unique=True) + need_infra = models.BooleanField(default=False) origin = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True) def __str__(self): diff --git a/machines/templates/machines/aff_extension.html b/machines/templates/machines/aff_extension.html index 5753bf8d..68c03026 100644 --- a/machines/templates/machines/aff_extension.html +++ b/machines/templates/machines/aff_extension.html @@ -2,14 +2,16 @@ Extension - Enregistrement A origin + Autorisation infra pour utiliser l'extension + Enregistrement A origin {% for extension in extension_list %} {{ extension.name }} - {{ extension.origin }} + {{ extension.need_infra }} + {{ extension.origin }} {% if is_infra %} {% include 'buttons/edit.html' with href='machines:edit-extension' id=extension.id %} diff --git a/machines/views.py b/machines/views.py index 279fea8c..c6829b1f 100644 --- a/machines/views.py +++ b/machines/views.py @@ -462,7 +462,7 @@ def add_alias(request, interfaceid): if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user: messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit") return redirect("/users/profil/" + str(request.user.id)) - alias = AliasForm(request.POST or None) + alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',))) if alias.is_valid(): alias = alias.save(commit=False) alias.interface_parent = interface @@ -484,7 +484,7 @@ def edit_alias(request, aliasid): if not request.user.has_perms(('cableur',)) and alias_instance.interface_parent.machine.user != request.user: messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit") return redirect("/users/profil/" + str(request.user.id)) - alias = AliasForm(request.POST or None, instance=alias_instance) + alias = AliasForm(request.POST or None, instance=alias_instance, infra=request.user.has_perms(('infra',))) if alias.is_valid(): with transaction.atomic(), reversion.create_revision(): alias_instance = alias.save()