mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-09 17:05:01 +00:00
uberf-10488: allow ws limit per account (#8864)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
b864fc6f91
commit
ebdb7fc392
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
`
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -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 })
|
||||
|
@ -58,6 +58,7 @@ export interface Account {
|
||||
locale?: string
|
||||
hash?: Buffer | null
|
||||
salt?: Buffer | null
|
||||
maxWorkspaces?: number
|
||||
}
|
||||
|
||||
// TODO: type data with generic type
|
||||
|
Loading…
Reference in New Issue
Block a user