diff --git a/src/controllers/groups_controller.rs b/src/controllers/groups_controller.rs index 82e9aaa..9df8bfc 100644 --- a/src/controllers/groups_controller.rs +++ b/src/controllers/groups_controller.rs @@ -226,4 +226,19 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult { // TODO : Send a notification, if required r.success("The membership has been successfully saved!") +} + +/// Cancel a group membership request +pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult { + let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?; + + if groups_helper::get_membership_level(&group_id, r.user_id_opt())? != GroupMembershipLevel::PENDING { + r.forbidden("You did not send a membership request to this group!".to_string())?; + } + + groups_helper::delete_member(&group_id, &r.user_id()?)?; + + // TODO : delete any related notification + + r.success("The request has been successfully cancelled!") } \ No newline at end of file diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index 365f9f9..fb24736 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -156,6 +156,8 @@ pub fn get_routes() -> Vec { Route::post("/groups/send_request", Box::new(groups_controller::send_request)), + Route::post("/groups/cancel_request", Box::new(groups_controller::cancel_request)), + // Virtual directory controller Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),