feature/single-organization-limit (#4620)

feat: enforce single organization limit during registration
This commit is contained in:
Ong Chung Yau 2025-06-10 23:12:09 +08:00 committed by GitHub
parent e17994d8fe
commit 21caedde72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View File

@ -104,6 +104,11 @@ export class AccountService {
}
}
private async ensureOneOrganizationOnly(queryRunner: QueryRunner) {
const organizations = await this.organizationservice.readOrganization(queryRunner)
if (organizations.length > 0) throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'You can only have one organization')
}
private async createRegisterAccount(data: AccountDTO, queryRunner: QueryRunner) {
data = this.initializeAccountDTO(data)
@ -111,6 +116,7 @@ export class AccountService {
switch (platform) {
case Platform.OPEN_SOURCE:
await this.ensureOneOrganizationOnly(queryRunner)
data.organization.name = OrganizationName.DEFAULT_ORGANIZATION
data.organizationUser.role = await this.roleService.readGeneralRoleByName(GeneralRole.OWNER, queryRunner)
data.workspace.name = WorkspaceName.DEFAULT_WORKSPACE
@ -196,6 +202,7 @@ export class AccountService {
data.workspace.name = WorkspaceName.DEFAULT_PERSONAL_WORKSPACE
data.workspaceUser.role = await this.roleService.readGeneralRoleByName(GeneralRole.PERSONAL_WORKSPACE, queryRunner)
} else {
await this.ensureOneOrganizationOnly(queryRunner)
data.organizationUser.role = await this.roleService.readGeneralRoleByName(GeneralRole.OWNER, queryRunner)
data.workspace.name = WorkspaceName.DEFAULT_WORKSPACE
data.workspaceUser.role = data.organizationUser.role