From 285926486aa2b4b1a66290bd405da91310dda17e Mon Sep 17 00:00:00 2001 From: jzunigax2 <125698953+jzunigax2@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:09:49 -0600 Subject: [PATCH] fix: delete user from teams whenever they are removed from/exit workspace --- src/modules/workspaces/workspaces.usecase.spec.ts | 11 +++++++++++ src/modules/workspaces/workspaces.usecase.ts | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/workspaces/workspaces.usecase.spec.ts b/src/modules/workspaces/workspaces.usecase.spec.ts index 62a39b1c..d27f84b0 100644 --- a/src/modules/workspaces/workspaces.usecase.spec.ts +++ b/src/modules/workspaces/workspaces.usecase.spec.ts @@ -4894,6 +4894,9 @@ describe('WorkspacesUsecases', () => { spaceLimit: 1099511627776, // 1TB }, }); + const team = newWorkspaceTeam({ + workspaceId: workspace.id, + }); jest .spyOn(workspaceRepository, 'findWorkspaceUser') @@ -4906,6 +4909,9 @@ describe('WorkspacesUsecases', () => { .spyOn(service, 'calculateFilesSizeSum') .mockResolvedValueOnce(483183820800) // 450 GB .mockResolvedValueOnce(483183820800); // 450 GB + jest + .spyOn(teamRepository, 'getTeamsUserBelongsTo') + .mockResolvedValueOnce([team]); jest.spyOn(service, 'adjustOwnerStorage').mockResolvedValueOnce(); expect( @@ -4915,6 +4921,11 @@ describe('WorkspacesUsecases', () => { expect( workspaceRepository.deleteUserFromWorkspace, ).toHaveBeenCalledWith(member.uuid, workspace.id); + + expect(teamRepository.deleteUserFromTeam).toHaveBeenCalledWith( + member.uuid, + team.id, + ); }); }); diff --git a/src/modules/workspaces/workspaces.usecase.ts b/src/modules/workspaces/workspaces.usecase.ts index 30457cb1..c0aeacfe 100644 --- a/src/modules/workspaces/workspaces.usecase.ts +++ b/src/modules/workspaces/workspaces.usecase.ts @@ -2626,6 +2626,15 @@ export class WorkspacesUsecases { 'ADD', ); + const teamsUserBelongsTo = await this.teamRepository.getTeamsUserBelongsTo( + user.uuid, + workspaceId, + ); + + for (const team of teamsUserBelongsTo) { + await this.teamRepository.deleteUserFromTeam(user.uuid, team.id); + } + await this.workspaceRepository.deleteUserFromWorkspace( user.uuid, workspaceId,