mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 04:43:10 +00:00
Machine inherits AclMixin
This commit is contained in:
parent
d2b3663d89
commit
2d40c3ecaa
2 changed files with 39 additions and 33 deletions
|
@ -62,7 +62,7 @@ from re2o.field_permissions import FieldPermissionModelMixin
|
||||||
from re2o.mixins import AclMixin, RevMixin
|
from re2o.mixins import AclMixin, RevMixin
|
||||||
|
|
||||||
|
|
||||||
class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
class Machine(RevMixin, FieldPermissionModelMixin, AclMixin, models.Model):
|
||||||
""" Class définissant une machine, object parent user, objets fils
|
""" Class définissant une machine, object parent user, objets fils
|
||||||
interfaces"""
|
interfaces"""
|
||||||
|
|
||||||
|
@ -80,14 +80,6 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
verbose_name = _("machine")
|
verbose_name = _("machine")
|
||||||
verbose_name_plural = _("machines")
|
verbose_name_plural = _("machines")
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_instance(cls, machineid, *_args, **_kwargs):
|
|
||||||
"""Get the Machine instance with machineid.
|
|
||||||
:param userid: The id
|
|
||||||
:return: The user
|
|
||||||
"""
|
|
||||||
return cls.objects.get(pk=machineid)
|
|
||||||
|
|
||||||
def linked_objects(self):
|
def linked_objects(self):
|
||||||
"""Return linked objects : machine and domain.
|
"""Return linked objects : machine and domain.
|
||||||
Usefull in history display"""
|
Usefull in history display"""
|
||||||
|
@ -157,8 +149,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
if user != user_request:
|
if user != user_request:
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
_("You don't have the right to add a machine to another"
|
_("You don't have the right to add a machine to another" " user."),
|
||||||
" user."),
|
|
||||||
("machines.add_machine",),
|
("machines.add_machine",),
|
||||||
)
|
)
|
||||||
if user.user_interfaces().count() >= max_lambdauser_interfaces:
|
if user.user_interfaces().count() >= max_lambdauser_interfaces:
|
||||||
|
@ -186,8 +177,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
if not (user_request.has_perm("machines.change_interface") and can_user):
|
if not (user_request.has_perm("machines.change_interface") and can_user):
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
_("You don't have the right to edit a machine of another"
|
_("You don't have the right to edit a machine of another" " user."),
|
||||||
" user."),
|
|
||||||
("machines.change_interface",) + permissions,
|
("machines.change_interface",) + permissions,
|
||||||
)
|
)
|
||||||
return True, None, None
|
return True, None, None
|
||||||
|
@ -225,8 +215,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
||||||
):
|
):
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
_("You don't have the right to view other machines than"
|
_("You don't have the right to view other machines than" " yours."),
|
||||||
" yours."),
|
|
||||||
("machines.view_machine",),
|
("machines.view_machine",),
|
||||||
)
|
)
|
||||||
return True, None, None
|
return True, None, None
|
||||||
|
@ -558,8 +547,7 @@ class IpType(RevMixin, AclMixin, models.Model):
|
||||||
for element in IpType.objects.all().exclude(pk=self.pk):
|
for element in IpType.objects.all().exclude(pk=self.pk):
|
||||||
if not self.ip_set.isdisjoint(element.ip_set):
|
if not self.ip_set.isdisjoint(element.ip_set):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("The specified range is not disjoint from existing"
|
_("The specified range is not disjoint from existing" " ranges.")
|
||||||
" ranges.")
|
|
||||||
)
|
)
|
||||||
# On formate le prefix v6
|
# On formate le prefix v6
|
||||||
if self.prefix_v6:
|
if self.prefix_v6:
|
||||||
|
@ -1302,7 +1290,11 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
if not (
|
if not (
|
||||||
preferences.models.OptionalMachine.get_cached_value("create_machine")
|
preferences.models.OptionalMachine.get_cached_value("create_machine")
|
||||||
):
|
):
|
||||||
return False, _("You don't have the right to add a machine."), ("machines.add_interface",)
|
return (
|
||||||
|
False,
|
||||||
|
_("You don't have the right to add a machine."),
|
||||||
|
("machines.add_interface",),
|
||||||
|
)
|
||||||
max_lambdauser_interfaces = preferences.models.OptionalMachine.get_cached_value(
|
max_lambdauser_interfaces = preferences.models.OptionalMachine.get_cached_value(
|
||||||
"max_lambdauser_interfaces"
|
"max_lambdauser_interfaces"
|
||||||
)
|
)
|
||||||
|
@ -1351,8 +1343,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
if not (user_request.has_perm("machines.change_interface") and can_user):
|
if not (user_request.has_perm("machines.change_interface") and can_user):
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
_("You don't have the right to edit interfaces of another"
|
_("You don't have the right to edit a machine of another" " user."),
|
||||||
" user."),
|
|
||||||
("machines.change_interface",) + permissions,
|
("machines.change_interface",) + permissions,
|
||||||
)
|
)
|
||||||
return True, None, None
|
return True, None, None
|
||||||
|
@ -1370,9 +1361,8 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
if not (user_request.has_perm("machines.delete_interface") and can_user):
|
if not (user_request.has_perm("machines.delete_interface") and can_user):
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
_("You don't have the right to delete interfaces of another"
|
_("You don't have the right to edit a machine of another" " user."),
|
||||||
" user."),
|
("machines.change_interface",) + permissions,
|
||||||
("machines.delete_interface",) + permissions,
|
|
||||||
)
|
)
|
||||||
return True, None, None
|
return True, None, None
|
||||||
|
|
||||||
|
@ -1761,8 +1751,7 @@ class Domain(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
):
|
):
|
||||||
return (
|
return (
|
||||||
False,
|
False,
|
||||||
_("You don't have the right to view other machines than"
|
_("You don't have the right to view other machines than" " yours."),
|
||||||
" yours."),
|
|
||||||
("machines.view_domain",),
|
("machines.view_domain",),
|
||||||
)
|
)
|
||||||
return True, None, None
|
return True, None, None
|
||||||
|
@ -1979,8 +1968,7 @@ class OuverturePortList(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_ouvertureportlist", _("Can view a ports opening list"
|
("view_ouvertureportlist", _("Can view a ports opening list" " object")),
|
||||||
" object")),
|
|
||||||
)
|
)
|
||||||
verbose_name = _("ports opening list")
|
verbose_name = _("ports opening list")
|
||||||
verbose_name_plural = _("ports opening lists")
|
verbose_name_plural = _("ports opening lists")
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Stack(AclMixin, RevMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class AccessPoint(AclMixin, Machine):
|
class AccessPoint(Machine):
|
||||||
"""Define a wireless AP. Inherit from machines.interfaces
|
"""Define a wireless AP. Inherit from machines.interfaces
|
||||||
|
|
||||||
Definition pour une borne wifi , hérite de machines.interfaces
|
Definition pour une borne wifi , hérite de machines.interfaces
|
||||||
|
@ -135,6 +135,12 @@ class AccessPoint(AclMixin, Machine):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.interface_set.first())
|
return str(self.interface_set.first())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_instance(cls, object_id, *_args, **kwargs):
|
||||||
|
"""Récupère une instance
|
||||||
|
:return: Une instance de la classe évidemment"""
|
||||||
|
return cls.objects.get(pk=object_id)
|
||||||
|
|
||||||
|
|
||||||
class Server(Machine):
|
class Server(Machine):
|
||||||
"""
|
"""
|
||||||
|
@ -173,8 +179,14 @@ class Server(Machine):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.interface_set.first())
|
return str(self.interface_set.first())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_instance(cls, object_id, *_args, **kwargs):
|
||||||
|
"""Récupère une instance
|
||||||
|
:return: Une instance de la classe évidemment"""
|
||||||
|
return cls.objects.get(pk=object_id)
|
||||||
|
|
||||||
class Switch(AclMixin, Machine):
|
|
||||||
|
class Switch(Machine):
|
||||||
""" Definition d'un switch. Contient un nombre de ports (number),
|
""" Definition d'un switch. Contient un nombre de ports (number),
|
||||||
un emplacement (location), un stack parent (optionnel, stack)
|
un emplacement (location), un stack parent (optionnel, stack)
|
||||||
et un id de membre dans le stack (stack_member_id)
|
et un id de membre dans le stack (stack_member_id)
|
||||||
|
@ -457,6 +469,12 @@ class Switch(AclMixin, Machine):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.get_name)
|
return str(self.get_name)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_instance(cls, object_id, *_args, **kwargs):
|
||||||
|
"""Récupère une instance
|
||||||
|
:return: Une instance de la classe évidemment"""
|
||||||
|
return cls.objects.get(pk=object_id)
|
||||||
|
|
||||||
|
|
||||||
class ModelSwitch(AclMixin, RevMixin, models.Model):
|
class ModelSwitch(AclMixin, RevMixin, models.Model):
|
||||||
"""Un modèle (au sens constructeur) de switch"""
|
"""Un modèle (au sens constructeur) de switch"""
|
||||||
|
@ -532,7 +550,9 @@ class ModuleOnSwitch(AclMixin, RevMixin, models.Model):
|
||||||
unique_together = ["slot", "switch"]
|
unique_together = ["slot", "switch"]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return _("On slot %(slot)s of %(switch)s").format(slot=str(self.slot), switch=str(self.switch))
|
return _("On slot %(slot)s of %(switch)s").format(
|
||||||
|
slot=str(self.slot), switch=str(self.switch)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ConstructorSwitch(AclMixin, RevMixin, models.Model):
|
class ConstructorSwitch(AclMixin, RevMixin, models.Model):
|
||||||
|
@ -842,9 +862,7 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
||||||
radius_type = models.CharField(
|
radius_type = models.CharField(
|
||||||
max_length=32,
|
max_length=32,
|
||||||
choices=TYPES,
|
choices=TYPES,
|
||||||
help_text=_(
|
help_text=_("Type of RADIUS authentication: inactive, MAC-address or 802.1X."),
|
||||||
"Type of RADIUS authentication: inactive, MAC-address or 802.1X."
|
|
||||||
),
|
|
||||||
verbose_name=_("RADIUS type"),
|
verbose_name=_("RADIUS type"),
|
||||||
)
|
)
|
||||||
radius_mode = models.CharField(
|
radius_mode = models.CharField(
|
||||||
|
|
Loading…
Reference in a new issue