8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00

Ajoute des acl sur les extensions autorisées en alias

This commit is contained in:
Gabriel Detraz 2016-11-19 23:19:44 +01:00
parent 12a7702af4
commit 1de35ba16c
5 changed files with 34 additions and 6 deletions

View file

@ -64,6 +64,12 @@ class AliasForm(ModelForm):
model = Alias model = Alias
fields = ['alias','extension'] 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): class DelAliasForm(ModelForm):
alias = forms.ModelMultipleChoiceField(queryset=Alias.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple) alias = forms.ModelMultipleChoiceField(queryset=Alias.objects.all(), label="Alias actuels", widget=forms.CheckboxSelectMultiple)
@ -113,7 +119,7 @@ class DelIpTypeForm(ModelForm):
class ExtensionForm(ModelForm): class ExtensionForm(ModelForm):
class Meta: class Meta:
model = Extension model = Extension
fields = ['name', 'origin'] fields = ['name', 'need_infra', 'origin']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ExtensionForm, self).__init__(*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) extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple)
class Meta: class Meta:
exclude = ['name', 'origin'] exclude = ['name', 'need_infra', 'origin']
model = Extension model = Extension
class MxForm(ModelForm): class MxForm(ModelForm):

View file

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

View file

@ -44,6 +44,7 @@ class Extension(models.Model):
PRETTY_NAME = "Extensions dns" PRETTY_NAME = "Extensions dns"
name = models.CharField(max_length=255, unique=True) 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) origin = models.OneToOneField('IpList', on_delete=models.PROTECT, blank=True, null=True)
def __str__(self): def __str__(self):

View file

@ -2,14 +2,16 @@
<thead> <thead>
<tr> <tr>
<th>Extension</th> <th>Extension</th>
<th>Enregistrement A origin</th> <th>Autorisation infra pour utiliser l'extension</th>
<th>Enregistrement A origin</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for extension in extension_list %} {% for extension in extension_list %}
<tr> <tr>
<td>{{ extension.name }}</td> <td>{{ extension.name }}</td>
<td>{{ extension.origin }}</td> <td>{{ extension.need_infra }}</td>
<td>{{ extension.origin }}</td>
<td class="text-right"> <td class="text-right">
{% if is_infra %} {% if is_infra %}
{% include 'buttons/edit.html' with href='machines:edit-extension' id=extension.id %} {% include 'buttons/edit.html' with href='machines:edit-extension' id=extension.id %}

View file

@ -462,7 +462,7 @@ def add_alias(request, interfaceid):
if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user: 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") 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)) 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(): if alias.is_valid():
alias = alias.save(commit=False) alias = alias.save(commit=False)
alias.interface_parent = interface 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: 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") 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)) 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(): if alias.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
alias_instance = alias.save() alias_instance = alias.save()