uberf-10488: allow ws limit per account (#8864)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2025-05-07 09:28:05 +04:00 committed by GitHub
parent b864fc6f91
commit ebdb7fc392
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 3 deletions

1
.vscode/launch.json vendored
View File

@ -196,6 +196,7 @@
"MAIL_URL": "",
// "DB_NS": "account-2",
// "WS_LIVENESS_DAYS": "1",
// "WORKSPACE_LIMIT_PER_USER": "1",
"MINIO_ACCESS_KEY": "minioadmin",
"MINIO_SECRET_KEY": "minioadmin",
"MINIO_ENDPOINT": "localhost"

View File

@ -335,6 +335,7 @@ describe('AccountPostgresDbCollection', () => {
a.timezone,
a.locale,
a.automatic,
a.max_workspaces,
p.hash,
p.salt
FROM global_account.account as a

View File

@ -371,6 +371,7 @@ export class AccountPostgresDbCollection
a.timezone,
a.locale,
a.automatic,
a.max_workspaces,
p.hash,
p.salt
FROM ${this.getTableName()} as a
@ -851,7 +852,8 @@ export class PostgresAccountDB implements AccountDB {
this.getV4Migration1(),
this.getV5Migration(),
this.getV6Migration(),
this.getV7Migration()
this.getV7Migration(),
this.getV8Migration()
]
}
@ -1145,4 +1147,14 @@ export class PostgresAccountDB implements AccountDB {
`
]
}
private getV8Migration (): [string, string] {
return [
'account_db_v8_add_account_max_workspaces',
`
ALTER TABLE ${this.ns}.account
ADD COLUMN IF NOT EXISTS max_workspaces SMALLINT;
`
]
}
}

View File

@ -379,11 +379,15 @@ export async function createWorkspace (
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
}
const accountObj = await db.account.findOne({ uuid: account })
if (accountObj == null) {
throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))
}
// Get a list of created workspaces
const created = (await db.workspace.find({ createdBy: socialId.personUuid })).length
// TODO: Add support for per person limit increase
if (created >= workspaceLimitPerUser) {
if (created >= (accountObj.maxWorkspaces ?? workspaceLimitPerUser)) {
ctx.warn('created-by-limit', { person: socialId.key, workspace: workspaceName })
throw new PlatformError(
new Status(Severity.ERROR, platform.status.WorkspaceLimitReached, { workspace: workspaceName })

View File

@ -58,6 +58,7 @@ export interface Account {
locale?: string
hash?: Buffer | null
salt?: Buffer | null
maxWorkspaces?: number
}
// TODO: type data with generic type