1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Can delete all user groups

This commit is contained in:
2020-03-26 17:08:56 +01:00
parent 9cc205f59a
commit c222c8b054
4 changed files with 47 additions and 2 deletions

View File

@ -434,4 +434,18 @@ export class AccountHelper {
return data;
}
/**
* Remove completely a user account
*
* @param userID Target user ID
*/
public static async Delete(userID: number) {
// Delete all groups memberships
await GroupsHelper.DeleteAllUsersGroups(userID);
// TODO : continue work
}
}

View File

@ -392,6 +392,17 @@ export class GroupsHelper {
}
/**
* Check out whether a user is the last admin of a user or not
*
* @param groupID Target group ID
* @param userID Target user ID
*/
private static async IsLastAdmin(groupID: number, userID: number) : Promise<boolean> {
return await this.GetMembershipLevel(groupID, userID) == GroupMembershipLevels.ADMINISTRATOR
&& await GroupsHelper.CountMembersAtLevel(groupID, GroupMembershipLevels.ADMINISTRATOR) == 1;
}
/**
* Get the current access of a user to a group
*
@ -617,6 +628,23 @@ export class GroupsHelper {
});
}
/**
* Delete all the groups the user belongs to
*
* @param userID Target user ID
*/
public static async DeleteAllUsersGroups(userID: number) {
// Process each group
for(const groupID of await this.GetListUser(userID)) {
if(await this.IsLastAdmin(groupID, userID))
await this.Delete(groupID);
else
await this.DeleteMember(groupID, userID);
}
}
/**
* Turn a database row into a {GroupInfo} object
*