diff --git a/src/controllers/groups_controller.rs b/src/controllers/groups_controller.rs index 8e7a366..de97500 100644 --- a/src/controllers/groups_controller.rs +++ b/src/controllers/groups_controller.rs @@ -337,4 +337,19 @@ pub fn get_membership(r: &mut HttpRequestHandler) -> RequestResult { let membership = groups_helper::get_membership(&group_id, Some(user_id))?; r.set_response(GroupMemberAPI::new(&membership)) +} + +/// Delete the membership of a user over a group +pub fn remove_membership(r: &mut HttpRequestHandler) -> RequestResult { + let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::LIMITED_ACCESS)?; + + if groups_helper::is_last_admin(&group_id, &r.user_id()?)? { + r.forbidden("You are the last administrator of this group!".to_string())?; + } + + groups_helper::delete_member(&group_id, &r.user_id()?)?; + + // TODO : delete group membership notifications + + r.success("Your membership has been successfully deleted!") } \ No newline at end of file diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index b0f2f40..34be1da 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -168,6 +168,8 @@ pub fn get_routes() -> Vec { Route::post("/groups/get_membership", Box::new(groups_controller::get_membership)), + Route::post("/groups/remove_membership", Box::new(groups_controller::remove_membership)), + // Virtual directory controller Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),