diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 2eab8b6..dddb56e 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -300,10 +300,11 @@ pub fn export(user_id: &UserID) -> ResultBoxError { } /// Delete a user's account -pub fn delete(_user_id: &UserID) -> ResultBoxError { +pub fn delete(user_id: &UserID) -> ResultBoxError { // TODO : close all websockets of user - // TODO : Delete all group membership + // Delete all group membership + groups_helper::delete_all_user_groups(user_id)?; // TODO : continue work here diff --git a/src/helpers/groups_helper.rs b/src/helpers/groups_helper.rs index 5a2f057..731053f 100644 --- a/src/helpers/groups_helper.rs +++ b/src/helpers/groups_helper.rs @@ -488,6 +488,19 @@ pub fn delete(group_id: &GroupID) -> ResultBoxError { .exec() } +/// Delete all the groups a user belongs to +pub fn delete_all_user_groups(user_id: &UserID) -> ResultBoxError { + for group_id in &get_list_user(user_id, false)? { + if is_last_admin(group_id, user_id)? { + delete(group_id)?; + } else { + delete_member(group_id, user_id)?; + } + } + + Ok(()) +} + /// Turn a database entry into a group struct fn db_to_group(row: &database::RowResult) -> ResultBoxError {