From f52689378622c068a5398875a08296bead1565f7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 9 Jul 2018 16:01:38 +0200 Subject: [PATCH] Can cancel a membership invitation --- RestControllers/GroupsController.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/RestControllers/GroupsController.php b/RestControllers/GroupsController.php index 04d96d2..af61d43 100644 --- a/RestControllers/GroupsController.php +++ b/RestControllers/GroupsController.php @@ -436,6 +436,31 @@ class GroupsController { return self::GroupMemberToAPI($membership); } + /** + * Cancel a membership invitation + * + * @url POST /groups/cancel_invitation + */ + public function canceInvitation() : 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 really been invited to the group or not + if(components()->groups->getMembershipLevel($userID, $groupID) != GroupMember::INVITED) + Rest_fatal_error(401, "This user has not been invited to join this group!"); + + //Cancel group invitation + if(!components()->groups->deleteInvitation($userID, $groupID)) + Rest_fatal_error(500, "Could not cancel membership invitation!"); + + //Success + return array("success" => "Membership invitation has been cancelled !"); + } + /** * Parse a GroupInfo object into an array for the API *