Merge pull request #14780 from ptibogxiv/patch-363

NEW fetch contact by email with REST API
This commit is contained in:
Laurent Destailleur 2020-09-20 17:17:03 +02:00 committed by GitHub
commit ba69fab76a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,6 +98,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
*