1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-12-27 22:18:51 +00:00

Can cancel a group membership invitation

This commit is contained in:
Pierre HUBERT 2020-06-29 08:46:57 +02:00
parent 7ef9f8dfc1
commit 5906c53484
2 changed files with 18 additions and 0 deletions

View File

@ -159,6 +159,22 @@ pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult {
r.set_response(GroupMemberAPI::for_list(&members))
}
/// Cancel an invitation sent to a user
pub fn cancel_invitation(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?;
let user_id = r.post_user_id("userID")?;
if groups_helper::get_membership_level(&group_id, Some(user_id.clone()))? != GroupMembershipLevel::INVITED {
r.forbidden("This user has not been invited to join this group!".to_string())?;
}
groups_helper::delete_member(&group_id, &user_id)?;
// TODO : delete related notifications
r.success("Membership invitation has been cancelled!")
}
/// Invite a user to join a group
pub fn invite_user(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("group_id", GroupAccessLevel::MODERATOR_ACCESS)?;

View File

@ -152,6 +152,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/groups/invite", Box::new(groups_controller::invite_user)),
Route::post("/groups/cancel_invitation", Box::new(groups_controller::cancel_invitation)),
Route::post("/groups/respond_invitation", Box::new(groups_controller::respond_invitation)),
Route::post("/groups/send_request", Box::new(groups_controller::send_request)),