From 8e8b3c2998cbb231ef917f10f745f39f3d707b9b Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sun, 8 Dec 2024 22:06:02 -0500 Subject: [PATCH 1/2] Implemented deleting user and banning user functionalities --- admin/src/components/ServerData.tsx | 3 ++ admin/src/components/Users.tsx | 81 +++++++++++++++++++++++++++++ server/src/user/user.service.ts | 1 + 3 files changed, 85 insertions(+) diff --git a/admin/src/components/ServerData.tsx b/admin/src/components/ServerData.tsx index 26167e72..923cb5d4 100644 --- a/admin/src/components/ServerData.tsx +++ b/admin/src/components/ServerData.tsx @@ -145,6 +145,9 @@ export function ServerDataProvider(props: { children: ReactNode }) { deleteUser(id: string) { return sock.updateUserData({ user: { id }, deleted: true }); }, + banUser(userId: string, isBanned: boolean) { + return sock.banUser({ userId, isBanned }); + }, updateGroup(group: GroupDto) { return sock.updateGroupData({ group, deleted: false }); }, diff --git a/admin/src/components/Users.tsx b/admin/src/components/Users.tsx index 13590d64..991cedfb 100644 --- a/admin/src/components/Users.tsx +++ b/admin/src/components/Users.tsx @@ -49,6 +49,41 @@ const SAVE_SVG = ( ); +const DELETE_SVG = ( + + + +); + +const BLOCK_SVG = ( + + + + +); + const styles = { select: { margin: "0 20px" }, buttonsCellContainer: { @@ -58,6 +93,7 @@ const styles = { display: "flex", justifyContent: "flex-end", alignItems: "center", + gap: "3px", }, editButton: { background: "#f3f3f3", @@ -106,6 +142,7 @@ function toForm(user: any) { id: user.id, groupId: user.groupId, email: user.email, + isBanned: user.isBanned, }; } @@ -163,6 +200,50 @@ function getColumns(setRowsData: any, serverData: any) { > {EDIT_SVG} + + ), editorCellRenderer: ({ diff --git a/server/src/user/user.service.ts b/server/src/user/user.service.ts index ace3bf41..f5e9a156 100644 --- a/server/src/user/user.service.ts +++ b/server/src/user/user.service.ts @@ -157,6 +157,7 @@ export class UserService { await this.prisma.$transaction(async tx => { await this.groupsService.fixOrDeleteGroup({ id: user.groupId }, tx); }); + console.log(`User ${user.id} deleted!`); } /** From 3bf0d8d85dd33ecd4e8949221d7615aa04f7f959 Mon Sep 17 00:00:00 2001 From: Frank Dai Date: Sun, 8 Dec 2024 22:14:07 -0500 Subject: [PATCH 2/2] Added documentation for user related backend service --- server/src/user/user.service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/user/user.service.ts b/server/src/user/user.service.ts index f5e9a156..e110c21b 100644 --- a/server/src/user/user.service.ts +++ b/server/src/user/user.service.ts @@ -141,6 +141,10 @@ export class UserService { return await this.prisma.user.findMany(); } + /** + * Delete a user based on their user id. + * @param user the user who will be deleted. + */ async deleteUser(ability: AppAbility, user: User) { if ( (await this.prisma.user.count({ @@ -220,6 +224,13 @@ export class UserService { }); } + /** + * Check if a user exists based on their authentication type and id. + * @param authType the authentication type of the user. + * @param id the id of the user. + * @returns A promise containing the user if they exist. + * Otherwise, it returns null. + */ async checkIfUserExists( authType: AuthType, id: string,