Skip to content

Commit

Permalink
Trying to fix globocom#132
Browse files Browse the repository at this point in the history
  • Loading branch information
brunojuliao committed Oct 27, 2021
1 parent 9ab53f8 commit a2da19b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions networkapi/interface/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions networkapi/interface/resource/InterfaceGetResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a2da19b

Please sign in to comment.