Skip to content

Commit

Permalink
fix: stop counting invites as used seats/space in workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jzunigax2 committed Nov 8, 2024
1 parent 78c2dfb commit 1fada0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/modules/workspaces/domains/workspaces.domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/workspaces/workspaces.usecase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2004,7 +2004,7 @@ describe('WorkspacesUsecases', () => {

expect(workspaceUsage).toEqual({
totalWorkspaceSpace: 1000000,
spaceAssigned: 900000,
spaceAssigned: 700000,
spaceUsed: 400000,
});
});
Expand Down
24 changes: 12 additions & 12 deletions src/modules/workspaces/workspaces.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class WorkspacesUsecases {
);
}

const spaceLeft = await this.getAssignableSpaceInWorkspace(workspace);
const spaceLeft = await this.getOwnerAvailableSpace(workspace);

const spaceToAssign =
createInviteDto.spaceLimit ??
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<boolean> {
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,*/
);
}

Expand Down

0 comments on commit 1fada0a

Please sign in to comment.