mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-09 11:26:27 +00:00
Merge branch 'acl_mixin' into 'master'
Acl mixin See merge request nounous/re2o!19
This commit is contained in:
commit
ea31157a71
19 changed files with 152 additions and 722 deletions
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
|
@ -59,7 +59,7 @@ from machines.models import regen
|
||||||
from re2o.field_permissions import FieldPermissionModelMixin
|
from re2o.field_permissions import FieldPermissionModelMixin
|
||||||
from re2o.mixins import AclMixin
|
from re2o.mixins import AclMixin
|
||||||
|
|
||||||
class Facture(FieldPermissionModelMixin, models.Model):
|
class Facture(AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
""" Définition du modèle des factures. Une facture regroupe une ou
|
""" Définition du modèle des factures. Une facture regroupe une ou
|
||||||
plusieurs ventes, rattachée à un user, et reliée à un moyen de paiement
|
plusieurs ventes, rattachée à un user, et reliée à un moyen de paiement
|
||||||
et si il y a lieu un numero pour les chèques. Possède les valeurs
|
et si il y a lieu un numero pour les chèques. Possède les valeurs
|
||||||
|
@ -114,13 +114,6 @@ class Facture(FieldPermissionModelMixin, models.Model):
|
||||||
).values_list('name', flat=True))
|
).values_list('name', flat=True))
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def get_instance(factureid, *args, **kwargs):
|
|
||||||
return Facture.objects.get(pk=factureid)
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
return user_request.has_perm('cotisations.add_facture'), u"Vous n'avez pas le\
|
|
||||||
droit de créer des factures"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.change_facture'):
|
if not user_request.has_perm('cotisations.change_facture'):
|
||||||
return False, u"Vous n'avez pas le droit d'éditer les factures"
|
return False, u"Vous n'avez pas le droit d'éditer les factures"
|
||||||
|
@ -144,11 +137,6 @@ class Facture(FieldPermissionModelMixin, models.Model):
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
if not user_request.has_perm('cotisations.view_facture'):
|
|
||||||
return False, u"Vous n'avez pas le droit de voir les factures"
|
|
||||||
return True, None
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.view_facture') and\
|
if not user_request.has_perm('cotisations.view_facture') and\
|
||||||
self.user != user_request:
|
self.user != user_request:
|
||||||
|
@ -192,7 +180,7 @@ def facture_post_delete(sender, **kwargs):
|
||||||
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
||||||
|
|
||||||
|
|
||||||
class Vente(models.Model):
|
class Vente(AclMixin, models.Model):
|
||||||
"""Objet vente, contient une quantité, une facture parente, un nom,
|
"""Objet vente, contient une quantité, une facture parente, un nom,
|
||||||
un prix. Peut-être relié à un objet cotisation, via le boolean
|
un prix. Peut-être relié à un objet cotisation, via le boolean
|
||||||
iscotisation"""
|
iscotisation"""
|
||||||
|
@ -277,14 +265,6 @@ class Vente(models.Model):
|
||||||
self.update_cotisation()
|
self.update_cotisation()
|
||||||
super(Vente, self).save(*args, **kwargs)
|
super(Vente, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def get_instance(venteid, *args, **kwargs):
|
|
||||||
return Vente.objects.get(pk=venteid)
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
return user_request.has_perm('cotisations.add_vente'), u"Vous n'avez pas le\
|
|
||||||
droit de créer des ventes"
|
|
||||||
return True, None
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.change_vente'):
|
if not user_request.has_perm('cotisations.change_vente'):
|
||||||
return False, u"Vous n'avez pas le droit d'éditer les ventes"
|
return False, u"Vous n'avez pas le droit d'éditer les ventes"
|
||||||
|
@ -308,11 +288,6 @@ class Vente(models.Model):
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
if not user_request.has_perm('cotisations.view_vente'):
|
|
||||||
return False, u"Vous n'avez pas le droit de voir les ventes"
|
|
||||||
return True, None
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.view_vente') and\
|
if not user_request.has_perm('cotisations.view_vente') and\
|
||||||
self.facture.user != user_request:
|
self.facture.user != user_request:
|
||||||
|
@ -402,9 +377,6 @@ class Article(AclMixin, models.Model):
|
||||||
"La durée est obligatoire si il s'agit d'une cotisation"
|
"La durée est obligatoire si il s'agit d'une cotisation"
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(articleid, *args, **kwargs):
|
|
||||||
return Article.objects.get(pk=articleid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -420,9 +392,6 @@ class Banque(AclMixin, models.Model):
|
||||||
("view_banque", "Peut voir un objet banque"),
|
("view_banque", "Peut voir un objet banque"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(banqueid, *args, **kwargs):
|
|
||||||
return Banque.objects.get(pk=banqueid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -443,9 +412,6 @@ class Paiement(AclMixin, models.Model):
|
||||||
("view_paiement", "Peut voir un objet paiement"),
|
("view_paiement", "Peut voir un objet paiement"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(paiementid, *args, **kwargs):
|
|
||||||
return Paiement.objects.get(pk=paiementid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.moyen
|
return self.moyen
|
||||||
|
|
||||||
|
@ -460,7 +426,7 @@ class Paiement(AclMixin, models.Model):
|
||||||
super(Paiement, self).save(*args, **kwargs)
|
super(Paiement, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Cotisation(models.Model):
|
class Cotisation(AclMixin, models.Model):
|
||||||
"""Objet cotisation, debut et fin, relié en onetoone à une vente"""
|
"""Objet cotisation, debut et fin, relié en onetoone à une vente"""
|
||||||
PRETTY_NAME = "Cotisations"
|
PRETTY_NAME = "Cotisations"
|
||||||
|
|
||||||
|
@ -485,14 +451,6 @@ class Cotisation(models.Model):
|
||||||
("change_all_cotisation", "Superdroit, peut modifier toutes les cotisations"),
|
("change_all_cotisation", "Superdroit, peut modifier toutes les cotisations"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(cotisationid, *args, **kwargs):
|
|
||||||
return Cotisations.objects.get(pk=cotisationid)
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
return user_request.has_perm('cotisations.add_cotisation'), u"Vous n'avez pas le\
|
|
||||||
droit de créer des cotisations"
|
|
||||||
return True, None
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.change_cotisation'):
|
if not user_request.has_perm('cotisations.change_cotisation'):
|
||||||
return False, u"Vous n'avez pas le droit d'éditer les cotisations"
|
return False, u"Vous n'avez pas le droit d'éditer les cotisations"
|
||||||
|
@ -512,11 +470,6 @@ class Cotisation(models.Model):
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
if not user_request.has_perm('cotisations.view_cotisation'):
|
|
||||||
return False, u"Vous n'avez pas le droit de voir les cotisations"
|
|
||||||
return True, None
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.view_cotisation') and\
|
if not user_request.has_perm('cotisations.view_cotisation') and\
|
||||||
self.vente.facture.user != user_request:
|
self.vente.facture.user != user_request:
|
||||||
|
|
|
@ -38,6 +38,7 @@ from .models import (
|
||||||
Nas,
|
Nas,
|
||||||
Service,
|
Service,
|
||||||
OuverturePort,
|
OuverturePort,
|
||||||
|
Ipv6List,
|
||||||
OuverturePortList
|
OuverturePortList
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,10 @@ class MachineAdmin(VersionAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Ipv6ListAdmin(VersionAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class IpTypeAdmin(VersionAdmin):
|
class IpTypeAdmin(VersionAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -124,6 +129,7 @@ admin.site.register(Interface, InterfaceAdmin)
|
||||||
admin.site.register(Domain, DomainAdmin)
|
admin.site.register(Domain, DomainAdmin)
|
||||||
admin.site.register(Service, ServiceAdmin)
|
admin.site.register(Service, ServiceAdmin)
|
||||||
admin.site.register(Vlan, VlanAdmin)
|
admin.site.register(Vlan, VlanAdmin)
|
||||||
|
admin.site.register(Ipv6List, Ipv6ListAdmin)
|
||||||
admin.site.register(Nas, NasAdmin)
|
admin.site.register(Nas, NasAdmin)
|
||||||
admin.site.register(OuverturePort, OuverturePortAdmin)
|
admin.site.register(OuverturePort, OuverturePortAdmin)
|
||||||
admin.site.register(OuverturePortList, OuverturePortListAdmin)
|
admin.site.register(OuverturePortList, OuverturePortListAdmin)
|
||||||
|
|
|
@ -66,9 +66,10 @@ class Machine(FieldPermissionModelMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(machineid, *args, **kwargs):
|
def get_instance(machineid, *args, **kwargs):
|
||||||
"""Récupère une instance
|
"""Get the Machine instance with machineid.
|
||||||
:param machineid: Instance id à trouver
|
:param userid: The id
|
||||||
:return: Une instance machine évidemment"""
|
:return: The user
|
||||||
|
"""
|
||||||
return Machine.objects.get(pk=machineid)
|
return Machine.objects.get(pk=machineid)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -85,6 +86,15 @@ class Machine(FieldPermissionModelMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
return user_request.has_perm('machines.change_machine_user'), "Vous ne pouvez pas modifier l'utilisateur de la machine."
|
return user_request.has_perm('machines.change_machine_user'), "Vous ne pouvez pas modifier l'utilisateur de la machine."
|
||||||
|
|
||||||
|
def can_view_all(user_request, *args, **kwargs):
|
||||||
|
"""Vérifie qu'on peut bien afficher l'ensemble des machines,
|
||||||
|
droit particulier correspondant
|
||||||
|
:param user_request: instance user qui fait l'edition
|
||||||
|
:return: True ou False avec la raison de l'échec le cas échéant"""
|
||||||
|
if not user_request.has_perm('machines.view_machine'):
|
||||||
|
return False, u"Vous ne pouvez pas afficher l'ensemble des machines sans permission"
|
||||||
|
return True, None
|
||||||
|
|
||||||
def can_create(user_request, userid, *args, **kwargs):
|
def can_create(user_request, userid, *args, **kwargs):
|
||||||
"""Vérifie qu'un user qui fait la requète peut bien créer la machine
|
"""Vérifie qu'un user qui fait la requète peut bien créer la machine
|
||||||
et n'a pas atteint son quota, et crée bien une machine à lui
|
et n'a pas atteint son quota, et crée bien une machine à lui
|
||||||
|
@ -132,15 +142,6 @@ class Machine(FieldPermissionModelMixin, models.Model):
|
||||||
d'un autre user que vous sans droit"
|
d'un autre user que vous sans droit"
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Vérifie qu'on peut bien afficher l'ensemble des machines,
|
|
||||||
droit particulier correspondant
|
|
||||||
:param user_request: instance user qui fait l'edition
|
|
||||||
:return: True ou False avec la raison de l'échec le cas échéant"""
|
|
||||||
if not user_request.has_perm('machines.view_machine'):
|
|
||||||
return False, u"Vous ne pouvez pas afficher l'ensemble des machines sans permission"
|
|
||||||
return True, 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 (soit
|
"""Vérifie qu'on peut bien voir cette instance particulière (soit
|
||||||
machine de soi, soit droit particulier
|
machine de soi, soit droit particulier
|
||||||
|
@ -185,13 +186,6 @@ class MachineType(AclMixin, models.Model):
|
||||||
machinetype"""
|
machinetype"""
|
||||||
return Interface.objects.filter(type=self)
|
return Interface.objects.filter(type=self)
|
||||||
|
|
||||||
def get_instance(machinetypeid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param machinetypeid: Instance id à trouver
|
|
||||||
:return: Une instance machinetype évidemment"""
|
|
||||||
return MachineType.objects.get(pk=machinetypeid)
|
|
||||||
|
|
||||||
|
|
||||||
def can_use_all(user_request, *args, **kwargs):
|
def can_use_all(user_request, *args, **kwargs):
|
||||||
"""Check if an user can use every MachineType.
|
"""Check if an user can use every MachineType.
|
||||||
|
|
||||||
|
@ -329,12 +323,6 @@ class IpType(AclMixin, models.Model):
|
||||||
self.clean()
|
self.clean()
|
||||||
super(IpType, self).save(*args, **kwargs)
|
super(IpType, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def get_instance(iptypeid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param iptypeid: Instance id à trouver
|
|
||||||
:return: Une instance iptype évidemment"""
|
|
||||||
return IpType.objects.get(pk=iptypeid)
|
|
||||||
|
|
||||||
def can_use_all(user_request, *args, **kwargs):
|
def can_use_all(user_request, *args, **kwargs):
|
||||||
"""Superdroit qui permet d'utiliser toutes les extensions sans restrictions
|
"""Superdroit qui permet d'utiliser toutes les extensions sans restrictions
|
||||||
:param user_request: instance user qui fait l'edition
|
:param user_request: instance user qui fait l'edition
|
||||||
|
@ -359,12 +347,6 @@ class Vlan(AclMixin, models.Model):
|
||||||
("view_vlan", "Peut voir un objet vlan"),
|
("view_vlan", "Peut voir un objet vlan"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(vlanid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param vlanid: Instance id à trouver
|
|
||||||
:return: Une instance vlan évidemment"""
|
|
||||||
return Vlan.objects.get(pk=vlanid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -404,12 +386,6 @@ class Nas(AclMixin, models.Model):
|
||||||
("view_nas", "Peut voir un objet Nas"),
|
("view_nas", "Peut voir un objet Nas"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(nasid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param nasid: Instance id à trouver
|
|
||||||
:return: Une instance nas évidemment"""
|
|
||||||
return Nas.objects.get(pk=nasid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -451,12 +427,6 @@ class SOA(AclMixin, models.Model):
|
||||||
("view_soa", "Peut voir un objet soa"),
|
("view_soa", "Peut voir un objet soa"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(soaid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param soaid: Instance id à trouver
|
|
||||||
:return: Une instance soa évidemment"""
|
|
||||||
return SOA.objects.get(pk=soaid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
|
@ -545,12 +515,6 @@ class Extension(AclMixin, models.Model):
|
||||||
entry += "@ IN AAAA " + str(self.origin_v6)
|
entry += "@ IN AAAA " + str(self.origin_v6)
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
def get_instance(extensionid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param extensionid: Instance id à trouver
|
|
||||||
:return: Une instance extension évidemment"""
|
|
||||||
return Extension.objects.get(pk=extensionid)
|
|
||||||
|
|
||||||
def can_use_all(user_request, *args, **kwargs):
|
def can_use_all(user_request, *args, **kwargs):
|
||||||
"""Superdroit qui permet d'utiliser toutes les extensions sans restrictions
|
"""Superdroit qui permet d'utiliser toutes les extensions sans restrictions
|
||||||
:param user_request: instance user qui fait l'edition
|
:param user_request: instance user qui fait l'edition
|
||||||
|
@ -587,12 +551,6 @@ class Mx(AclMixin, models.Model):
|
||||||
fichiers de zones"""
|
fichiers de zones"""
|
||||||
return "@ IN MX " + str(self.priority).ljust(3) + " " + str(self.name)
|
return "@ IN MX " + str(self.priority).ljust(3) + " " + str(self.name)
|
||||||
|
|
||||||
def get_instance(mxid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param mxid: Instance id à trouver
|
|
||||||
:return: Une instance mx évidemment"""
|
|
||||||
return Mx.objects.get(pk=mxid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name)
|
return str(self.zone) + ' ' + str(self.priority) + ' ' + str(self.name)
|
||||||
|
|
||||||
|
@ -614,12 +572,6 @@ class Ns(AclMixin, models.Model):
|
||||||
"""Renvoie un enregistrement NS complet pour les filezones"""
|
"""Renvoie un enregistrement NS complet pour les filezones"""
|
||||||
return "@ IN NS " + str(self.ns)
|
return "@ IN NS " + str(self.ns)
|
||||||
|
|
||||||
def get_instance(nsid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param nsid: Instance id à trouver
|
|
||||||
:return: Une instance ns évidemment"""
|
|
||||||
return Ns.objects.get(pk=nsid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.zone) + ' ' + str(self.ns)
|
return str(self.zone) + ' ' + str(self.ns)
|
||||||
|
|
||||||
|
@ -637,12 +589,6 @@ class Txt(AclMixin, models.Model):
|
||||||
("view_txt", "Peut voir un objet txt"),
|
("view_txt", "Peut voir un objet txt"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(txtid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param txtid: Instance id à trouver
|
|
||||||
:return: Une instance txt évidemment"""
|
|
||||||
return Txt.objects.get(pk=txtid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.zone) + " : " + str(self.field1) + " " +\
|
return str(self.zone) + " : " + str(self.field1) + " " +\
|
||||||
str(self.field2)
|
str(self.field2)
|
||||||
|
@ -701,12 +647,6 @@ class Srv(AclMixin, models.Model):
|
||||||
("view_soa", "Peut voir un objet soa"),
|
("view_soa", "Peut voir un objet soa"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(srvid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param srvid: Instance id à trouver
|
|
||||||
:return: Une instance srv évidemment"""
|
|
||||||
return Srv.objects.get(pk=srvid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.service) + ' ' + str(self.protocole) + ' ' +\
|
return str(self.service) + ' ' + str(self.protocole) + ' ' +\
|
||||||
str(self.extension) + ' ' + str(self.priority) +\
|
str(self.extension) + ' ' + str(self.priority) +\
|
||||||
|
@ -721,7 +661,7 @@ class Srv(AclMixin, models.Model):
|
||||||
str(self.port) + ' ' + str(self.target) + '.'
|
str(self.port) + ' ' + str(self.target) + '.'
|
||||||
|
|
||||||
|
|
||||||
class Interface(FieldPermissionModelMixin,models.Model):
|
class Interface(AclMixin, FieldPermissionModelMixin,models.Model):
|
||||||
""" Une interface. Objet clef de l'application machine :
|
""" Une interface. Objet clef de l'application machine :
|
||||||
- une address mac unique. Possibilité de la rendre unique avec le
|
- une address mac unique. Possibilité de la rendre unique avec le
|
||||||
typemachine
|
typemachine
|
||||||
|
@ -879,12 +819,6 @@ class Interface(FieldPermissionModelMixin,models.Model):
|
||||||
correspondent pas")
|
correspondent pas")
|
||||||
super(Interface, self).save(*args, **kwargs)
|
super(Interface, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def get_instance(interfaceid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param interfaceid: Instance id à trouver
|
|
||||||
:return: Une instance interface évidemment"""
|
|
||||||
return Interface.objects.get(pk=interfaceid)
|
|
||||||
|
|
||||||
def can_create(user_request, machineid, *args, **kwargs):
|
def can_create(user_request, machineid, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits infra pour créer
|
"""Verifie que l'user a les bons droits infra pour créer
|
||||||
une interface, ou bien que la machine appartient bien à l'user
|
une interface, ou bien que la machine appartient bien à l'user
|
||||||
|
@ -936,16 +870,6 @@ class Interface(FieldPermissionModelMixin,models.Model):
|
||||||
d'un autre user que vous sans droit"
|
d'un autre user que vous sans droit"
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Vérifie qu'on peut bien afficher l'ensemble des interfaces,
|
|
||||||
droit particulier view objet correspondant
|
|
||||||
:param user_request: instance user qui fait l'edition
|
|
||||||
:return: True ou False avec la raison de l'échec le cas échéant"""
|
|
||||||
if not user_request.has_perm('machines.view_interface'):
|
|
||||||
return False, u"Vous n'avez pas le droit de voir des machines autre\
|
|
||||||
que les vôtres"
|
|
||||||
return True, 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 view objet ou qu'elle appartient à l'user
|
droit view objet ou qu'elle appartient à l'user
|
||||||
|
@ -984,7 +908,7 @@ class Interface(FieldPermissionModelMixin,models.Model):
|
||||||
return self.ipv4 and not self.has_private_ip()
|
return self.ipv4 and not self.has_private_ip()
|
||||||
|
|
||||||
|
|
||||||
class Ipv6List(FieldPermissionModelMixin, models.Model):
|
class Ipv6List(AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
PRETTY_NAME = 'Enregistrements Ipv6 des machines'
|
PRETTY_NAME = 'Enregistrements Ipv6 des machines'
|
||||||
|
|
||||||
ipv6 = models.GenericIPAddressField(
|
ipv6 = models.GenericIPAddressField(
|
||||||
|
@ -1000,12 +924,6 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
|
||||||
("change_ipv6list_slaac_ip", "Peut changer la valeur slaac sur une ipv6"),
|
("change_ipv6list_slaac_ip", "Peut changer la valeur slaac sur une ipv6"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(ipv6listid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param interfaceid: Instance id à trouver
|
|
||||||
:return: Une instance interface évidemment"""
|
|
||||||
return Ipv6List.objects.get(pk=ipv6listid)
|
|
||||||
|
|
||||||
def can_create(user_request, interfaceid, *args, **kwargs):
|
def can_create(user_request, interfaceid, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits infra pour créer
|
"""Verifie que l'user a les bons droits infra pour créer
|
||||||
une ipv6, ou possède l'interface associée
|
une ipv6, ou possède l'interface associée
|
||||||
|
@ -1050,16 +968,6 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
|
||||||
d'un autre user que vous sans droit"
|
d'un autre user que vous sans droit"
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Vérifie qu'on peut bien afficher l'ensemble des interfaces,
|
|
||||||
droit particulier view objet correspondant
|
|
||||||
:param user_request: instance user qui fait l'edition
|
|
||||||
:return: True ou False avec la raison de l'échec le cas échéant"""
|
|
||||||
if not user_request.has_perm('machines.view_ipv6list'):
|
|
||||||
return False, u"Vous n'avez pas le droit de voir des machines autre\
|
|
||||||
que les vôtres"
|
|
||||||
return True, 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 view objet ou qu'elle appartient à l'user
|
droit view objet ou qu'elle appartient à l'user
|
||||||
|
@ -1104,7 +1012,7 @@ class Ipv6List(FieldPermissionModelMixin, models.Model):
|
||||||
return str(self.ipv6)
|
return str(self.ipv6)
|
||||||
|
|
||||||
|
|
||||||
class Domain(models.Model):
|
class Domain(AclMixin, models.Model):
|
||||||
""" Objet domain. Enregistrement A et CNAME en même temps : permet de
|
""" Objet domain. Enregistrement A et CNAME en même temps : permet de
|
||||||
stocker les alias et les nom de machines, suivant si interface_parent
|
stocker les alias et les nom de machines, suivant si interface_parent
|
||||||
ou cname sont remplis"""
|
ou cname sont remplis"""
|
||||||
|
@ -1197,12 +1105,6 @@ class Domain(models.Model):
|
||||||
else:
|
else:
|
||||||
return self.cname.get_parent_interface()
|
return self.cname.get_parent_interface()
|
||||||
|
|
||||||
def get_instance(domainid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param domainid: Instance id à trouver
|
|
||||||
:return: Une instance domain évidemment"""
|
|
||||||
return Domain.objects.get(pk=domainid)
|
|
||||||
|
|
||||||
def can_create(user_request, interfaceid, *args, **kwargs):
|
def can_create(user_request, interfaceid, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits infra pour créer
|
"""Verifie que l'user a les bons droits infra pour créer
|
||||||
un domain, ou possède l'interface associée
|
un domain, ou possède l'interface associée
|
||||||
|
@ -1252,16 +1154,6 @@ class Domain(models.Model):
|
||||||
d'un autre user que vous sans droit"
|
d'un autre user que vous sans droit"
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Vérifie qu'on peut bien afficher l'ensemble des domain,
|
|
||||||
droit particulier view objet correspondant
|
|
||||||
:param user_request: instance user qui fait l'edition
|
|
||||||
:return: True ou False avec la raison de l'échec le cas échéant"""
|
|
||||||
if not user_request.has_perm('machines.view_domain'):
|
|
||||||
return False, u"Vous ne pouvez pas supprimer un alias à une machine\
|
|
||||||
d'un autre user que vous sans droit"
|
|
||||||
return True, 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 view objet ou qu'elle appartient à l'user
|
droit view objet ou qu'elle appartient à l'user
|
||||||
|
@ -1306,12 +1198,6 @@ class IpList(AclMixin, models.Model):
|
||||||
self.clean()
|
self.clean()
|
||||||
super(IpList, self).save(*args, **kwargs)
|
super(IpList, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def get_instance(iplistid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param iplistid: Instance id à trouver
|
|
||||||
:return: Une instance iplist évidemment"""
|
|
||||||
return IpList.objects.get(pk=iplistid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.ipv4
|
return self.ipv4
|
||||||
|
|
||||||
|
@ -1357,12 +1243,6 @@ class Service(AclMixin, models.Model):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Service, self).save(*args, **kwargs)
|
super(Service, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def get_instance(serviceid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param serviceid: Instance id à trouver
|
|
||||||
:return: Une instance service évidemment"""
|
|
||||||
return Service.objects.get(pk=serviceid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.service_type)
|
return str(self.service_type)
|
||||||
|
|
||||||
|
@ -1403,12 +1283,6 @@ class Service_link(AclMixin, models.Model):
|
||||||
) < timezone.now()
|
) < timezone.now()
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(servicelinkid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param servicelinkid: Instance id à trouver
|
|
||||||
:return: Une instance servicelink évidemment"""
|
|
||||||
return ServiceLink.objects.get(pk=servicelinkid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.server) + " " + str(self.service)
|
return str(self.server) + " " + str(self.service)
|
||||||
|
|
||||||
|
@ -1427,12 +1301,6 @@ class OuverturePortList(AclMixin, models.Model):
|
||||||
("view_ouvertureportlist", "Peut voir un objet ouvertureport"),
|
("view_ouvertureportlist", "Peut voir un objet ouvertureport"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(ouvertureportlistid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param ouvertureportlistid: Instance id à trouver
|
|
||||||
:return: Une instance ouvertureportlist évidemment"""
|
|
||||||
return OuverturePortList.objects.get(pk=ouvertureportlistid)
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
def can_delete(self, user_request, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits bureau pour delete
|
"""Verifie que l'user a les bons droits bureau pour delete
|
||||||
cette instance ouvertureportlist
|
cette instance ouvertureportlist
|
||||||
|
@ -1516,12 +1384,6 @@ class OuverturePort(AclMixin, models.Model):
|
||||||
default=OUT,
|
default=OUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(ouvertureportid, *args, **kwargs):
|
|
||||||
"""Récupère une instance
|
|
||||||
:param ouvertureportid: Instance id à trouver
|
|
||||||
:return: Une instance ouvertureport évidemment"""
|
|
||||||
return OuverturePort.objects.get(pk=ouvertureportid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.begin == self.end:
|
if self.begin == self.end:
|
||||||
return str(self.begin)
|
return str(self.begin)
|
||||||
|
|
|
@ -34,7 +34,7 @@ from django.dispatch import receiver
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
from .aes_field import AESEncryptedField
|
from .aes_field import AESEncryptedField
|
||||||
|
from re2o.mixins import AclMixin
|
||||||
|
|
||||||
class PreferencesModel(models.Model):
|
class PreferencesModel(models.Model):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -54,7 +54,7 @@ class PreferencesModel(models.Model):
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class OptionalUser(PreferencesModel):
|
class OptionalUser(AclMixin, PreferencesModel):
|
||||||
"""Options pour l'user : obligation ou nom du telephone,
|
"""Options pour l'user : obligation ou nom du telephone,
|
||||||
activation ou non du solde, autorisation du negatif, fingerprint etc"""
|
activation ou non du solde, autorisation du negatif, fingerprint etc"""
|
||||||
PRETTY_NAME = "Options utilisateur"
|
PRETTY_NAME = "Options utilisateur"
|
||||||
|
@ -101,58 +101,6 @@ class OptionalUser(PreferencesModel):
|
||||||
("view_optionaluser", "Peut voir les options de l'user"),
|
("view_optionaluser", "Peut voir les options de l'user"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
|
||||||
return OptionalUser.objects.get_or_create()
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a OptionalUser object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create a user object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.add_optionaluser'), u"Vous n'avez pas le droit\
|
|
||||||
de créer les préférences concernant les users"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a OptionalUser object.
|
|
||||||
|
|
||||||
:param self: The OptionalUser which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.change_optionaluser'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant les users"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a OptionalUser object.
|
|
||||||
|
|
||||||
:param self: The OptionalUser which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.delete_optionaluser'), u"Vous n'avez pas le droit\
|
|
||||||
de supprimer les préférences concernant les users"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every OptionalUser objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_optionaluser'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant les utilisateurs"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a OptionalUser object.
|
|
||||||
|
|
||||||
:param self: The targeted OptionalUser.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_optionaluser'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant les utilisateurs"
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Creation du mode de paiement par solde"""
|
"""Creation du mode de paiement par solde"""
|
||||||
if self.user_solde:
|
if self.user_solde:
|
||||||
|
@ -169,7 +117,7 @@ def optionaluser_post_save(sender, **kwargs):
|
||||||
user_pref.set_in_cache()
|
user_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class OptionalMachine(PreferencesModel):
|
class OptionalMachine(AclMixin, PreferencesModel):
|
||||||
"""Options pour les machines : maximum de machines ou d'alias par user
|
"""Options pour les machines : maximum de machines ou d'alias par user
|
||||||
sans droit, activation de l'ipv6"""
|
sans droit, activation de l'ipv6"""
|
||||||
PRETTY_NAME = "Options machines"
|
PRETTY_NAME = "Options machines"
|
||||||
|
@ -205,59 +153,6 @@ class OptionalMachine(PreferencesModel):
|
||||||
("view_optionalmachine", "Peut voir les options de machine"),
|
("view_optionalmachine", "Peut voir les options de machine"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
|
||||||
return OptionalMachine.objects.get_or_create()
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a OptionalMachine object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create an object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.add_optionalmachine'), u"Vous n'avez pas le droit\
|
|
||||||
de créer les préférences concernant les machines"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a OptionalMachine object.
|
|
||||||
|
|
||||||
:param self: The OptionalMachine which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.change_optionalmachine'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant les machines"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a OptionalMachine object.
|
|
||||||
|
|
||||||
:param self: The OptionalMachine which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return user_request.has_perm('preferences.delete_optionalmachine'), u"Vous n'avez pas le droit\
|
|
||||||
de supprimer les préférences concernant les machines"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every OptionalMachine objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_optionalmachine'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant les machines"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a OptionalMachine object.
|
|
||||||
|
|
||||||
:param self: The targeted OptionalMachine.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_optionalmachine'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant les machines"
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=OptionalMachine)
|
@receiver(post_save, sender=OptionalMachine)
|
||||||
def optionalmachine_post_save(sender, **kwargs):
|
def optionalmachine_post_save(sender, **kwargs):
|
||||||
|
@ -269,7 +164,7 @@ def optionalmachine_post_save(sender, **kwargs):
|
||||||
interface.sync_ipv6()
|
interface.sync_ipv6()
|
||||||
|
|
||||||
|
|
||||||
class OptionalTopologie(PreferencesModel):
|
class OptionalTopologie(AclMixin, PreferencesModel):
|
||||||
"""Reglages pour la topologie : mode d'accès radius, vlan où placer
|
"""Reglages pour la topologie : mode d'accès radius, vlan où placer
|
||||||
les machines en accept ou reject"""
|
les machines en accept ou reject"""
|
||||||
PRETTY_NAME = "Options topologie"
|
PRETTY_NAME = "Options topologie"
|
||||||
|
@ -306,58 +201,6 @@ class OptionalTopologie(PreferencesModel):
|
||||||
("view_optionaltopologie", "Peut voir les options de topologie"),
|
("view_optionaltopologie", "Peut voir les options de topologie"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
|
||||||
return OptionalTopologie.objects.get_or_create()
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a OptionalTopologie object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create an object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.add_optionaltopologie'), u"Vous n'avez pas le droit\
|
|
||||||
de créer les préférences concernant la topologie"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a OptionalTopologie object.
|
|
||||||
|
|
||||||
:param self: The OptionalTopologie which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.change_optionaltopologie'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant la topologie"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a OptionalTopologie object.
|
|
||||||
|
|
||||||
:param self: The OptionalTopologie which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.delete_optionaltoplogie'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant la topologie"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every OptionalTopologie objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_optionaltopologie'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant la topologie"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a OptionalTopologie object.
|
|
||||||
|
|
||||||
:param self: The targeted OptionalTopologie.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_optionaltopologie'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant la topologie"
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=OptionalTopologie)
|
@receiver(post_save, sender=OptionalTopologie)
|
||||||
def optionaltopologie_post_save(sender, **kwargs):
|
def optionaltopologie_post_save(sender, **kwargs):
|
||||||
|
@ -366,7 +209,7 @@ def optionaltopologie_post_save(sender, **kwargs):
|
||||||
topologie_pref.set_in_cache()
|
topologie_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class GeneralOption(PreferencesModel):
|
class GeneralOption(AclMixin, PreferencesModel):
|
||||||
"""Options générales : nombre de resultats par page, nom du site,
|
"""Options générales : nombre de resultats par page, nom du site,
|
||||||
temps où les liens sont valides"""
|
temps où les liens sont valides"""
|
||||||
PRETTY_NAME = "Options générales"
|
PRETTY_NAME = "Options générales"
|
||||||
|
@ -398,59 +241,6 @@ class GeneralOption(PreferencesModel):
|
||||||
("view_generaloption", "Peut voir les options générales"),
|
("view_generaloption", "Peut voir les options générales"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
|
||||||
return GeneralOption.objects.get_or_create()
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a GeneralOption object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create an object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.add_generaloption'), u"Vous n'avez pas le droit\
|
|
||||||
de créer les préférences générales"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a GeneralOption object.
|
|
||||||
|
|
||||||
:param self: The GeneralOption which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.change_generaloption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences générales"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a GeneralOption object.
|
|
||||||
|
|
||||||
:param self: The GeneralOption which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.delete_generaloption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences générales"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every GeneralOption objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return user_request.has_perm('preferences.view_generaloption'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences générales"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a GeneralOption object.
|
|
||||||
|
|
||||||
:param self: The targeted GeneralOption.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_generaloption'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences générales"
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=GeneralOption)
|
@receiver(post_save, sender=GeneralOption)
|
||||||
def generaloption_post_save(sender, **kwargs):
|
def generaloption_post_save(sender, **kwargs):
|
||||||
|
@ -459,7 +249,7 @@ def generaloption_post_save(sender, **kwargs):
|
||||||
general_pref.set_in_cache()
|
general_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class Service(models.Model):
|
class Service(AclMixin, models.Model):
|
||||||
"""Liste des services affichés sur la page d'accueil : url, description,
|
"""Liste des services affichés sur la page d'accueil : url, description,
|
||||||
image et nom"""
|
image et nom"""
|
||||||
name = models.CharField(max_length=32)
|
name = models.CharField(max_length=32)
|
||||||
|
@ -472,65 +262,11 @@ class Service(models.Model):
|
||||||
("view_service", "Peut voir les options de service"),
|
("view_service", "Peut voir les options de service"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(serviceid, *args, **kwargs):
|
|
||||||
return Service.objects.get(pk=serviceid)
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a Service object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create an object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return user_request.has_perm('preferences.add_service'), u"Vous n'avez pas le droit\
|
|
||||||
de créer un service pour la page d'accueil"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a Service object.
|
|
||||||
|
|
||||||
:param self: The Service which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.change_service'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les services pour la page d'accueil"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a Service object.
|
|
||||||
|
|
||||||
:param self: The Right which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.delete_service'), u"Vous n'avez pas le droit\
|
|
||||||
de supprimer les services pour la page d'accueil"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every Service objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return user_request.has_perm('preferences.view_service'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les services pour la page d'accueil"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a Service object.
|
|
||||||
|
|
||||||
:param self: The targeted Service.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_service'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les services pour la page d'accueil"
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
|
|
||||||
class AssoOption(PreferencesModel):
|
class AssoOption(AclMixin, PreferencesModel):
|
||||||
"""Options générales de l'asso : siret, addresse, nom, etc"""
|
"""Options générales de l'asso : siret, addresse, nom, etc"""
|
||||||
PRETTY_NAME = "Options de l'association"
|
PRETTY_NAME = "Options de l'association"
|
||||||
|
|
||||||
|
@ -579,58 +315,6 @@ class AssoOption(PreferencesModel):
|
||||||
("view_assooption", "Peut voir les options de l'asso"),
|
("view_assooption", "Peut voir les options de l'asso"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
|
||||||
return AssoOption.objects.get_or_create()
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a AssoOption object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create an object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.add_assooption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant l'association"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a AssoOption object.
|
|
||||||
|
|
||||||
:param self: The AssoOption which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.change_assooption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant l'association"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a AssoOption object.
|
|
||||||
|
|
||||||
:param self: The AssoOption which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.delete_assooption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant l'association"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every AssoOption objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_assooption'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant l'association"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a AssoOption object.
|
|
||||||
|
|
||||||
:param self: The targeted AssoOption.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_assooption'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant l'association"
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=AssoOption)
|
@receiver(post_save, sender=AssoOption)
|
||||||
def assooption_post_save(sender, **kwargs):
|
def assooption_post_save(sender, **kwargs):
|
||||||
|
@ -639,7 +323,7 @@ def assooption_post_save(sender, **kwargs):
|
||||||
asso_pref.set_in_cache()
|
asso_pref.set_in_cache()
|
||||||
|
|
||||||
|
|
||||||
class MailMessageOption(models.Model):
|
class MailMessageOption(AclMixin, models.Model):
|
||||||
"""Reglages, mail de bienvenue et autre"""
|
"""Reglages, mail de bienvenue et autre"""
|
||||||
PRETTY_NAME = "Options de corps de mail"
|
PRETTY_NAME = "Options de corps de mail"
|
||||||
|
|
||||||
|
@ -650,56 +334,3 @@ class MailMessageOption(models.Model):
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_mailmessageoption", "Peut voir les options de mail"),
|
("view_mailmessageoption", "Peut voir les options de mail"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
|
||||||
return MailMessageOption.objects.get_or_create()
|
|
||||||
|
|
||||||
def can_create(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can create a MailMessageOption object.
|
|
||||||
|
|
||||||
:param user_request: The user who wants to create an object.
|
|
||||||
:return: a message and a boolean which is True if the user can create.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.add_mailmessageoption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant les mails"
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can edit a MailMessageOption object.
|
|
||||||
|
|
||||||
:param self: The MailMessageOption which is to be edited.
|
|
||||||
:param user_request: The user who requests to edit self.
|
|
||||||
:return: a message and a boolean which is True if edition is granted.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return user_request.has_perm('preferences.change_mailmessageoption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant les mails"
|
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete a AssoOption object.
|
|
||||||
|
|
||||||
:param self: The AssoOption which is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if deletion is granted, and a message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.delete_mailmessageoption'), u"Vous n'avez pas le droit\
|
|
||||||
d'éditer les préférences concernant les mails"
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every AssoOption objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_mailmessageoption'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant les mails"
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can view a AssoOption object.
|
|
||||||
|
|
||||||
:param self: The targeted AssoOption.
|
|
||||||
:param user_request: The user who ask for viewing the target.
|
|
||||||
:return: A boolean telling if the acces is granted and an explanation
|
|
||||||
text
|
|
||||||
"""
|
|
||||||
return user_request.has_perm('preferences.view_mailmessageoption'), u"Vous n'avez pas le droit\
|
|
||||||
de voir les préférences concernant les mails"
|
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
# se veut agnostique au réseau considéré, de manière à être installable en
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
||||||
# quelques clics.
|
# quelques clics.
|
||||||
#
|
#
|
||||||
# Copyright © 2017 Gabriel Détraz
|
# Copyright © 2018 Gabriel Détraz
|
||||||
# Copyright © 2017 Goulven Kermarec
|
|
||||||
# Copyright © 2017 Augustin Lemesle
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -30,34 +28,42 @@ class AclMixin(object):
|
||||||
def get_modulename(cls):
|
def get_modulename(cls):
|
||||||
return str(cls.__module__).split('.')[0].lower()
|
return str(cls.__module__).split('.')[0].lower()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_instance(cls, *args, **kwargs):
|
||||||
|
"""Récupère une instance
|
||||||
|
:param objectid: Instance id à trouver
|
||||||
|
:return: Une instance de la classe évidemment"""
|
||||||
|
object_id = kwargs.get(cls.get_classname() + 'id')
|
||||||
|
return cls.objects.get(pk=object_id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_create(cls, user_request, *args, **kwargs):
|
def can_create(cls, user_request, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits infra pour créer
|
"""Verifie que l'user a les bons droits pour créer
|
||||||
un servicelink
|
un object
|
||||||
:param user_request: instance utilisateur qui fait la requête
|
:param user_request: instance utilisateur qui fait la requête
|
||||||
:return: soit True, soit False avec la raison de l'échec"""
|
:return: soit True, soit False avec la raison de l'échec"""
|
||||||
return user_request.has_perm(cls.get_modulename() + '.add_' + cls.get_classname()), u"Vous n'avez pas le droit\
|
return user_request.has_perm(cls.get_modulename() + '.add_' + cls.get_classname()), u"Vous n'avez pas le droit\
|
||||||
de créer un " + cls.get_classname()
|
de créer un " + cls.get_classname()
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits infra pour editer
|
"""Verifie que l'user a les bons droits pour editer
|
||||||
cette instance servicelink
|
cette instance
|
||||||
:param self: Instance servicelink à editer
|
:param self: Instance à editer
|
||||||
:param user_request: Utilisateur qui fait la requête
|
:param user_request: Utilisateur qui fait la requête
|
||||||
:return: soit True, soit False avec la raison de l'échec"""
|
:return: soit True, soit False avec la raison de l'échec"""
|
||||||
return user_request.has_perm(self.get_modulename() + '.change_' + self.get_classname()), u"Vous n'avez pas le droit d'éditer des " + self.get_classname()
|
return user_request.has_perm(self.get_modulename() + '.change_' + self.get_classname()), u"Vous n'avez pas le droit d'éditer des " + self.get_classname()
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
def can_delete(self, user_request, *args, **kwargs):
|
||||||
"""Verifie que l'user a les bons droits infra pour delete
|
"""Verifie que l'user a les bons droits pour delete
|
||||||
cette instance servicelink
|
cette instance
|
||||||
:param self: Instance servicelink à delete
|
:param self: Instance à delete
|
||||||
:param user_request: Utilisateur qui fait la requête
|
:param user_request: Utilisateur qui fait la requête
|
||||||
:return: soit True, soit False avec la raison de l'échec"""
|
:return: soit True, soit False avec la raison de l'échec"""
|
||||||
return user_request.has_perm(self.get_modulename() + '.delete_' + self.get_classname()), u"Vous n'avez pas le droit d'éditer des " + self.get_classname()
|
return user_request.has_perm(self.get_modulename() + '.delete_' + self.get_classname()), u"Vous n'avez pas le droit d'éditer des " + self.get_classname()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_view_all(cls, user_request, *args, **kwargs):
|
def can_view_all(cls, user_request, *args, **kwargs):
|
||||||
"""Vérifie qu'on peut bien afficher l'ensemble des services,
|
"""Vérifie qu'on peut bien afficher l'ensemble des objets,
|
||||||
droit particulier view objet correspondant
|
droit particulier view objet correspondant
|
||||||
:param user_request: instance user qui fait l'edition
|
:param user_request: instance user qui fait l'edition
|
||||||
:return: True ou False avec la raison de l'échec le cas échéant"""
|
:return: True ou False avec la raison de l'échec le cas échéant"""
|
||||||
|
@ -66,7 +72,7 @@ class AclMixin(object):
|
||||||
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 view objet
|
droit view objet
|
||||||
:param self: instance service à voir
|
:param self: instance à voir
|
||||||
:param user_request: instance user qui fait l'edition
|
:param user_request: instance user qui fait l'edition
|
||||||
:return: True ou False avec la raison de l'échec le cas échéant"""
|
:return: True ou False avec la raison de l'échec le cas échéant"""
|
||||||
return user_request.has_perm(self.get_modulename() + '.view_' + self.get_classname()), u"Vous n'avez pas le droit de voir des " + self.get_classname()
|
return user_request.has_perm(self.get_modulename() + '.view_' + self.get_classname()), u"Vous n'avez pas le droit de voir des " + self.get_classname()
|
||||||
|
|
|
@ -65,7 +65,7 @@ HISTORY_BIND = {
|
||||||
'school' : users.models.School,
|
'school' : users.models.School,
|
||||||
'listright' : users.models.ListRight,
|
'listright' : users.models.ListRight,
|
||||||
'serviceuser' : users.models.ServiceUser,
|
'serviceuser' : users.models.ServiceUser,
|
||||||
'shell' : users.models.ListShell,
|
'listshell' : users.models.ListShell,
|
||||||
},
|
},
|
||||||
'preferences' : {
|
'preferences' : {
|
||||||
'service' : preferences.models.Service,
|
'service' : preferences.models.Service,
|
||||||
|
@ -81,9 +81,9 @@ HISTORY_BIND = {
|
||||||
'port' : topologie.models.Port,
|
'port' : topologie.models.Port,
|
||||||
'room' : topologie.models.Room,
|
'room' : topologie.models.Room,
|
||||||
'stack' : topologie.models.Stack,
|
'stack' : topologie.models.Stack,
|
||||||
'model_switch' : topologie.models.ModelSwitch,
|
'modelswitch' : topologie.models.ModelSwitch,
|
||||||
'constructor_switch' : topologie.models.ConstructorSwitch,
|
'constructorswitch' : topologie.models.ConstructorSwitch,
|
||||||
'ap' : topologie.models.AccessPoint,
|
'accesspoint' : topologie.models.AccessPoint,
|
||||||
},
|
},
|
||||||
'machines' : {
|
'machines' : {
|
||||||
'machine' : machines.models.Machine,
|
'machine' : machines.models.Machine,
|
||||||
|
@ -99,7 +99,7 @@ HISTORY_BIND = {
|
||||||
'ns' : machines.models.Ns,
|
'ns' : machines.models.Ns,
|
||||||
'service' : machines.models.Service,
|
'service' : machines.models.Service,
|
||||||
'vlan' : machines.models.Vlan,
|
'vlan' : machines.models.Vlan,
|
||||||
'nas' : machines.models.Vlan,
|
'nas' : machines.models.Nas,
|
||||||
'ipv6list' : machines.models.Ipv6List,
|
'ipv6list' : machines.models.Ipv6List,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -128,8 +128,10 @@ def history(request, application, object_name, object_id):
|
||||||
model = HISTORY_BIND[application][object_name]
|
model = HISTORY_BIND[application][object_name]
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
raise Http404(u"Il n'existe pas d'historique pour ce modèle.")
|
raise Http404(u"Il n'existe pas d'historique pour ce modèle.")
|
||||||
|
object_name_id = object_name + 'id'
|
||||||
|
kwargs = {object_name_id: object_id}
|
||||||
try:
|
try:
|
||||||
instance = model.get_instance(object_id)
|
instance = model.get_instance(**kwargs)
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante")
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
|
|
19
topologie/migrations/0055_auto_20180329_0431.py
Normal file
19
topologie/migrations/0055_auto_20180329_0431.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-03-29 02:31
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0054_auto_20180326_1742'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='accesspoint',
|
||||||
|
options={'permissions': (('view_accesspoint', 'Peut voir une borne'),)},
|
||||||
|
),
|
||||||
|
]
|
|
@ -67,9 +67,6 @@ class Stack(AclMixin, models.Model):
|
||||||
("view_stack", "Peut voir un objet stack"),
|
("view_stack", "Peut voir un objet stack"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(stack_id, *args, **kwargs):
|
|
||||||
return Stack.objects.get(pk=stack_id)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return " ".join([self.name, self.stack_id])
|
return " ".join([self.name, self.stack_id])
|
||||||
|
|
||||||
|
@ -105,9 +102,6 @@ class AccessPoint(AclMixin, Machine):
|
||||||
("view_accesspoint", "Peut voir une borne"),
|
("view_accesspoint", "Peut voir une borne"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(ap_id, *args, **kwargs):
|
|
||||||
return AccessPoint.objects.get(pk=ap_id)
|
|
||||||
|
|
||||||
|
|
||||||
class Switch(AclMixin, Machine):
|
class Switch(AclMixin, Machine):
|
||||||
""" Definition d'un switch. Contient un nombre de ports (number),
|
""" Definition d'un switch. Contient un nombre de ports (number),
|
||||||
|
@ -146,9 +140,6 @@ class Switch(AclMixin, Machine):
|
||||||
("view_switch", "Peut voir un objet switch"),
|
("view_switch", "Peut voir un objet switch"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(switch_id, *args, **kwargs):
|
|
||||||
return Switch.objects.get(pk=switch_id)
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
""" Verifie que l'id stack est dans le bon range
|
""" Verifie que l'id stack est dans le bon range
|
||||||
Appelle également le clean de la classe parente"""
|
Appelle également le clean de la classe parente"""
|
||||||
|
@ -210,9 +201,6 @@ class ModelSwitch(AclMixin, models.Model):
|
||||||
("view_modelswitch", "Peut voir un objet modelswitch"),
|
("view_modelswitch", "Peut voir un objet modelswitch"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(model_switch_id, *args, **kwargs):
|
|
||||||
return ModelSwitch.objects.get(pk=model_switch_id)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.constructor) + ' ' + self.reference
|
return str(self.constructor) + ' ' + self.reference
|
||||||
|
|
||||||
|
@ -227,9 +215,6 @@ class ConstructorSwitch(AclMixin, models.Model):
|
||||||
("view_constructorswitch", "Peut voir un objet constructorswitch"),
|
("view_constructorswitch", "Peut voir un objet constructorswitch"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(constructor_switch_id, *args, **kwargs):
|
|
||||||
return ConstructorSwitch.objects.get(pk=constructor_switch_id)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -297,14 +282,14 @@ class Port(AclMixin, models.Model):
|
||||||
("view_port", "Peut voir un objet port"),
|
("view_port", "Peut voir un objet port"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(port_id, *args, **kwargs):
|
def get_instance(portid, *args, **kwargs):
|
||||||
return Port.objects\
|
return Port.objects\
|
||||||
.select_related('machine_interface__domain__extension')\
|
.select_related('machine_interface__domain__extension')\
|
||||||
.select_related('machine_interface__machine__switch')\
|
.select_related('machine_interface__machine__switch')\
|
||||||
.select_related('room')\
|
.select_related('room')\
|
||||||
.select_related('related')\
|
.select_related('related')\
|
||||||
.prefetch_related('switch__interface_set__domain__extension')\
|
.prefetch_related('switch__interface_set__domain__extension')\
|
||||||
.get(pk=port_id)
|
.get(pk=portid)
|
||||||
|
|
||||||
def make_port_related(self):
|
def make_port_related(self):
|
||||||
""" Synchronise le port distant sur self"""
|
""" Synchronise le port distant sur self"""
|
||||||
|
@ -363,9 +348,6 @@ class Room(AclMixin, models.Model):
|
||||||
("view_room", "Peut voir un objet chambre"),
|
("view_room", "Peut voir un objet chambre"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(room_id, *args, **kwargs):
|
|
||||||
return Room.objects.get(pk=room_id)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<td>{{ap.interface_set.first.details}}</td>
|
<td>{{ap.interface_set.first.details}}</td>
|
||||||
<td>{{ap.location}}</td>
|
<td>{{ap.location}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'ap' ap.pk %}">
|
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'accesspoint' ap.pk %}">
|
||||||
<i class="fa fa-history"></i>
|
<i class="fa fa-history"></i>
|
||||||
</a>
|
</a>
|
||||||
{% can_edit ap %}
|
{% can_edit ap %}
|
||||||
|
|
|
@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{constructor_switch}}</td>
|
<td>{{constructor_switch}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'constructor_switch' constructor_switch.pk %}">
|
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'constructorswitch' constructor_switch.pk %}">
|
||||||
<i class="fa fa-history"></i>
|
<i class="fa fa-history"></i>
|
||||||
</a>
|
</a>
|
||||||
{% can_edit constructor_switch %}
|
{% can_edit constructor_switch %}
|
||||||
|
|
|
@ -41,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<td>{{model_switch.reference}}</td>
|
<td>{{model_switch.reference}}</td>
|
||||||
<td>{{model_switch.constructor}}</td>
|
<td>{{model_switch.constructor}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'model_switch' model_switch.pk %}">
|
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'modelswitch' model_switch.pk %}">
|
||||||
<i class="fa fa-history"></i>
|
<i class="fa fa-history"></i>
|
||||||
</a>
|
</a>
|
||||||
{% can_edit model_switch %}
|
{% can_edit model_switch %}
|
||||||
|
|
|
@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if port.related %}
|
{% if port.related %}
|
||||||
<a href="{% url 'topologie:index-port' switch_id=port.related.switch.id %}">{{ port.related }}</a>
|
<a href="{% url 'topologie:index-port' switchid=port.related.switch.id %}">{{ port.related }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ port.radius }}</td>
|
<td>{{ port.radius }}</td>
|
||||||
|
|
|
@ -33,9 +33,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-switch' id_switch %}"><i class="fa fa-edit"></i> Editer</a>
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-switch' id_switch %}"><i class="fa fa-edit"></i> Editer</a>
|
||||||
{% can_create Port %}
|
{% can_create Port %}
|
||||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-port' id_switch %}"><i class="fa fa-plus"></i> Ajouter un port</a>
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-port' id_switch %}"><i class="fa fa-plus"></i> Ajouter un port</a>
|
||||||
{% acl_end %}
|
|
||||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:create-ports' id_switch %}"><i class="fa fa-plus"></i> Ajouter des ports</a>
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:create-ports' id_switch %}"><i class="fa fa-plus"></i> Ajouter des ports</a>
|
||||||
{% include "topologie/aff_port.html" with port_list=port_list %}
|
{% acl_end %}
|
||||||
|
{% include "topologie/aff_port.html" with port_list=port_list %}
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -37,18 +37,18 @@ urlpatterns = [
|
||||||
url(r'^$', views.index, name='index'),
|
url(r'^$', views.index, name='index'),
|
||||||
url(r'^index_ap/$', views.index_ap, name='index-ap'),
|
url(r'^index_ap/$', views.index_ap, name='index-ap'),
|
||||||
url(r'^new_ap/$', views.new_ap, name='new-ap'),
|
url(r'^new_ap/$', views.new_ap, name='new-ap'),
|
||||||
url(r'^edit_ap/(?P<ap_id>[0-9]+)$',
|
url(r'^edit_ap/(?P<accesspointid>[0-9]+)$',
|
||||||
views.edit_ap,
|
views.edit_ap,
|
||||||
name='edit-ap'),
|
name='edit-ap'),
|
||||||
url(r'^create_ports/(?P<switch_id>[0-9]+)$',
|
url(r'^create_ports/(?P<switchid>[0-9]+)$',
|
||||||
views.create_ports,
|
views.create_ports,
|
||||||
name='create-ports'),
|
name='create-ports'),
|
||||||
url(r'^index_room/$', views.index_room, name='index-room'),
|
url(r'^index_room/$', views.index_room, name='index-room'),
|
||||||
url(r'^new_room/$', views.new_room, name='new-room'),
|
url(r'^new_room/$', views.new_room, name='new-room'),
|
||||||
url(r'^edit_room/(?P<room_id>[0-9]+)$', views.edit_room, name='edit-room'),
|
url(r'^edit_room/(?P<roomid>[0-9]+)$', views.edit_room, name='edit-room'),
|
||||||
url(r'^del_room/(?P<room_id>[0-9]+)$', views.del_room, name='del-room'),
|
url(r'^del_room/(?P<roomid>[0-9]+)$', views.del_room, name='del-room'),
|
||||||
url(r'^new_switch/$', views.new_switch, name='new-switch'),
|
url(r'^new_switch/$', views.new_switch, name='new-switch'),
|
||||||
url(r'^switch/(?P<switch_id>[0-9]+)$',
|
url(r'^switch/(?P<switchid>[0-9]+)$',
|
||||||
views.index_port,
|
views.index_port,
|
||||||
name='index-port'),
|
name='index-port'),
|
||||||
url(
|
url(
|
||||||
|
@ -57,18 +57,18 @@ urlpatterns = [
|
||||||
name='history',
|
name='history',
|
||||||
kwargs={'application':'topologie'},
|
kwargs={'application':'topologie'},
|
||||||
),
|
),
|
||||||
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),
|
url(r'^edit_port/(?P<portid>[0-9]+)$', views.edit_port, name='edit-port'),
|
||||||
url(r'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'),
|
url(r'^new_port/(?P<switchid>[0-9]+)$', views.new_port, name='new-port'),
|
||||||
url(r'^del_port/(?P<port_id>[0-9]+)$', views.del_port, name='del-port'),
|
url(r'^del_port/(?P<portid>[0-9]+)$', views.del_port, name='del-port'),
|
||||||
url(r'^edit_switch/(?P<switch_id>[0-9]+)$',
|
url(r'^edit_switch/(?P<switchid>[0-9]+)$',
|
||||||
views.edit_switch,
|
views.edit_switch,
|
||||||
name='edit-switch'),
|
name='edit-switch'),
|
||||||
url(r'^new_stack/$', views.new_stack, name='new-stack'),
|
url(r'^new_stack/$', views.new_stack, name='new-stack'),
|
||||||
url(r'^index_stack/$', views.index_stack, name='index-stack'),
|
url(r'^index_stack/$', views.index_stack, name='index-stack'),
|
||||||
url(r'^edit_stack/(?P<stack_id>[0-9]+)$',
|
url(r'^edit_stack/(?P<stackid>[0-9]+)$',
|
||||||
views.edit_stack,
|
views.edit_stack,
|
||||||
name='edit-stack'),
|
name='edit-stack'),
|
||||||
url(r'^del_stack/(?P<stack_id>[0-9]+)$',
|
url(r'^del_stack/(?P<stackid>[0-9]+)$',
|
||||||
views.del_stack,
|
views.del_stack,
|
||||||
name='del-stack'),
|
name='del-stack'),
|
||||||
url(r'^index_model_switch/$',
|
url(r'^index_model_switch/$',
|
||||||
|
@ -83,20 +83,20 @@ urlpatterns = [
|
||||||
views.new_model_switch,
|
views.new_model_switch,
|
||||||
name='new-model-switch'
|
name='new-model-switch'
|
||||||
),
|
),
|
||||||
url(r'^edit_model_switch/(?P<model_switch_id>[0-9]+)$',
|
url(r'^edit_model_switch/(?P<modelswitchid>[0-9]+)$',
|
||||||
views.edit_model_switch,
|
views.edit_model_switch,
|
||||||
name='edit-model-switch'),
|
name='edit-model-switch'),
|
||||||
url(r'^del_model_switch/(?P<model_switch_id>[0-9]+)$',
|
url(r'^del_model_switch/(?P<modelswitchid>[0-9]+)$',
|
||||||
views.del_model_switch,
|
views.del_model_switch,
|
||||||
name='del-model-switch'),
|
name='del-model-switch'),
|
||||||
url(r'^new_constructor_switch/$',
|
url(r'^new_constructor_switch/$',
|
||||||
views.new_constructor_switch,
|
views.new_constructor_switch,
|
||||||
name='new-constructor-switch'
|
name='new-constructor-switch'
|
||||||
),
|
),
|
||||||
url(r'^edit_constructor_switch/(?P<constructor_switch_id>[0-9]+)$',
|
url(r'^edit_constructor_switch/(?P<constructorswitchid>[0-9]+)$',
|
||||||
views.edit_constructor_switch,
|
views.edit_constructor_switch,
|
||||||
name='edit-constructor-switch'),
|
name='edit-constructor-switch'),
|
||||||
url(r'^del_constructor_switch/(?P<constructor_switch_id>[0-9]+)$',
|
url(r'^del_constructor_switch/(?P<constructorswitchid>[0-9]+)$',
|
||||||
views.del_constructor_switch,
|
views.del_constructor_switch,
|
||||||
name='del-constructor-switch'),
|
name='del-constructor-switch'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -123,7 +123,7 @@ def index(request):
|
||||||
@login_required
|
@login_required
|
||||||
@can_view_all(Port)
|
@can_view_all(Port)
|
||||||
@can_view(Switch)
|
@can_view(Switch)
|
||||||
def index_port(request, switch, switch_id):
|
def index_port(request, switch, switchid):
|
||||||
""" Affichage de l'ensemble des ports reliés à un switch particulier"""
|
""" Affichage de l'ensemble des ports reliés à un switch particulier"""
|
||||||
port_list = Port.objects.filter(switch=switch)\
|
port_list = Port.objects.filter(switch=switch)\
|
||||||
.select_related('room')\
|
.select_related('room')\
|
||||||
|
@ -143,7 +143,7 @@ def index_port(request, switch, switch_id):
|
||||||
)
|
)
|
||||||
return render(request, 'topologie/index_p.html', {
|
return render(request, 'topologie/index_p.html', {
|
||||||
'port_list': port_list,
|
'port_list': port_list,
|
||||||
'id_switch': switch_id,
|
'id_switch': switchid,
|
||||||
'nom_switch': switch
|
'nom_switch': switch
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -250,10 +250,10 @@ def index_model_switch(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Port)
|
@can_create(Port)
|
||||||
def new_port(request, switch_id):
|
def new_port(request, switchid):
|
||||||
""" Nouveau port"""
|
""" Nouveau port"""
|
||||||
try:
|
try:
|
||||||
switch = Switch.objects.get(pk=switch_id)
|
switch = Switch.objects.get(pk=switchid)
|
||||||
except Switch.DoesNotExist:
|
except Switch.DoesNotExist:
|
||||||
messages.error(request, u"Switch inexistant")
|
messages.error(request, u"Switch inexistant")
|
||||||
return redirect(reverse('topologie:index'))
|
return redirect(reverse('topologie:index'))
|
||||||
|
@ -271,14 +271,14 @@ def new_port(request, switch_id):
|
||||||
messages.error(request, "Ce port existe déjà")
|
messages.error(request, "Ce port existe déjà")
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'topologie:index-port',
|
'topologie:index-port',
|
||||||
kwargs={'switch_id':switch_id}
|
kwargs={'switchid':switchid}
|
||||||
))
|
))
|
||||||
return form({'id_switch': switch_id,'topoform': port, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request)
|
return form({'id_switch': switchid,'topoform': port, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(Port)
|
@can_edit(Port)
|
||||||
def edit_port(request, port_object, port_id):
|
def edit_port(request, port_object, portid):
|
||||||
""" Edition d'un port. Permet de changer le switch parent et
|
""" Edition d'un port. Permet de changer le switch parent et
|
||||||
l'affectation du port"""
|
l'affectation du port"""
|
||||||
|
|
||||||
|
@ -293,14 +293,14 @@ def edit_port(request, port_object, port_id):
|
||||||
messages.success(request, "Le port a bien été modifié")
|
messages.success(request, "Le port a bien été modifié")
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'topologie:index-port',
|
'topologie:index-port',
|
||||||
kwargs={'switch_id': str(port_object.switch.id)}
|
kwargs={'switchid': str(port_object.switch.id)}
|
||||||
))
|
))
|
||||||
return form({'id_switch': str(port_object.switch.id), 'topoform': port, 'action_name' : 'Editer'}, 'topologie/topo.html', request)
|
return form({'id_switch': str(port_object.switch.id), 'topoform': port, 'action_name' : 'Editer'}, 'topologie/topo.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete(Port)
|
@can_delete(Port)
|
||||||
def del_port(request, port, port_id):
|
def del_port(request, port, portid):
|
||||||
""" Supprime le port"""
|
""" Supprime le port"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
|
@ -314,7 +314,7 @@ def del_port(request, port, port_id):
|
||||||
impossible de le supprimer" % port)
|
impossible de le supprimer" % port)
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'topologie:index-port',
|
'topologie:index-port',
|
||||||
kwargs={'switch_id':str(port.switch.id)}
|
kwargs={'switchid':str(port.switch.id)}
|
||||||
))
|
))
|
||||||
return form({'objet': port}, 'topologie/delete.html', request)
|
return form({'objet': port}, 'topologie/delete.html', request)
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ def del_port(request, port, port_id):
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Stack)
|
@can_create(Stack)
|
||||||
def new_stack(request):
|
def new_stack(request):
|
||||||
"""Ajoute un nouveau stack : stack_id_min, max, et nombre de switches"""
|
"""Ajoute un nouveau stack : stackid_min, max, et nombre de switches"""
|
||||||
stack = StackForm(request.POST or None)
|
stack = StackForm(request.POST or None)
|
||||||
if stack.is_valid():
|
if stack.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -335,7 +335,7 @@ def new_stack(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(Stack)
|
@can_edit(Stack)
|
||||||
def edit_stack(request, stack, stack_id):
|
def edit_stack(request, stack, stackid):
|
||||||
"""Edition d'un stack (nombre de switches, nom...)"""
|
"""Edition d'un stack (nombre de switches, nom...)"""
|
||||||
|
|
||||||
stack = StackForm(request.POST or None, instance=stack)
|
stack = StackForm(request.POST or None, instance=stack)
|
||||||
|
@ -354,7 +354,7 @@ def edit_stack(request, stack, stack_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete(Stack)
|
@can_delete(Stack)
|
||||||
def del_stack(request, stack, stack_id):
|
def del_stack(request, stack, stackid):
|
||||||
"""Supprime un stack"""
|
"""Supprime un stack"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
|
@ -372,7 +372,7 @@ def del_stack(request, stack, stack_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(Stack)
|
@can_edit(Stack)
|
||||||
def edit_switchs_stack(request, stack, stack_id):
|
def edit_switchs_stack(request, stack, stackid):
|
||||||
"""Permet d'éditer la liste des switches dans une stack et l'ajouter"""
|
"""Permet d'éditer la liste des switches dans une stack et l'ajouter"""
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
@ -440,10 +440,10 @@ def new_switch(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Port)
|
@can_create(Port)
|
||||||
def create_ports(request, switch_id):
|
def create_ports(request, switchid):
|
||||||
""" Création d'une liste de ports pour un switch."""
|
""" Création d'une liste de ports pour un switch."""
|
||||||
try:
|
try:
|
||||||
switch = Switch.objects.get(pk=switch_id)
|
switch = Switch.objects.get(pk=switchid)
|
||||||
except Switch.DoesNotExist:
|
except Switch.DoesNotExist:
|
||||||
messages.error(request, u"Switch inexistant")
|
messages.error(request, u"Switch inexistant")
|
||||||
return redirect(reverse('topologie:index'))
|
return redirect(reverse('topologie:index'))
|
||||||
|
@ -471,14 +471,14 @@ def create_ports(request, switch_id):
|
||||||
|
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'topologie:index-port',
|
'topologie:index-port',
|
||||||
kwargs={'switch_id':switch_id}
|
kwargs={'switchid':switchid}
|
||||||
))
|
))
|
||||||
return form({'id_switch': switch_id, 'topoform': port_form}, 'topologie/switch.html', request)
|
return form({'id_switch': switchid, 'topoform': port_form}, 'topologie/switch.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(Switch)
|
@can_edit(Switch)
|
||||||
def edit_switch(request, switch, switch_id):
|
def edit_switch(request, switch, switchid):
|
||||||
""" Edition d'un switch. Permet de chambre nombre de ports,
|
""" Edition d'un switch. Permet de chambre nombre de ports,
|
||||||
place dans le stack, interface et machine associée"""
|
place dans le stack, interface et machine associée"""
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ def edit_switch(request, switch, switch_id):
|
||||||
return redirect(reverse('topologie:index'))
|
return redirect(reverse('topologie:index'))
|
||||||
i_mbf_param = generate_ipv4_mbf_param(interface_form, False )
|
i_mbf_param = generate_ipv4_mbf_param(interface_form, False )
|
||||||
return form({
|
return form({
|
||||||
'id_switch': switch_id,
|
'id_switch': switchid,
|
||||||
'topoform': interface_form,
|
'topoform': interface_form,
|
||||||
'machineform': switch_form,
|
'machineform': switch_form,
|
||||||
'domainform': domain_form,
|
'domainform': domain_form,
|
||||||
|
@ -590,7 +590,7 @@ def new_ap(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(AccessPoint)
|
@can_edit(AccessPoint)
|
||||||
def edit_ap(request, ap, ap_id):
|
def edit_ap(request, ap, accesspointid):
|
||||||
""" Edition d'un switch. Permet de chambre nombre de ports,
|
""" Edition d'un switch. Permet de chambre nombre de ports,
|
||||||
place dans le stack, interface et machine associée"""
|
place dans le stack, interface et machine associée"""
|
||||||
interface_form = EditInterfaceForm(
|
interface_form = EditInterfaceForm(
|
||||||
|
@ -665,7 +665,7 @@ def new_room(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(Room)
|
@can_edit(Room)
|
||||||
def edit_room(request, room, room_id):
|
def edit_room(request, room, roomid):
|
||||||
""" Edition numero et details de la chambre"""
|
""" Edition numero et details de la chambre"""
|
||||||
|
|
||||||
room = EditRoomForm(request.POST or None, instance=room)
|
room = EditRoomForm(request.POST or None, instance=room)
|
||||||
|
@ -683,7 +683,7 @@ def edit_room(request, room, room_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete(Room)
|
@can_delete(Room)
|
||||||
def del_room(request, room, room_id):
|
def del_room(request, room, roomid):
|
||||||
""" Suppression d'un chambre"""
|
""" Suppression d'un chambre"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
|
@ -719,7 +719,7 @@ def new_model_switch(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(ModelSwitch)
|
@can_edit(ModelSwitch)
|
||||||
def edit_model_switch(request, model_switch, model_switch_id):
|
def edit_model_switch(request, model_switch, modelswitchid):
|
||||||
""" Edition d'un modèle de switch"""
|
""" Edition d'un modèle de switch"""
|
||||||
|
|
||||||
model_switch = EditModelSwitchForm(request.POST or None, instance=model_switch)
|
model_switch = EditModelSwitchForm(request.POST or None, instance=model_switch)
|
||||||
|
@ -737,7 +737,7 @@ def edit_model_switch(request, model_switch, model_switch_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete(ModelSwitch)
|
@can_delete(ModelSwitch)
|
||||||
def del_model_switch(request, model_switch_id):
|
def del_model_switch(request, model_switch, modelswitchid):
|
||||||
""" Suppression d'un modèle de switch"""
|
""" Suppression d'un modèle de switch"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
|
@ -773,7 +773,7 @@ def new_constructor_switch(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(ConstructorSwitch)
|
@can_edit(ConstructorSwitch)
|
||||||
def edit_constructor_switch(request, constructor_switch, constructor_switch_id):
|
def edit_constructor_switch(request, constructor_switch, constructorswitchid):
|
||||||
""" Edition d'un constructeur de switch"""
|
""" Edition d'un constructeur de switch"""
|
||||||
|
|
||||||
constructor_switch = EditConstructorSwitchForm(request.POST or None, instance=constructor_switch)
|
constructor_switch = EditConstructorSwitchForm(request.POST or None, instance=constructor_switch)
|
||||||
|
@ -791,7 +791,7 @@ def edit_constructor_switch(request, constructor_switch, constructor_switch_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete(ConstructorSwitch)
|
@can_delete(ConstructorSwitch)
|
||||||
def del_constructor_switch(request, constructor_switch_id):
|
def del_constructor_switch(request, constructor_switch, constructorswitchid):
|
||||||
""" Suppression d'un constructeur de switch"""
|
""" Suppression d'un constructeur de switch"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -171,7 +171,7 @@ class UserManager(BaseUserManager):
|
||||||
"""
|
"""
|
||||||
return self._create_user(pseudo, surname, email, password, True)
|
return self._create_user(pseudo, surname, email, password, True)
|
||||||
|
|
||||||
class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin, AclMixin):
|
||||||
""" Definition de l'utilisateur de base.
|
""" Definition de l'utilisateur de base.
|
||||||
Champs principaux : name, surnname, pseudo, email, room, password
|
Champs principaux : name, surnname, pseudo, email, room, password
|
||||||
Herite du django BaseUser et du système d'auth django"""
|
Herite du django BaseUser et du système d'auth django"""
|
||||||
|
@ -668,14 +668,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
num += 1
|
num += 1
|
||||||
return composed_pseudo(num)
|
return composed_pseudo(num)
|
||||||
|
|
||||||
def get_instance(userid, *args, **kwargs):
|
|
||||||
"""Get the User instance with userid.
|
|
||||||
|
|
||||||
:param userid: The id
|
|
||||||
:return: The user
|
|
||||||
"""
|
|
||||||
return User.objects.get(pk=userid)
|
|
||||||
|
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
"""Check if an user can edit an user object.
|
"""Check if an user can edit an user object.
|
||||||
|
|
||||||
|
@ -746,29 +738,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
def can_change_groups(user_request, *args, **kwargs):
|
def can_change_groups(user_request, *args, **kwargs):
|
||||||
return user_request.has_perm('users.change_user_groups'), "Droit requis pour éditer les groupes de l'user"
|
return user_request.has_perm('users.change_user_groups'), "Droit requis pour éditer les groupes de l'user"
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can delete an user object.
|
|
||||||
|
|
||||||
:param self: The user who is to be deleted.
|
|
||||||
:param user_request: The user who requests deletion.
|
|
||||||
:return: True if user_request has the right 'bureau', and a message.
|
|
||||||
"""
|
|
||||||
if user_request.has_perm('users.delete_user'):
|
|
||||||
return True, None
|
|
||||||
else:
|
|
||||||
return False, u"Vous ne pouvez pas supprimer cet utilisateur."
|
|
||||||
|
|
||||||
def can_view_all(user_request, *args, **kwargs):
|
|
||||||
"""Check if an user can access to the list of every user objects
|
|
||||||
|
|
||||||
:param user_request: The user who wants to view the list.
|
|
||||||
:return: True if the user can view the list and an explanation message.
|
|
||||||
"""
|
|
||||||
if user_request.has_perm('users.view_user'):
|
|
||||||
return True, None
|
|
||||||
else:
|
|
||||||
return False, u"Vous n'avez pas accès à la liste des utilisateurs."
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
"""Check if an user can view an user object.
|
"""Check if an user can view an user object.
|
||||||
|
|
||||||
|
@ -791,6 +760,23 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
else:
|
else:
|
||||||
return False, u"Vous ne pouvez voir un autre utilisateur que vous même"
|
return False, u"Vous ne pouvez voir un autre utilisateur que vous même"
|
||||||
|
|
||||||
|
def can_view_all(user_request, *args, **kwargs):
|
||||||
|
"""Check if an user can access to the list of every user objects
|
||||||
|
|
||||||
|
:param user_request: The user who wants to view the list.
|
||||||
|
:return: True if the user can view the list and an explanation message.
|
||||||
|
"""
|
||||||
|
return user_request.has_perm('users.view_user'), u"Vous n'avez pas accès à la liste des utilisateurs."
|
||||||
|
|
||||||
|
def can_delete(self, user_request, *args, **kwargs):
|
||||||
|
"""Check if an user can delete an user object.
|
||||||
|
|
||||||
|
:param self: The user who is to be deleted.
|
||||||
|
:param user_request: The user who requests deletion.
|
||||||
|
:return: True if user_request has the right 'bureau', and a message.
|
||||||
|
"""
|
||||||
|
return user_request.has_perm('users.delete_user'), u"Vous ne pouvez pas supprimer cet utilisateur."
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(User, self).__init__(*args, **kwargs)
|
super(User, self).__init__(*args, **kwargs)
|
||||||
self.field_permissions = {
|
self.field_permissions = {
|
||||||
|
@ -813,8 +799,6 @@ class Adherent(User):
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_instance(adherentid, *args, **kwargs):
|
def get_instance(adherentid, *args, **kwargs):
|
||||||
"""Try to find an instance of `Adherent` with the given id.
|
"""Try to find an instance of `Adherent` with the given id.
|
||||||
|
|
||||||
|
@ -990,9 +974,6 @@ class ServiceUser(AclMixin, AbstractBaseUser):
|
||||||
)]).values_list('dn', flat=True))
|
)]).values_list('dn', flat=True))
|
||||||
group.save()
|
group.save()
|
||||||
|
|
||||||
def get_instance(userid, *args, **kwargs):
|
|
||||||
return ServiceUser.objects.get(pk=userid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.pseudo
|
return self.pseudo
|
||||||
|
|
||||||
|
@ -1021,9 +1002,6 @@ class School(AclMixin, models.Model):
|
||||||
("view_school", "Peut voir un objet school"),
|
("view_school", "Peut voir un objet school"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(schoolid, *args, **kwargs):
|
|
||||||
return School.objects.get(pk=schoolid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -1058,9 +1036,6 @@ class ListRight(AclMixin, Group):
|
||||||
("view_listright", "Peut voir un objet Group/ListRight"),
|
("view_listright", "Peut voir un objet Group/ListRight"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(listrightid, *args, **kwargs):
|
|
||||||
return ListRight.objects.get(pk=listrightid)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -1110,9 +1085,6 @@ class ListShell(AclMixin, models.Model):
|
||||||
("view_listshell", "Peut voir un objet shell quelqu'il soit"),
|
("view_listshell", "Peut voir un objet shell quelqu'il soit"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_instance(shellid, *args, **kwargs):
|
|
||||||
return ListShell.objects.get(pk=shellid)
|
|
||||||
|
|
||||||
def get_pretty_name(self):
|
def get_pretty_name(self):
|
||||||
"""Return the canonical name of the shell"""
|
"""Return the canonical name of the shell"""
|
||||||
return self.shell.split("/")[-1]
|
return self.shell.split("/")[-1]
|
||||||
|
@ -1236,9 +1208,6 @@ class Whitelist(AclMixin, models.Model):
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return self.date_end > timezone.now()
|
return self.date_end > timezone.now()
|
||||||
|
|
||||||
def get_instance(whitelistid, *args, **kwargs):
|
|
||||||
return Whitelist.objects.get(pk=whitelistid)
|
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
"""Check if an user can view a Whitelist object.
|
"""Check if an user can view a Whitelist object.
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,12 @@ urlpatterns = [
|
||||||
url(r'^del_listright/$', views.del_listright, name='del-listright'),
|
url(r'^del_listright/$', views.del_listright, name='del-listright'),
|
||||||
url(r'^add_shell/$', views.add_shell, name='add-shell'),
|
url(r'^add_shell/$', views.add_shell, name='add-shell'),
|
||||||
url(
|
url(
|
||||||
r'^edit_shell/(?P<shellid>[0-9]+)$',
|
r'^edit_shell/(?P<listshellid>[0-9]+)$',
|
||||||
views.edit_shell,
|
views.edit_shell,
|
||||||
name='edit-shell'
|
name='edit-shell'
|
||||||
),
|
),
|
||||||
url(
|
url(
|
||||||
r'^del_shell/(?P<shellid>[0-9]+)$',
|
r'^del_shell/(?P<listshellid>[0-9]+)$',
|
||||||
views.del_shell,
|
views.del_shell,
|
||||||
name='del-shell'
|
name='del-shell'
|
||||||
),
|
),
|
||||||
|
|
|
@ -515,8 +515,8 @@ def add_shell(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(ListShell)
|
@can_edit(ListShell)
|
||||||
def edit_shell(request, shell_instance, shellid):
|
def edit_shell(request, shell_instance, listshellid):
|
||||||
""" Editer un shell à partir du shellid"""
|
""" Editer un shell à partir du listshellid"""
|
||||||
shell = ShellForm(request.POST or None, instance=shell_instance)
|
shell = ShellForm(request.POST or None, instance=shell_instance)
|
||||||
if shell.is_valid():
|
if shell.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -532,7 +532,7 @@ def edit_shell(request, shell_instance, shellid):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_delete(ListShell)
|
@can_delete(ListShell)
|
||||||
def del_shell(request, shell, shellid):
|
def del_shell(request, shell, listshellid):
|
||||||
"""Destruction d'un shell"""
|
"""Destruction d'un shell"""
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
|
Loading…
Reference in a new issue