From f325ec7ae7bc044def3f3ba518e69c6d153e0e31 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 21 Jan 2021 18:05:48 +0100 Subject: [PATCH] Start to delete user account --- src/helpers/account_helper.rs | 5 +++-- src/helpers/groups_helper.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) 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 {