From 7fe83b24baf2f12dad52fde0eaa48fdfd5d4cb24 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sat, 29 Aug 2020 12:38:22 +0200 Subject: [PATCH 1/3] NEW api get member by thirdparty --- htdocs/adherents/class/api_members.class.php | 113 +++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 2128abe73d6..1c57e29375a 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2017 Regis Houssin + * Copyright (C) 2020 Thibault FOUCART * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +19,7 @@ use Luracast\Restler\RestException; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; @@ -75,6 +77,117 @@ class Members extends DolibarrApi return $this->_cleanObjectDatas($member); } + + /** + * Get properties of a member object by linked thirdparty + * + * Return an array with member informations + * + * @param int $thirdparty ID of third party + * + * @return array|mixed Data without useless information + * + * @url GET thirdparty/{thirdparty} + * + * @throws RestException 401 + * @throws RestException 404 + */ + function getByThirdparty($thirdparty) + { + if(! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $member = new Adherent($this->db); + $result = $member->fetch('', '', $thirdparty); + if( ! $result ) { + throw new RestException(404, 'member not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } + + /** + * Get properties of a member object by linked thirdparty email + * + * Return an array with member informations + * + * @param string $email Email of third party + * + * @return array|mixed Data without useless information + * + * @url GET thirdparty/email/{email} + * + * @throws RestException 401 + * @throws RestException 404 + */ + function getByThirdpartyEmail($email) + { + if(! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $thirdparty = new Societe($this->db); + $result = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); + if( ! $result ) { + throw new RestException(404, 'thirdparty not found'); + } + + $member = new Adherent($this->db); + $result = $member->fetch('', '', $thirdparty->id); + if( ! $result ) { + throw new RestException(404, 'member not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } + + /** + * Get properties of a member object by linked thirdparty barcode + * + * Return an array with member informations + * + * @param string $barcode Barcode of third party + * + * @return array|mixed Data without useless information + * + * @url GET thirdparty/barcode/{barcode} + * + * @throws RestException 401 + * @throws RestException 404 + */ + function getByThirdpartyBarcode($barcode) + { + if(! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $thirdparty = new Societe($this->db); + $result = $thirdparty->fetch('', '', '', $barcode); + if( ! $result ) { + throw new RestException(404, 'thirdparty not found'); + } + + $member = new Adherent($this->db); + $result = $member->fetch('', '', $thirdparty->id); + if( ! $result ) { + throw new RestException(404, 'member not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } /** * List members From 96b3474185c48d044112b8360305c4ec24e29f45 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 29 Aug 2020 10:40:30 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/adherents/class/api_members.class.php | 38 ++++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 1c57e29375a..d58a5840ad8 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -77,14 +77,14 @@ class Members extends DolibarrApi return $this->_cleanObjectDatas($member); } - + /** * Get properties of a member object by linked thirdparty * * Return an array with member informations * * @param int $thirdparty ID of third party - * + * * @return array|mixed Data without useless information * * @url GET thirdparty/{thirdparty} @@ -94,30 +94,30 @@ class Members extends DolibarrApi */ function getByThirdparty($thirdparty) { - if(! DolibarrApiAccess::$user->rights->adherent->lire) { + if (! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401); } $member = new Adherent($this->db); $result = $member->fetch('', '', $thirdparty); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'member not found'); } - if( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + if ( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } return $this->_cleanObjectDatas($member); } - + /** * Get properties of a member object by linked thirdparty email * * Return an array with member informations * * @param string $email Email of third party - * + * * @return array|mixed Data without useless information * * @url GET thirdparty/email/{email} @@ -127,36 +127,36 @@ class Members extends DolibarrApi */ function getByThirdpartyEmail($email) { - if(! DolibarrApiAccess::$user->rights->adherent->lire) { + if (! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401); } $thirdparty = new Societe($this->db); $result = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'thirdparty not found'); } - + $member = new Adherent($this->db); $result = $member->fetch('', '', $thirdparty->id); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'member not found'); } - if( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + if ( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } return $this->_cleanObjectDatas($member); } - + /** * Get properties of a member object by linked thirdparty barcode * * Return an array with member informations * * @param string $barcode Barcode of third party - * + * * @return array|mixed Data without useless information * * @url GET thirdparty/barcode/{barcode} @@ -166,23 +166,23 @@ class Members extends DolibarrApi */ function getByThirdpartyBarcode($barcode) { - if(! DolibarrApiAccess::$user->rights->adherent->lire) { + if (! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401); } $thirdparty = new Societe($this->db); $result = $thirdparty->fetch('', '', '', $barcode); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'thirdparty not found'); } - + $member = new Adherent($this->db); $result = $member->fetch('', '', $thirdparty->id); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'member not found'); } - if( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + if ( ! DolibarrApi::_checkAccessToResource('adherent', $member->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } From a64223f73dda36e75cdc431b983b5d521475ce71 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sat, 29 Aug 2020 12:44:17 +0200 Subject: [PATCH 3/3] Update api_members.class.php --- htdocs/adherents/class/api_members.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index d58a5840ad8..990e21dd08b 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -92,7 +92,7 @@ class Members extends DolibarrApi * @throws RestException 401 * @throws RestException 404 */ - function getByThirdparty($thirdparty) + public function getByThirdparty($thirdparty) { if (! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401); @@ -125,7 +125,7 @@ class Members extends DolibarrApi * @throws RestException 401 * @throws RestException 404 */ - function getByThirdpartyEmail($email) + public function getByThirdpartyEmail($email) { if (! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401); @@ -164,7 +164,7 @@ class Members extends DolibarrApi * @throws RestException 401 * @throws RestException 404 */ - function getByThirdpartyBarcode($barcode) + public function getByThirdpartyBarcode($barcode) { if (! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401);