Commit 8fbcecd3 authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Acl infra nouvelle gestion

parent 0833f8c7
......@@ -177,9 +177,10 @@ class AliasForm(ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
infra = kwargs.pop('infra')
user = kwargs.pop('user')
super(AliasForm, self).__init__(*args, prefix=prefix, **kwargs)
if not infra:
can_use_all, reason = Extension.can_use_all(user)
if not can_use_all:
self.fields['extension'].queryset = Extension.objects.filter(
need_infra=False
)
......
......@@ -713,6 +713,12 @@ class Extension(models.Model):
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le droit\
de voir les extensions"
def can_use_all(user_request, *args, **kwargs):
"""Superdroit qui permet d'utiliser toutes les extensions sans restrictions
:param user_request: instance user qui fait l'edition
:return: True ou False avec la raison de l'échec le cas échéant"""
return user_request.has_perms(('infra',)), None
def can_view(self, user_request, *args, **kwargs):
"""Vérifie qu'on peut bien voir cette instance particulière avec
droit cableur
......
......@@ -736,7 +736,7 @@ def del_srv(request, instances):
@can_edit(Interface)
def add_alias(request, interface, interfaceid):
alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
alias = AliasForm(request.POST or None, user=request.user)
if alias.is_valid():
alias = alias.save(commit=False)
alias.cname = interface.domain
......@@ -755,7 +755,7 @@ def add_alias(request, interface, interfaceid):
@can_edit(Domain)
def edit_alias(request, domain_instance, domainid):
alias = AliasForm(request.POST or None, instance=domain_instance, infra=request.user.has_perms(('infra',)))
alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user)
if alias.is_valid():
with transaction.atomic(), reversion.create_revision():
domain_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