8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 23:43:47 +00:00

Ajoute des acl sur les extensions autorisées en alias

This commit is contained in:
chirac 2016-11-19 23:19:44 +01:00
parent 5c2ee98b8a
commit bab2b10acb
5 changed files with 34 additions and 6 deletions

View file

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

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"
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):

View file

@ -2,14 +2,16 @@
<thead>
<tr>
<th>Extension</th>
<th>Enregistrement A origin</th>
<th>Autorisation infra pour utiliser l'extension</th>
<th>Enregistrement A origin</th>
<th></th>
</tr>
</thead>
{% for extension in extension_list %}
<tr>
<td>{{ extension.name }}</td>
<td>{{ extension.origin }}</td>
<td>{{ extension.need_infra }}</td>
<td>{{ extension.origin }}</td>
<td class="text-right">
{% if is_infra %}
{% 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:
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()