Merge pull request #9160 from hregis/develop_api

FIX compatibility with multicompany transverse mode
This commit is contained in:
Juanjo Menent 2018-08-02 10:57:27 +02:00 committed by GitHub
commit 738caa605f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -231,11 +231,12 @@ class Users extends DolibarrApi
* *
* @param int $id User ID * @param int $id User ID
* @param int $group Group ID * @param int $group Group ID
* @param int $entity Entity ID (valid only for superadmin in multicompany transverse mode)
* @return int 1 if success * @return int 1 if success
* *
* @url GET {id}/setGroup/{group} * @url GET {id}/setGroup/{group}
*/ */
function setGroup($id, $group) { function setGroup($id, $group, $entity = 1) {
global $conf; global $conf;
@ -253,9 +254,18 @@ class Users extends DolibarrApi
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
} }
if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && ! empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity))
{
$entity = (! empty($entity) ? $entity : $conf->entity);
}
else
{
// When using API, action is done on entity of logged user because a user of entity X with permission to create user should not be able to // When using API, action is done on entity of logged user because a user of entity X with permission to create user should not be able to
// hack the security by giving himself permissions on another entity. // hack the security by giving himself permissions on another entity.
$result = $this->useraccount->SetInGroup($group, DolibarrApiAccess::$user->entity > 0 ? DolibarrApiAccess::$user->entity : $conf->entity); $entity = (DolibarrApiAccess::$user->entity > 0 ? DolibarrApiAccess::$user->entity : $conf->entity);
}
$result = $this->useraccount->SetInGroup($group, $entity);
if (! ($result > 0)) if (! ($result > 0))
{ {
throw new RestException(500, $this->useraccount->error); throw new RestException(500, $this->useraccount->error);