From 38c770ffb3eb90c7ecc49d916e2665b34632972b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Nov 2017 01:16:12 +0100 Subject: [PATCH 1/3] FIX #7806 --- htdocs/user/class/api_users.class.php | 74 ++++++++++++++++----------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index f119fa36ffa..6c06a1e2fea 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -22,14 +22,14 @@ use Luracast\Restler\RestException; /** * API class for users * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ class Users extends DolibarrApi { /** * - * @var array $FIELDS Mandatory fields, checked when create and update object + * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDS = array( 'login' @@ -49,7 +49,7 @@ class Users extends DolibarrApi $this->useraccount = new User($this->db); } - + /** * List Users * @@ -65,22 +65,22 @@ class Users extends DolibarrApi */ function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') { global $db, $conf; - + $obj_ret = array(); - + if(! DolibarrApiAccess::$user->rights->user->user->lire) { throw new RestException(401, "You are not allowed to read list of users"); } - + // case of external user, $societe param is ignored and replaced by user's socid //$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe; - + $sql = "SELECT t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."user as t"; $sql.= ' WHERE t.entity IN ('.getEntity('user').')'; if ($user_ids) $sql.=" AND t.rowid IN (".$user_ids.")"; // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -89,7 +89,7 @@ class Users extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -97,12 +97,12 @@ class Users extends DolibarrApi $page = 0; } $offset = $limit * $page; - + $sql.= $db->plimit($limit + 1, $offset); } - + $result = $db->query($sql); - + if ($result) { $num = $db->num_rows($result); @@ -125,7 +125,7 @@ class Users extends DolibarrApi } return $obj_ret; } - + /** * Get properties of an user object * @@ -133,7 +133,7 @@ class Users extends DolibarrApi * * @param int $id ID of user * @return array|mixed data without useless information - * + * * @throws RestException */ function get($id) { @@ -154,8 +154,8 @@ class Users extends DolibarrApi return $this->_cleanObjectDatas($this->useraccount); } - - + + /** * Create user account * @@ -185,14 +185,14 @@ class Users extends DolibarrApi } return $this->useraccount->id; } - - + + /** * Update account * * @param int $id Id of account to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ function put($id, $request_data = NULL) { //if (!DolibarrApiAccess::$user->rights->user->user->creer) { @@ -228,7 +228,7 @@ class Users extends DolibarrApi * @param int $id User ID * @param int $group Group ID * @return int 1 if success - * + * * @url GET {id}/setGroup/{group} */ function setGroup($id, $group) { @@ -240,18 +240,18 @@ class Users extends DolibarrApi { throw new RestException(404, 'User not found'); } - + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } - + $result = $this->useraccount->SetInGroup($group,1); if (! ($result > 0)) { throw new RestException(500, $this->useraccount->error); } - + return 1; } @@ -286,25 +286,37 @@ class Users extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + unset($object->default_values); unset($object->lastsearch_values); unset($object->lastsearch_values_tmp); - + unset($object->total_ht); unset($object->total_tva); unset($object->total_localtax1); unset($object->total_localtax2); unset($object->total_ttc); - + + unset($object->fk_delivery_address); + unset($object->fk_incoterms); + unset($object->all_permissions_are_loaded); + + // List of properties never returned by API, whatever are permissions + unset($object->pass); + unset($object->pass_indatabase); + unset($object->pass_indatabase_crypted); + unset($object->pass_temp); + unset($object->api_key); + unset($object->clicktodial_password); + return $object; - } - + } + /** * Validate fields before create or update object - * + * * @param array|null $data Data to validate * @return array * @throws RestException From 4cbcf5189afbcfdc52e944f9288c456eee55e2f9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Nov 2017 01:24:24 +0100 Subject: [PATCH 2/3] FIX #7806 --- htdocs/user/class/api_users.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 6c06a1e2fea..841f4d485bf 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -286,6 +286,7 @@ class Users extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { + global $conf; $object = parent::_cleanObjectDatas($object); @@ -298,10 +299,16 @@ class Users extends DolibarrApi unset($object->total_localtax1); unset($object->total_localtax2); unset($object->total_ttc); + unset($object->libelle_incoterms); + unset($object->location_incoterms); unset($object->fk_delivery_address); unset($object->fk_incoterms); unset($object->all_permissions_are_loaded); + unset($object->shipping_method_id); + unset($object->nb_rights); + unset($object->search_sid); + unset($object->ldap_sid); // List of properties never returned by API, whatever are permissions unset($object->pass); @@ -310,6 +317,19 @@ class Users extends DolibarrApi unset($object->pass_temp); unset($object->api_key); unset($object->clicktodial_password); + unset($object->openid); + + + $canreadsalary = ((! empty($conf->salaries->enabled) && ! empty(DolibarrApiAccess::$user->rights->salaries->read)) + || (! empty($conf->hrm->enabled) && ! empty(DolibarrApiAccess::$user->rights->hrm->employee->read))); + + if (! $canreadsalary) + { + unset($object->salary); + unset($object->salaryextra); + unset($object->thm); + unset($object->tjm); + } return $object; } From 61798d1af007dfcdf1ef284d5e8546af479e3096 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Nov 2017 02:32:25 +0100 Subject: [PATCH 3/3] FIX list of module not complete when module mb_strlen not available Conflicts: dev/dolibarr_changes.txt --- dev/dolibarr_changes.txt | 15 ++++++++++++++- htdocs/includes/parsedown/Parsedown.php | 10 +++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt index 3c2b7b3c932..0570525cdad 100644 --- a/dev/dolibarr_changes.txt +++ b/dev/dolibarr_changes.txt @@ -110,4 +110,17 @@ to get if ($className == 'Luracast\Restler\string') return; if ($className == 'Luracast\Restler\mixed') return; ... - \ No newline at end of file + + +PARSEDOWN +--------- + +* Fix to avoid fatal error when mb_strlen not available: + + // @CHANGE LDR Fix when mb_strlen is not available + //$shortage = 4 - mb_strlen($line, 'utf-8') % 4; + if (function_exists('mb_strlen')) $len = mb_strlen($line, 'utf-8'); + else $len = strlen($line); + $shortage = 4 - $len % 4; + + diff --git a/htdocs/includes/parsedown/Parsedown.php b/htdocs/includes/parsedown/Parsedown.php index 20863a7537a..a1ec563683f 100644 --- a/htdocs/includes/parsedown/Parsedown.php +++ b/htdocs/includes/parsedown/Parsedown.php @@ -141,7 +141,11 @@ class Parsedown foreach ($parts as $part) { - $shortage = 4 - mb_strlen($line, 'utf-8') % 4; + // @CHANGE LDR Fix when mb_strlen is not available + //$shortage = 4 - mb_strlen($line, 'utf-8') % 4; + if (function_exists('mb_strlen')) $len = mb_strlen($line, 'utf-8'); + else $len = strlen($line); + $shortage = 4 - $len % 4; $line .= str_repeat(' ', $shortage); $line .= $part; @@ -515,10 +519,10 @@ class Parsedown ), ); - if($name === 'ol') + if($name === 'ol') { $listStart = stristr($matches[0], '.', true); - + if($listStart !== '1') { $Block['element']['attributes'] = array('start' => $listStart);