Skip to content

Commit ebdb7fc

Browse files
authored
uberf-10488: allow ws limit per account (#8864)
Signed-off-by: Alexey Zinoviev <[email protected]>
1 parent b864fc6 commit ebdb7fc

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

.vscode/launch.json

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
"MAIL_URL": "",
197197
// "DB_NS": "account-2",
198198
// "WS_LIVENESS_DAYS": "1",
199+
// "WORKSPACE_LIMIT_PER_USER": "1",
199200
"MINIO_ACCESS_KEY": "minioadmin",
200201
"MINIO_SECRET_KEY": "minioadmin",
201202
"MINIO_ENDPOINT": "localhost"

server/account/src/__tests__/postgres.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ describe('AccountPostgresDbCollection', () => {
335335
a.timezone,
336336
a.locale,
337337
a.automatic,
338+
a.max_workspaces,
338339
p.hash,
339340
p.salt
340341
FROM global_account.account as a

server/account/src/collections/postgres.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export class AccountPostgresDbCollection
371371
a.timezone,
372372
a.locale,
373373
a.automatic,
374+
a.max_workspaces,
374375
p.hash,
375376
p.salt
376377
FROM ${this.getTableName()} as a
@@ -851,7 +852,8 @@ export class PostgresAccountDB implements AccountDB {
851852
this.getV4Migration1(),
852853
this.getV5Migration(),
853854
this.getV6Migration(),
854-
this.getV7Migration()
855+
this.getV7Migration(),
856+
this.getV8Migration()
855857
]
856858
}
857859

@@ -1145,4 +1147,14 @@ export class PostgresAccountDB implements AccountDB {
11451147
`
11461148
]
11471149
}
1150+
1151+
private getV8Migration (): [string, string] {
1152+
return [
1153+
'account_db_v8_add_account_max_workspaces',
1154+
`
1155+
ALTER TABLE ${this.ns}.account
1156+
ADD COLUMN IF NOT EXISTS max_workspaces SMALLINT;
1157+
`
1158+
]
1159+
}
11481160
}

server/account/src/operations.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,15 @@ export async function createWorkspace (
379379
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
380380
}
381381

382+
const accountObj = await db.account.findOne({ uuid: account })
383+
if (accountObj == null) {
384+
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
385+
}
386+
382387
// Get a list of created workspaces
383388
const created = (await db.workspace.find({ createdBy: socialId.personUuid })).length
384389

385-
// TODO: Add support for per person limit increase
386-
if (created >= workspaceLimitPerUser) {
390+
if (created >= (accountObj.maxWorkspaces ?? workspaceLimitPerUser)) {
387391
ctx.warn('created-by-limit', { person: socialId.key, workspace: workspaceName })
388392
throw new PlatformError(
389393
new Status(Severity.ERROR, platform.status.WorkspaceLimitReached, { workspace: workspaceName })

server/account/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface Account {
5858
locale?: string
5959
hash?: Buffer | null
6060
salt?: Buffer | null
61+
maxWorkspaces?: number
6162
}
6263

6364
// TODO: type data with generic type

0 commit comments

Comments
 (0)