From 5906c53484e64e020d3fc167f87fdbe069b45ada Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 29 Jun 2020 08:46:57 +0200 Subject: [PATCH] Can cancel a group membership invitation --- src/controllers/groups_controller.rs | 16 ++++++++++++++++ src/controllers/routes.rs | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/controllers/groups_controller.rs b/src/controllers/groups_controller.rs index a3d433a..8e7a366 100644 --- a/src/controllers/groups_controller.rs +++ b/src/controllers/groups_controller.rs @@ -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)?; diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index 696207d..b0f2f40 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -152,6 +152,8 @@ pub fn get_routes() -> Vec { 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)),