-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* made bootstrap pick up admin role directly, not store on service; ensure 3 singlton entities have authorization policy type set * fixed issues with authorization reset controller; moved user auth reset to be via ID to make clear it is reloaded * fixed typos * fixed admin account not having auth policy properly set --------- Co-authored-by: Valentin Yanakiev <[email protected]>
- Loading branch information
1 parent
abee5a5
commit a8e2e11
Showing
9 changed files
with
109 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,6 @@ import { bootstrapSpaceTutorialsCallouts } from './platform-template-definitions | |
|
||
@Injectable() | ||
export class BootstrapService { | ||
private adminAgentInfo?: AgentInfo; | ||
|
||
constructor( | ||
private accountService: AccountService, | ||
private accountAuthorizationService: AccountAuthorizationService, | ||
|
@@ -296,7 +294,7 @@ export class BootstrapService { | |
userData.email | ||
); | ||
if (!userExists) { | ||
let user = await this.userService.createUser({ | ||
const user = await this.userService.createUser({ | ||
email: userData.email, | ||
accountUpn: userData.email, | ||
firstName: userData.firstName, | ||
|
@@ -306,19 +304,11 @@ export class BootstrapService { | |
}, | ||
}); | ||
|
||
const credentialsData = userData.credentials; | ||
for (const credentialData of credentialsData) { | ||
await this.adminAuthorizationService.grantCredentialToUser({ | ||
userID: user.id, | ||
type: credentialData.type, | ||
resourceID: credentialData.resourceID, | ||
}); | ||
} | ||
user = await this.userAuthorizationService.grantCredentials(user); | ||
|
||
// Once all is done, reset the user authorizations | ||
const userAuthorizations = | ||
await this.userAuthorizationService.applyAuthorizationPolicy(user); | ||
await this.userAuthorizationService.applyAuthorizationPolicy( | ||
user.id | ||
); | ||
await this.authorizationPolicyService.saveAll(userAuthorizations); | ||
|
||
const account = await this.userService.getAccount(user); | ||
|
@@ -327,16 +317,18 @@ export class BootstrapService { | |
account | ||
); | ||
await this.authorizationPolicyService.saveAll(accountAuthorizations); | ||
if (!this.adminAgentInfo) { | ||
this.adminAgentInfo = await this.createSystemAgentInfo(user); | ||
} | ||
} else { | ||
if (!this.adminAgentInfo) { | ||
const user = await this.userService.getUserByEmail(userData.email); | ||
if (user) { | ||
this.adminAgentInfo = await this.createSystemAgentInfo(user); | ||
} | ||
|
||
const credentialsData = userData.credentials; | ||
for (const credentialData of credentialsData) { | ||
await this.adminAuthorizationService.grantCredentialToUser({ | ||
userID: user.id, | ||
type: credentialData.type, | ||
resourceID: credentialData.resourceID, | ||
}); | ||
} | ||
await this.userAuthorizationService.grantCredentialsAllUsersReceive( | ||
user.id | ||
); | ||
} | ||
} | ||
} catch (error: any) { | ||
|
@@ -432,14 +424,15 @@ export class BootstrapService { | |
DEFAULT_HOST_ORG_NAMEID | ||
); | ||
if (!hostOrganization) { | ||
const adminAgentInfo = await this.getAdminAgentInfo(); | ||
hostOrganization = await this.organizationService.createOrganization( | ||
{ | ||
nameID: DEFAULT_HOST_ORG_NAMEID, | ||
profileData: { | ||
displayName: DEFAULT_HOST_ORG_DISPLAY_NAME, | ||
}, | ||
}, | ||
this.adminAgentInfo | ||
adminAgentInfo | ||
); | ||
const orgAuthorizations = | ||
await this.organizationAuthorizationService.applyAuthorizationPolicy( | ||
|
@@ -457,6 +450,21 @@ export class BootstrapService { | |
} | ||
} | ||
|
||
private async getAdminAgentInfo(): Promise<AgentInfo> { | ||
const adminUserEmail = '[email protected]'; | ||
const adminUser = await this.userService.getUserByEmail(adminUserEmail, { | ||
relations: { | ||
agent: true, | ||
}, | ||
}); | ||
if (!adminUser) { | ||
throw new BootstrapException( | ||
`Unable to load fixed admin user for creating organization: ${adminUserEmail}` | ||
); | ||
} | ||
return this.createSystemAgentInfo(adminUser); | ||
} | ||
|
||
private async ensureSpaceSingleton() { | ||
this.logger.verbose?.( | ||
'=== Ensuring at least one Account with a space is present ===', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AuthorizationPolicy1730877510629 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Get the authorization ID on the ai_server table | ||
await this.updateAuthorizationPolicyTypeOnSingleton( | ||
queryRunner, | ||
'ai_server', | ||
'ai-server' | ||
); | ||
await this.updateAuthorizationPolicyTypeOnSingleton( | ||
queryRunner, | ||
'license_policy', | ||
'license-policy' | ||
); | ||
await this.updateAuthorizationPolicyTypeOnSingleton( | ||
queryRunner, | ||
'library', | ||
'library' | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
|
||
private async updateAuthorizationPolicyTypeOnSingleton( | ||
queryRunner: QueryRunner, | ||
tableName: string, | ||
type: string | ||
) { | ||
const entities: { | ||
id: string; | ||
authorizationId: string; | ||
}[] = await queryRunner.query( | ||
`SELECT id, authorizationId FROM ${tableName}` | ||
); | ||
if (entities.length !== 1) { | ||
throw new Error(`Expected exactly one ${tableName} record`); | ||
} | ||
const entity = entities[0]; | ||
// update the authorization policy to include the new type | ||
await queryRunner.query( | ||
`UPDATE authorization_policy SET type = '${type}' WHERE id = '${entity.authorizationId}'` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters