Can invite a user to join a group.

This commit is contained in:
Pierre HUBERT
2018-09-02 14:49:15 +02:00
parent 1ef7f662e5
commit 4e0b5c5fc9
2 changed files with 46 additions and 0 deletions

View File

@ -359,6 +359,36 @@ class GroupsController {
return $members;
}
/**
* Invite a user to join the network
*
* @url POST /groups/invite
*/
public function inviteUser(){
user_login_required();
//Get target group ID
$groupID = getPostGroupIdWithAccess("group_id", GroupInfo::MODERATOR_ACCESS);
//Get target user ID
$userID = getPostUserID("userID");
//Get the current status of the user over the group
if(components()->groups->getMembershipLevel($userID, $groupID) != GroupMember::VISITOR)
Rest_fatal_error(401, "The user is not a visitor for this group!");
//Save the invitation of the user
if(!components()->groups->sendInvitation($userID, $groupID))
Rest_fatal_error(500, "Could not send user invitation!");
//Create notification
create_group_membership_notification($userID, userID, $groupID, Notification::SENT_GROUP_MEMBERSHIP_INVITATION);
//Success
return array("success" => "The user has been successfully invited to join this group!");
}
/**
* Respond to a membership invitation
*