Merge pull request #10427 from EuskalMoneta/develop

NEW Get the list of groups of a user with the REST API.
This commit is contained in:
Laurent Destailleur 2019-01-27 17:58:09 +01:00 committed by GitHub
commit d1befcb1ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,8 @@
use Luracast\Restler\RestException;
//require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
/**
* API class for users
@ -231,6 +232,41 @@ class Users extends DolibarrApi
}
}
/**
* List the groups of a user
*
* @param int $id Id of user
* @return array Array of group objects
*
* @throws RestException
*
* @url GET {id}/groups
*/
function getGroups($id)
{
$obj_ret = array();
if (! DolibarrApiAccess::$user->rights->user->user->lire) {
throw new RestException(401);
}
$user = new User($this->db);
$result = $user->fetch($id);
if( ! $result ) {
throw new RestException(404, 'user not found');
}
$usergroup = new UserGroup($this->db);
$groups = $usergroup->listGroupsForUser($id, false);
$obj_ret = array();
foreach ($groups as $group) {
$obj_ret[] = $this->_cleanObjectDatas($group);
}
return $obj_ret;
}
/**
* Add a user into a group
*