mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 21:18:57 +00:00
Can cancel a membership request.
This commit is contained in:
parent
c3bdbedb30
commit
cd8fc40810
@ -260,6 +260,29 @@ class GroupsController {
|
||||
return array("success" => "The response to the invitation was saved!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel a membership request
|
||||
*
|
||||
* @url POST /groups/cancel_request
|
||||
*/
|
||||
public function cancelRequest(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Get the ID of the group (with basic access)
|
||||
$groupID = getPostGroupIdWithAccess("id", GroupInfo::LIMITED_ACCESS);
|
||||
|
||||
//Check if the user has created a membership request
|
||||
if(components()->groups->getMembershipLevel(userID, $groupID) != GroupMember::PENDING)
|
||||
Rest_fatal_error(401, "You did not send a membership request to this group!");
|
||||
|
||||
//Try to cancel membership request
|
||||
if(!components()->groups->cancelRequest(userID, $groupID))
|
||||
Rest_fatal_error(500, "An error occurred while trying to cancel membership request!");
|
||||
|
||||
return array("success" => "The request has been successfully cancelled!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a GroupInfo object into an array for the API
|
||||
*
|
||||
|
@ -214,6 +214,22 @@ class GroupsComponent {
|
||||
array($groupID, $userID)) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user membership with a precise status
|
||||
*
|
||||
* @param int $userID Target user ID
|
||||
* @param int $groupID Target group
|
||||
* @param int $status The status of the membership to delete
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
private function deleteMembershipWithStatus(int $userID, int $groupID, int $status) : bool {
|
||||
return db()->deleteEntry(
|
||||
self::GROUPS_MEMBERS_TABLE,
|
||||
"groups_id = ? AND user_id = ? AND level = ?",
|
||||
array($groupID, $userID, $status)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a user received an invitation or not
|
||||
*
|
||||
@ -255,11 +271,18 @@ class GroupsComponent {
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function deleteInvitation(int $userID, int $groupID) : bool {
|
||||
return db()->deleteEntry(
|
||||
self::GROUPS_MEMBERS_TABLE,
|
||||
"groups_id = ? AND user_id = ? AND level = ?",
|
||||
array($groupID, $userID, GroupMember::INVITED)
|
||||
);
|
||||
return $this->deleteMembershipWithStatus($userID, $groupID, GroupMember::INVITED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel a membership request
|
||||
*
|
||||
* @param int $userID The ID of the target user
|
||||
* @param int $groupID The ID of the related group
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function cancelRequest(int $userID, int $groupID) : bool {
|
||||
return $this->deleteMembershipWithStatus($userID, $groupID, GroupMember::PENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user