mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-10-31 10:14:51 +00:00 
			
		
		
		
	Created a function to quickly check if user is allowed to see a post.
This commit is contained in:
		| @@ -236,6 +236,27 @@ function getPostPostID(string $name = "postID") : int { | ||||
| 	return $postID; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get the ID of a post in a rest request and check if the current | ||||
|  * user is allowed to see it or not (check for basic access at least) | ||||
|  *  | ||||
|  * @param string $name Optionnal, the name of the post id field | ||||
|  * @return int $postID The ID of the post | ||||
|  */ | ||||
| function getPostPostIDWithAccess(string $name = "postID") : int { | ||||
|  | ||||
| 	//Get the ID of the post | ||||
| 	$postID = getPostPostID($name); | ||||
|  | ||||
| 	//Check user can see the post | ||||
| 	if(CS::get()->components->posts->access_level($postID, userID) === Posts::NO_ACCESS) | ||||
| 		Rest_fatal_error(401, "You are not allowed to access this post informations !"); | ||||
| 	 | ||||
| 	//Return post ID | ||||
| 	return $postID; | ||||
|  | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Get the ID of a movie in a rest request | ||||
|  *  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Pierre
					Pierre