Skip to content

Commit

Permalink
Merge pull request #426 from internxt/fix/delete-users-from-team-on-w…
Browse files Browse the repository at this point in the history
…p-removal-or-exit

[_]: fix/delete user from teams whenever they are removed from/exit workspace
  • Loading branch information
sg-gs authored Nov 7, 2024
2 parents 5c3252c + 2859264 commit 78c2dfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/modules/workspaces/workspaces.usecase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4894,6 +4894,9 @@ describe('WorkspacesUsecases', () => {
spaceLimit: 1099511627776, // 1TB
},
});
const team = newWorkspaceTeam({
workspaceId: workspace.id,
});

jest
.spyOn(workspaceRepository, 'findWorkspaceUser')
Expand All @@ -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(
Expand All @@ -4915,6 +4921,11 @@ describe('WorkspacesUsecases', () => {
expect(
workspaceRepository.deleteUserFromWorkspace,
).toHaveBeenCalledWith(member.uuid, workspace.id);

expect(teamRepository.deleteUserFromTeam).toHaveBeenCalledWith(
member.uuid,
team.id,
);
});
});

Expand Down
9 changes: 9 additions & 0 deletions src/modules/workspaces/workspaces.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 78c2dfb

Please sign in to comment.