From 5090742362c12a92430861a1563786a339e9a3fd Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 29 Dec 2017 01:42:00 +0100 Subject: [PATCH] Acl infra nouvelle gestion --- machines/forms.py | 5 +++-- machines/models.py | 6 ++++++ machines/views.py | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index fefdc9c3..96ee58af 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -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 ) diff --git a/machines/models.py b/machines/models.py index ab17217b..37d0cd73 100644 --- a/machines/models.py +++ b/machines/models.py @@ -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 diff --git a/machines/views.py b/machines/views.py index be51ec27..be19d1d0 100644 --- a/machines/views.py +++ b/machines/views.py @@ -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()