From 1af52162177422fabb3e98358af904b54fcbb992 Mon Sep 17 00:00:00 2001 From: Tetrergeru Date: Fri, 24 May 2024 14:27:01 +0200 Subject: [PATCH] Add support for names in contacts --- moira_client/models/contact.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/moira_client/models/contact.py b/moira_client/models/contact.py index 6f38407..a564bec 100644 --- a/moira_client/models/contact.py +++ b/moira_client/models/contact.py @@ -21,6 +21,7 @@ def __init__(self, value='', type='', **kwargs): self.type = type self.value = value self.user = kwargs.get('user', None) + self.name = kwargs.get('name', None) self._id = kwargs.get('id', None) @@ -28,7 +29,7 @@ class ContactManager: def __init__(self, client): self._client = client - def add(self, value, contact_type): + def add(self, value, contact_type, name=None): """ Add new contact @@ -38,16 +39,23 @@ def add(self, value, contact_type): :raises: ResponseStructureError """ - data = { - 'value': value, - 'type': contact_type - } contacts = self.fetch_by_current_user() for contact in contacts: if contact.value == value and contact.type == contact_type: + if name and contact.name != name: + contact.name = name + self.update(contact) + return contact return contact + data = { + 'value': value, + 'type': contact_type + } + if name: + data['name'] = name + result = self._client.put(self._full_path(), json=data) if 'id' not in result: raise ResponseStructureError('No id in response', result) @@ -135,6 +143,8 @@ def update(self, contact): 'type': contact.type, 'value': contact.value, } + if contact.name: + data['name'] = contact.name try: self._client.put(self._full_path(contact.id), json=data)