From 1fada0a7afb8b6331a947ce10aa9be9b99566483 Mon Sep 17 00:00:00 2001 From: jzunigax2 <125698953+jzunigax2@users.noreply.github.com> Date: Fri, 8 Nov 2024 08:31:14 -0600 Subject: [PATCH] fix: stop counting invites as used seats/space in workspaces --- .../workspaces/domains/workspaces.domain.ts | 4 ++-- .../workspaces/workspaces.usecase.spec.ts | 8 +++---- src/modules/workspaces/workspaces.usecase.ts | 24 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/modules/workspaces/domains/workspaces.domain.ts b/src/modules/workspaces/domains/workspaces.domain.ts index 7c50d4a1..1683a8b8 100644 --- a/src/modules/workspaces/domains/workspaces.domain.ts +++ b/src/modules/workspaces/domains/workspaces.domain.ts @@ -62,8 +62,8 @@ export class Workspace implements WorkspaceAttributes { return this.setupCompleted === true; } - isWorkspaceFull(currentUsersCount: number, numberOfInvites: number = 0) { - return this.numberOfSeats <= currentUsersCount + numberOfInvites; + isWorkspaceFull(currentUsersCount: number /*, numberOfInvites: number = 0*/) { + return this.numberOfSeats <= currentUsersCount /* + numberOfInvites*/; } isDefaultTeam(team: WorkspaceTeam) { diff --git a/src/modules/workspaces/workspaces.usecase.spec.ts b/src/modules/workspaces/workspaces.usecase.spec.ts index d27f84b0..8372c774 100644 --- a/src/modules/workspaces/workspaces.usecase.spec.ts +++ b/src/modules/workspaces/workspaces.usecase.spec.ts @@ -173,7 +173,7 @@ describe('WorkspacesUsecases', () => { jest.spyOn(service, 'isWorkspaceFull').mockResolvedValueOnce(false); jest.spyOn(userRepository, 'findByUuid').mockResolvedValueOnce(user); jest - .spyOn(service, 'getAssignableSpaceInWorkspace') + .spyOn(service, 'getOwnerAvailableSpace') .mockResolvedValueOnce(6000000); jest @@ -216,7 +216,7 @@ describe('WorkspacesUsecases', () => { jest.spyOn(service, 'isWorkspaceFull').mockResolvedValueOnce(false); jest.spyOn(userRepository, 'findByUuid').mockResolvedValueOnce(user); jest - .spyOn(service, 'getAssignableSpaceInWorkspace') + .spyOn(service, 'getOwnerAvailableSpace') .mockResolvedValueOnce(6000000); jest .spyOn(service, 'getWorkspaceFixedStoragePerUser') @@ -368,7 +368,7 @@ describe('WorkspacesUsecases', () => { .mockResolvedValueOnce(null); jest.spyOn(service, 'isWorkspaceFull').mockResolvedValueOnce(false); jest - .spyOn(service, 'getAssignableSpaceInWorkspace') + .spyOn(service, 'getOwnerAvailableSpace') .mockResolvedValueOnce(spaceLeft); jest.spyOn(workspaceRepository, 'findInvite').mockResolvedValueOnce(null); jest @@ -2004,7 +2004,7 @@ describe('WorkspacesUsecases', () => { expect(workspaceUsage).toEqual({ totalWorkspaceSpace: 1000000, - spaceAssigned: 900000, + spaceAssigned: 700000, spaceUsed: 400000, }); }); diff --git a/src/modules/workspaces/workspaces.usecase.ts b/src/modules/workspaces/workspaces.usecase.ts index c0aeacfe..e8390814 100644 --- a/src/modules/workspaces/workspaces.usecase.ts +++ b/src/modules/workspaces/workspaces.usecase.ts @@ -387,7 +387,7 @@ export class WorkspacesUsecases { ); } - const spaceLeft = await this.getAssignableSpaceInWorkspace(workspace); + const spaceLeft = await this.getOwnerAvailableSpace(workspace); const spaceToAssign = createInviteDto.spaceLimit ?? @@ -1517,7 +1517,7 @@ export class WorkspacesUsecases { return userAlreadyInWorkspace.toJSON(); } - const isWorkspaceFull = await this.isWorkspaceFull(workspace, true); + const isWorkspaceFull = await this.isWorkspaceFull(workspace); if (isWorkspaceFull) { throw new BadRequestException( @@ -1758,35 +1758,35 @@ export class WorkspacesUsecases { const [ spaceLimit, totalSpaceLimitAssigned, - totalSpaceAssignedInInvitations, + //totalSpaceAssignedInInvitations, spaceUsed, ] = await Promise.all([ this.getWorkspaceNetworkLimit(workspace), this.workspaceRepository.getTotalSpaceLimitInWorkspaceUsers(workspace.id), - this.workspaceRepository.getSpaceLimitInInvitations(workspace.id), + /*this.workspaceRepository.getSpaceLimitInInvitations(workspace.id),*/ this.workspaceRepository.getTotalDriveAndBackupUsageWorkspaceUsers( workspace.id, ), ]); - const spaceAssigned = - totalSpaceLimitAssigned + totalSpaceAssignedInInvitations; + const spaceAssigned = totalSpaceLimitAssigned; return { totalWorkspaceSpace: spaceLimit, spaceAssigned, spaceUsed }; } async isWorkspaceFull( workspace: Workspace, - skipOneInvite = false, + //skipOneInvite = false, ): Promise { - const [workspaceUsersCount, workspaceInvitationsCount] = await Promise.all([ - this.workspaceRepository.getWorkspaceUsersCount(workspace.id), - this.workspaceRepository.getWorkspaceInvitationsCount(workspace.id), - ]); + const [workspaceUsersCount /*workspaceInvitationsCount*/] = + await Promise.all([ + this.workspaceRepository.getWorkspaceUsersCount(workspace.id), + //this.workspaceRepository.getWorkspaceInvitationsCount(workspace.id), + ]); return workspace.isWorkspaceFull( workspaceUsersCount, - skipOneInvite ? workspaceInvitationsCount - 1 : workspaceInvitationsCount, + /*skipOneInvite ? workspaceInvitationsCount - 1 : workspaceInvitationsCount,*/ ); }