Can get a user membership

This commit is contained in:
Pierre HUBERT
2018-07-09 15:32:52 +02:00
parent aee09dee43
commit 1a9b152b4d
2 changed files with 47 additions and 1 deletions

View File

@ -412,6 +412,30 @@ class GroupsController {
return array("success" => "The response to the request has been successfully saved!");
}
/**
* Get information about a membership
*
* @url POST /groups/get_membership
*/
public function getMembership() : array {
//Get the ID of the target group
$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::MODERATOR_ACCESS);
//Get user ID
$userID = getPostUserID("userID");
//Check if the user has a membership or not
if(!components()->groups->hasMembership($userID, $groupID))
Rest_fatal_error(404, "Specified user does not have any membership in this group!");
//Get user membership
$membership = components()->groups->getMembership($userID, $groupID);
//Parse and return result
return self::GroupMemberToAPI($membership);
}
/**
* Parse a GroupInfo object into an array for the API
*