Get safely the ID of a group in a POST request.

This commit is contained in:
Pierre HUBERT 2018-07-04 06:12:27 +02:00
parent 0a3ae02bce
commit 291558578b

View File

@ -563,4 +563,24 @@ function getPostUserDirectory(string $name) : string {
//Return the directory //Return the directory
return $directory; return $directory;
}
/**
* Get a POST group ID
*
* @param string $name The name of variable in the $_POST request
* @return int The ID of the group
* @throws RESTException If the directory is missing
*/
function getPostGroupId(string $name) : int {
//Get the ID of the group
$id = postInt($name);
//Check if the group exists or not
if(!components()->groups->exists($id))
Rest_fatal_error(404, "Specified group does not exists !");
//Return the ID of the group
return $id;
} }