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:
commit
d1befcb1ba
@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
use Luracast\Restler\RestException;
|
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
|
* 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
|
* Add a user into a group
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user