-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Douglas Gubert <[email protected]>
- Loading branch information
Showing
8 changed files
with
83 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/meteor': minor | ||
--- | ||
|
||
Added a new Roles bridge to RC Apps-Engine for reading and retrieving role details. |
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,33 @@ | ||
import type { IRole } from '@rocket.chat/apps-engine/definition/roles'; | ||
import { RoleBridge } from '@rocket.chat/apps-engine/server/bridges'; | ||
import { Roles } from '@rocket.chat/models'; | ||
|
||
import type { AppServerOrchestrator } from '../../../../ee/server/apps/orchestrator'; | ||
|
||
export class AppRoleBridge extends RoleBridge { | ||
constructor(private readonly orch: AppServerOrchestrator) { | ||
super(); | ||
} | ||
|
||
protected async getOneByIdOrName(idOrName: IRole['id'] | IRole['name'], appId: string): Promise<IRole | null> { | ||
this.orch.debugLog(`The App ${appId} is getting the roleByIdOrName: "${idOrName}"`); | ||
|
||
const role = await Roles.findOneByIdOrName(idOrName); | ||
return this.orch.getConverters()?.get('roles').convertRole(role); | ||
} | ||
|
||
protected async getCustomRoles(appId: string): Promise<Array<IRole>> { | ||
this.orch.debugLog(`The App ${appId} is getting the custom roles`); | ||
|
||
const cursor = Roles.findCustomRoles(); | ||
|
||
const roles: IRole[] = []; | ||
|
||
for await (const role of cursor) { | ||
const convRole = await this.orch.getConverters()?.get('roles').convertRole(role); | ||
roles.push(convRole); | ||
} | ||
|
||
return roles; | ||
} | ||
} |
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,29 @@ | ||
import type { IRole as AppsEngineRole } from '@rocket.chat/apps-engine/definition/roles'; | ||
import type { IRole } from '@rocket.chat/core-typings'; | ||
import { Roles } from '@rocket.chat/models'; | ||
|
||
import { transformMappedData } from '../../../../ee/lib/misc/transformMappedData'; | ||
|
||
export class AppRolesConverter { | ||
async convertById(roleId: string): Promise<AppsEngineRole | undefined> { | ||
const role = await Roles.findOneById(roleId); | ||
|
||
if (!role) { | ||
return; | ||
} | ||
return this.convertRole(role); | ||
} | ||
|
||
async convertRole(role: IRole): Promise<AppsEngineRole> { | ||
const map = { | ||
id: '_id', | ||
name: 'name', | ||
description: 'description', | ||
mandatory2fa: 'mandatory2fa', | ||
protected: 'protected', | ||
scope: 'scope', | ||
}; | ||
|
||
return (await transformMappedData(role, map)) as unknown as AppsEngineRole; | ||
} | ||
} |
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