|
|
|
@ -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 interfaces 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,9 +1361,8 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model): |
|
|
|
if not (user_request.has_perm("machines.delete_interface") and can_user): |
|
|
|
return ( |
|
|
|
False, |
|
|
|
_("You don't have the right to delete interfaces of another" |
|
|
|
" user."), |
|
|
|
("machines.delete_interface",) + permissions, |
|
|
|
_("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") |
|
|
|
|