8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-03 18:12:24 +00:00

fix acl functions in topologie models inheriting from Machine

This commit is contained in:
Hugo Levy-Falk 2020-05-01 12:23:41 +02:00 committed by Gabriel Detraz
parent ec7d8e8532
commit 0156952c12
3 changed files with 59 additions and 13 deletions

View file

@ -130,6 +130,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, AclMixin, models.Model):
:param user_request: Utilisateur qui fait la requête :param user_request: Utilisateur qui fait la requête
:param userid: id de l'user dont on va créer une machine :param userid: id de l'user dont on va créer une machine
:return: soit True, soit False avec la raison de l'échec""" :return: soit True, soit False avec la raison de l'échec"""
raise ValueError("Now you see me.")
try: try:
user = users.models.User.objects.get(pk=userid) user = users.models.User.objects.get(pk=userid)
except users.models.User.DoesNotExist: except users.models.User.DoesNotExist:

View file

@ -135,11 +135,26 @@ class AccessPoint(Machine):
def __str__(self): def __str__(self):
return str(self.interface_set.first()) return str(self.interface_set.first())
# We want to retrieve the default behaviour given by AclMixin rather
# than the one overwritten by Machine. If you are not familiar with
# the behaviour of `super`, please check https://docs.python.org/3/library/functions.html#super
@classmethod @classmethod
def get_instance(cls, object_id, *_args, **kwargs): def get_instance(cls, *args, **kwargs):
"""Récupère une instance return super(Machine, cls).get_instance(*args, **kwargs)
:return: Une instance de la classe évidemment"""
return cls.objects.get(pk=object_id) @classmethod
def can_create(cls, *args, **kwargs):
return super(Machine, cls).can_create(*args, **kwargs)
def can_edit(self, *args, **kwargs):
return super(Machine, self).can_edit(*args, **kwargs)
def can_delete(self, *args, **kwargs):
return super(Machine, self).can_delete(*args, **kwargs)
def can_view(self, *args, **kwargs):
return super(Machine, self).can_view(*args, **kwargs)
class Server(Machine): class Server(Machine):
@ -179,11 +194,26 @@ class Server(Machine):
def __str__(self): def __str__(self):
return str(self.interface_set.first()) return str(self.interface_set.first())
# We want to retrieve the default behaviour given by AclMixin rather
# than the one overwritten by Machine. If you are not familiar with
# the behaviour of `super`, please check https://docs.python.org/3/library/functions.html#super
@classmethod @classmethod
def get_instance(cls, object_id, *_args, **kwargs): def get_instance(cls, *args, **kwargs):
"""Récupère une instance return super(Machine, cls).get_instance(*args, **kwargs)
:return: Une instance de la classe évidemment"""
return cls.objects.get(pk=object_id) @classmethod
def can_create(cls, *args, **kwargs):
return super(Machine, cls).can_create(*args, **kwargs)
def can_edit(self, *args, **kwargs):
return super(Machine, self).can_edit(*args, **kwargs)
def can_delete(self, *args, **kwargs):
return super(Machine, self).can_delete(*args, **kwargs)
def can_view(self, *args, **kwargs):
return super(Machine, self).can_view(*args, **kwargs)
class Switch(Machine): class Switch(Machine):
@ -469,11 +499,26 @@ class Switch(Machine):
def __str__(self): def __str__(self):
return str(self.get_name) return str(self.get_name)
# We want to retrieve the default behaviour given by AclMixin rather
# than the one overwritten by Machine. If you are not familiar with
# the behaviour of `super`, please check https://docs.python.org/3/library/functions.html#super
@classmethod @classmethod
def get_instance(cls, object_id, *_args, **kwargs): def get_instance(cls, *args, **kwargs):
"""Récupère une instance return super(Machine, cls).get_instance(*args, **kwargs)
:return: Une instance de la classe évidemment"""
return cls.objects.get(pk=object_id) @classmethod
def can_create(cls, *args, **kwargs):
return super(Machine, cls).can_create(*args, **kwargs)
def can_edit(self, *args, **kwargs):
return super(Machine, self).can_edit(*args, **kwargs)
def can_delete(self, *args, **kwargs):
return super(Machine, self).can_delete(*args, **kwargs)
def can_view(self, *args, **kwargs):
return super(Machine, self).can_view(*args, **kwargs)
class ModelSwitch(AclMixin, RevMixin, models.Model): class ModelSwitch(AclMixin, RevMixin, models.Model):