mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Machine inherits AclMixin
This commit is contained in:
parent
68ce40a368
commit
7edef7b722
2 changed files with 38 additions and 32 deletions
|
@ -62,7 +62,7 @@ from re2o.field_permissions import FieldPermissionModelMixin
|
|||
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
|
||||
interfaces"""
|
||||
|
||||
|
@ -80,14 +80,6 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
verbose_name = _("machine")
|
||||
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):
|
||||
"""Return linked objects : machine and domain.
|
||||
Usefull in history display"""
|
||||
|
@ -157,8 +149,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
if user != user_request:
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to add a machine to another"
|
||||
" user."),
|
||||
_("You don't have the right to add a machine to another" " user."),
|
||||
("machines.add_machine",),
|
||||
)
|
||||
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):
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to edit a machine of another"
|
||||
" user."),
|
||||
_("You don't have the right to edit a machine of another" " user."),
|
||||
("machines.change_interface",) + permissions,
|
||||
)
|
||||
return True, None, None
|
||||
|
@ -225,8 +215,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
):
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to view other machines than"
|
||||
" yours."),
|
||||
_("You don't have the right to view other machines than" " yours."),
|
||||
("machines.view_machine",),
|
||||
)
|
||||
return True, None, None
|
||||
|
@ -558,8 +547,7 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
for element in IpType.objects.all().exclude(pk=self.pk):
|
||||
if not self.ip_set.isdisjoint(element.ip_set):
|
||||
raise ValidationError(
|
||||
_("The specified range is not disjoint from existing"
|
||||
" ranges.")
|
||||
_("The specified range is not disjoint from existing" " ranges.")
|
||||
)
|
||||
# On formate le prefix v6
|
||||
if self.prefix_v6:
|
||||
|
@ -1302,7 +1290,11 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
if not (
|
||||
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"
|
||||
)
|
||||
|
@ -1351,8 +1343,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
if not (user_request.has_perm("machines.change_interface") and can_user):
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to edit a machine of another"
|
||||
" user."),
|
||||
_("You don't have the right to edit a machine of another" " user."),
|
||||
("machines.change_interface",) + permissions,
|
||||
)
|
||||
return True, None, None
|
||||
|
@ -1370,8 +1361,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
if not (user_request.has_perm("machines.change_interface") and can_user):
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to edit a machine of another"
|
||||
" user."),
|
||||
_("You don't have the right to edit a machine of another" " user."),
|
||||
("machines.change_interface",) + permissions,
|
||||
)
|
||||
return True, None, None
|
||||
|
@ -1761,8 +1751,7 @@ class Domain(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
):
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to view other machines than"
|
||||
" yours."),
|
||||
_("You don't have the right to view other machines than" " yours."),
|
||||
("machines.view_domain",),
|
||||
)
|
||||
return True, None, None
|
||||
|
@ -1979,8 +1968,7 @@ class OuverturePortList(RevMixin, AclMixin, models.Model):
|
|||
|
||||
class Meta:
|
||||
permissions = (
|
||||
("view_ouvertureportlist", _("Can view a ports opening list"
|
||||
" object")),
|
||||
("view_ouvertureportlist", _("Can view a ports opening list" " object")),
|
||||
)
|
||||
verbose_name = _("ports opening list")
|
||||
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
|
||||
|
||||
Definition pour une borne wifi , hérite de machines.interfaces
|
||||
|
@ -135,6 +135,12 @@ class AccessPoint(AclMixin, Machine):
|
|||
def __str__(self):
|
||||
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):
|
||||
"""
|
||||
|
@ -173,8 +179,14 @@ class Server(Machine):
|
|||
def __str__(self):
|
||||
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),
|
||||
un emplacement (location), un stack parent (optionnel, stack)
|
||||
et un id de membre dans le stack (stack_member_id)
|
||||
|
@ -457,6 +469,12 @@ class Switch(AclMixin, Machine):
|
|||
def __str__(self):
|
||||
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):
|
||||
"""Un modèle (au sens constructeur) de switch"""
|
||||
|
@ -532,7 +550,9 @@ class ModuleOnSwitch(AclMixin, RevMixin, models.Model):
|
|||
unique_together = ["slot", "switch"]
|
||||
|
||||
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):
|
||||
|
@ -842,9 +862,7 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
|||
radius_type = models.CharField(
|
||||
max_length=32,
|
||||
choices=TYPES,
|
||||
help_text=_(
|
||||
"Type of RADIUS authentication: inactive, MAC-address or 802.1X."
|
||||
),
|
||||
help_text=_("Type of RADIUS authentication: inactive, MAC-address or 802.1X."),
|
||||
verbose_name=_("RADIUS type"),
|
||||
)
|
||||
radius_mode = models.CharField(
|
||||
|
|
Loading…
Reference in a new issue