From 28e4be3b0ecbe937ac8710bace428c44b4e6bb6a Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 22 Nov 2020 16:25:38 +0100 Subject: [PATCH 1/5] Fix contact API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Get roles by API (without GET this data, we can't add this to POST, so data was deleted 👎 ) --- htdocs/societe/class/api_contacts.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index bc456dd7185..a32619855fd 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -78,6 +78,7 @@ class Contacts extends DolibarrApi $result = $this->contact->initAsSpecimen(); } else { $result = $this->contact->fetch($id); + $this->contact->fetchRoles(); } if (!$result) @@ -120,6 +121,7 @@ class Contacts extends DolibarrApi $result = $this->contact->initAsSpecimen(); } else { $result = $this->contact->fetch('', '', '', $email); + $this->contact->fetchRoles(); } if (!$result) @@ -241,6 +243,7 @@ class Contacts extends DolibarrApi $contact_static = new Contact($this->db); if ($contact_static->fetch($obj->rowid)) { + $contact_static->fetchRoles(); if ($includecount) { $contact_static->load_ref_elements(); From f227d5e72ae654cb2b6b3d7f268662026082456f Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Mon, 23 Nov 2020 22:53:56 +0100 Subject: [PATCH 2/5] Update api_contacts.class.php --- htdocs/societe/class/api_contacts.class.php | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index a32619855fd..9b1f0cc084d 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -63,12 +63,13 @@ class Contacts extends DolibarrApi * Return an array with contact informations * * @param int $id ID of contact + * @param int $includeroles Includes roles of the 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 * * @throws RestException */ - public function get($id, $includecount = 0) + public function get($id, $includeroles = 0, $includecount = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -78,7 +79,6 @@ class Contacts extends DolibarrApi $result = $this->contact->initAsSpecimen(); } else { $result = $this->contact->fetch($id); - $this->contact->fetchRoles(); } if (!$result) @@ -90,6 +90,11 @@ class Contacts extends DolibarrApi { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + + if ($includeroles) + { + $this->contact->fetchRoles(); + } if ($includecount) { @@ -103,6 +108,7 @@ class Contacts extends DolibarrApi * Get properties of a contact object by Email * * @param string $email Email of contact + * @param int $includeroles Includes roles of the 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 * @@ -111,7 +117,7 @@ class Contacts extends DolibarrApi * @throws RestException 401 Insufficient rights * @throws RestException 404 User or group not found */ - public function getByEmail($email, $includecount = 0) + public function getByEmail($email, $includeroles = 0, $includecount = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -133,6 +139,11 @@ class Contacts extends DolibarrApi { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + + if ($includeroles) + { + $this->contact->fetchRoles(); + } if ($includecount) { @@ -152,14 +163,15 @@ class Contacts extends DolibarrApi * @param int $limit Limit for list * @param int $page Page number * @param string $thirdparty_ids Thirdparty ids to filter contacts of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} - * @param int $category Use this param to filter list by category + * @param int $category Use this param to filter list by category * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @param int $includeroles Includes roles of the contact * @param int $includecount Count and return also number of elements the contact is used as a link for * @return array Array of contact objects * * @throws RestException */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $includecount = 0) + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $includeroles = 0, $includecount = 0) { global $db, $conf; @@ -244,6 +256,10 @@ class Contacts extends DolibarrApi if ($contact_static->fetch($obj->rowid)) { $contact_static->fetchRoles(); + if ($includeroles) + { + $contact_static->fetchRoles(); + } if ($includecount) { $contact_static->load_ref_elements(); From c1ba61e54853350df7a7a109b26947284ba9bf02 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 23 Nov 2020 21:55:36 +0000 Subject: [PATCH 3/5] Fixing style errors. --- htdocs/societe/class/api_contacts.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 9b1f0cc084d..1ebcf3fecb8 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -90,7 +90,7 @@ class Contacts extends DolibarrApi { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if ($includeroles) { $this->contact->fetchRoles(); @@ -139,7 +139,7 @@ class Contacts extends DolibarrApi { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if ($includeroles) { $this->contact->fetchRoles(); From 0d50402803850e0f52dee278062efe461694be68 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Mon, 23 Nov 2020 23:31:46 +0100 Subject: [PATCH 4/5] Update api_contacts.class.php --- htdocs/societe/class/api_contacts.class.php | 41 +++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 1ebcf3fecb8..ee131a5c40f 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -63,13 +63,13 @@ class Contacts extends DolibarrApi * Return an array with contact informations * * @param int $id ID of contact - * @param int $includeroles Includes roles of the contact * @param int $includecount Count and return also number of elements the contact is used as a link for + * @param int $includeroles Includes roles of the contact * @return array|mixed data without useless information * * @throws RestException */ - public function get($id, $includeroles = 0, $includecount = 0) + public function get($id, $includecount = 0, $includeroles = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -91,15 +91,15 @@ class Contacts extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if ($includeroles) - { - $this->contact->fetchRoles(); - } - if ($includecount) { $this->contact->load_ref_elements(); } + + if ($includeroles) + { + $this->contact->fetchRoles(); + } return $this->_cleanObjectDatas($this->contact); } @@ -108,8 +108,8 @@ class Contacts extends DolibarrApi * Get properties of a contact object by Email * * @param string $email Email of contact - * @param int $includeroles Includes roles of the contact * @param int $includecount Count and return also number of elements the contact is used as a link for + * @param int $includeroles Includes roles of the contact * @return array|mixed data without useless information * * @url GET email/{email} @@ -117,7 +117,7 @@ class Contacts extends DolibarrApi * @throws RestException 401 Insufficient rights * @throws RestException 404 User or group not found */ - public function getByEmail($email, $includeroles = 0, $includecount = 0) + public function getByEmail($email, $includecount = 0, $includeroles = 0) { if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { @@ -140,16 +140,16 @@ class Contacts extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if ($includeroles) - { - $this->contact->fetchRoles(); - } - if ($includecount) { $this->contact->load_ref_elements(); } + if ($includeroles) + { + $this->contact->fetchRoles(); + } + return $this->_cleanObjectDatas($this->contact); } @@ -165,13 +165,13 @@ class Contacts extends DolibarrApi * @param string $thirdparty_ids Thirdparty ids to filter contacts of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} * @param int $category Use this param to filter list by category * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" - * @param int $includeroles Includes roles of the contact * @param int $includecount Count and return also number of elements the contact is used as a link for + * @param int $includeroles Includes roles of the contact * @return array Array of contact objects * * @throws RestException */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $includeroles = 0, $includecount = 0) + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '', $includecount = 0, $includeroles = 0) { global $db, $conf; @@ -256,14 +256,15 @@ class Contacts extends DolibarrApi if ($contact_static->fetch($obj->rowid)) { $contact_static->fetchRoles(); + if ($includecount) + { + $contact_static->load_ref_elements(); + } if ($includeroles) { $contact_static->fetchRoles(); } - if ($includecount) - { - $contact_static->load_ref_elements(); - } + $obj_ret[] = $this->_cleanObjectDatas($contact_static); } From 11704ea6fb4153724fc9cd94f22f3ef8e4108216 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 23 Nov 2020 22:33:45 +0000 Subject: [PATCH 5/5] Fixing style errors. --- htdocs/societe/class/api_contacts.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index ee131a5c40f..9463aba5277 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -95,7 +95,7 @@ class Contacts extends DolibarrApi { $this->contact->load_ref_elements(); } - + if ($includeroles) { $this->contact->fetchRoles(); @@ -259,7 +259,7 @@ class Contacts extends DolibarrApi if ($includecount) { $contact_static->load_ref_elements(); - } + } if ($includeroles) { $contact_static->fetchRoles();