Commit bab2b10a authored by chirac's avatar chirac

Ajoute des acl sur les extensions autorisées en alias

parent 5c2ee98b
......@@ -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):
......
# -*- 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),
),
]
......@@ -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):
......
......@@ -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 %}
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment