mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Acl infra nouvelle gestion
This commit is contained in:
parent
0833f8c793
commit
8fbcecd3ea
3 changed files with 11 additions and 4 deletions
|
@ -177,9 +177,10 @@ class AliasForm(ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
infra = kwargs.pop('infra')
|
user = kwargs.pop('user')
|
||||||
super(AliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
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(
|
self.fields['extension'].queryset = Extension.objects.filter(
|
||||||
need_infra=False
|
need_infra=False
|
||||||
)
|
)
|
||||||
|
|
|
@ -713,6 +713,12 @@ class Extension(models.Model):
|
||||||
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le droit\
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le droit\
|
||||||
de voir les extensions"
|
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):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
"""Vérifie qu'on peut bien voir cette instance particulière avec
|
"""Vérifie qu'on peut bien voir cette instance particulière avec
|
||||||
droit cableur
|
droit cableur
|
||||||
|
|
|
@ -736,7 +736,7 @@ def del_srv(request, instances):
|
||||||
@can_edit(Interface)
|
@can_edit(Interface)
|
||||||
def add_alias(request, interface, interfaceid):
|
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():
|
if alias.is_valid():
|
||||||
alias = alias.save(commit=False)
|
alias = alias.save(commit=False)
|
||||||
alias.cname = interface.domain
|
alias.cname = interface.domain
|
||||||
|
@ -755,7 +755,7 @@ def add_alias(request, interface, interfaceid):
|
||||||
@can_edit(Domain)
|
@can_edit(Domain)
|
||||||
def edit_alias(request, domain_instance, domainid):
|
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():
|
if alias.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
domain_instance = alias.save()
|
domain_instance = alias.save()
|
||||||
|
|
Loading…
Reference in a new issue