From 206b1189c90bbd73ef2749d9db11e7338abf29a9 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 18 Sep 2020 17:52:48 +0200 Subject: [PATCH 1/2] NEW fetch contact by email with REST API --- htdocs/societe/class/api_contacts.class.php | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 37d9239265f..027cd124d36 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -97,6 +97,48 @@ class Contacts extends DolibarrApi return $this->_cleanObjectDatas($this->contact); } + + /** + * Get properties of a contact object by Email + * + * @param string $email Email of contact + * @param int $includecount Count and return also number of elements the contact is used as a link for + * @return array|mixed data without useless information + * + * @url GET email/{email} + * + * @throws RestException 401 Insufficient rights + * @throws RestException 404 User or group not found + */ + public function getByEmail($email, $includecount = 0) + { + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) + { + throw new RestException(401, 'No permission to read contacts'); + } + if (empty($email)) { + $result = $this->contact->initAsSpecimen(); + } else { + $result = $this->contact->fetch('', '', '', $email); + } + + if (!$result) + { + throw new RestException(404, 'Contact not found'); + } + + if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) + { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if ($includecount) + { + $this->contact->load_ref_elements(); + } + + return $this->_cleanObjectDatas($this->contact); + } /** * List contacts From f9b4a0f68ba7a03cfc86daacfe7bf0ec3b5ad711 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 18 Sep 2020 15:54:37 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/societe/class/api_contacts.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 027cd124d36..4d9bd4a47f4 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -97,7 +97,7 @@ class Contacts extends DolibarrApi return $this->_cleanObjectDatas($this->contact); } - + /** * Get properties of a contact object by Email *