From f219b0f4fab8977b5b74fb8b55f26b100080d1fc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 29 Jun 2020 08:55:36 +0200 Subject: [PATCH] A user can remove its group's membership --- src/controllers/groups_controller.rs | 15 +++++++++++++++ src/controllers/routes.rs | 2 ++ 2 files changed, 17 insertions(+) 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)),