From a2da19b5cc8f7c311656b2f5bbb1d929e299779b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Oliveira=20Juli=C3=A3o?= <2057387+brunojuliao@users.noreply.github.com> Date: Wed, 27 Oct 2021 16:31:57 -0300 Subject: [PATCH] Trying to fix #132 --- networkapi/interface/models.py | 8 ++++++++ networkapi/interface/resource/InterfaceGetResource.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/networkapi/interface/models.py b/networkapi/interface/models.py index 4e5e1d784..943cb011f 100644 --- a/networkapi/interface/models.py +++ b/networkapi/interface/models.py @@ -93,6 +93,14 @@ def __init__(self, cause, message=None): InterfaceError.__init__(self, cause, message) +class InterfaceChannelForEquipmentDuplicatedError(InterfaceError): + + """Retorna exceção quando já existir uma interface do tipo canal com o mesmo nome para o equipamento informado.""" + + def __init__(self, cause, message=None): + InterfaceError.__init__(self, cause, message) + + class InterfaceUsedByOtherInterfaceError(InterfaceError): """Retorna exceção quando a interface a ser removida for utilizada por outra interface.""" diff --git a/networkapi/interface/resource/InterfaceGetResource.py b/networkapi/interface/resource/InterfaceGetResource.py index a0bcedc7e..ef7449be1 100644 --- a/networkapi/interface/resource/InterfaceGetResource.py +++ b/networkapi/interface/resource/InterfaceGetResource.py @@ -29,6 +29,7 @@ from networkapi.interface.models import Interface from networkapi.interface.models import InterfaceError from networkapi.interface.models import InterfaceNotFoundError +from networkapi.interface.models import InterfaceChannelForEquipmentDuplicatedError from networkapi.rest import RestResource from networkapi.rest import UserNotAuthorizedError from networkapi.util import is_valid_int_greater_zero_param @@ -132,6 +133,9 @@ def handle_get(self, request, user, *args, **kwargs): channel_id = get_channel[0].channel.id if get_channel else "" interfaces = Interface.objects.filter(channel__id=channel_id) if channel_id else [] for i in interfaces: + if i.equipamento.nome == equip_name: + raise InterfaceChannelForEquipmentDuplicatedError( + None, u'An interface of type channel with the same name on the same equipment already exists') equipInterface_list.append(get_new_interface_map(i)) return self.response(dumps_networkapi({'interfaces': equipInterface_list})) if equipamento is not None: