File tree Expand file tree Collapse file tree 14 files changed +54
-77
lines changed
apps/meteor/app/apps/server/bridges Expand file tree Collapse file tree 14 files changed +54
-77
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @rocket.chat/apps-engine " : minor
3+ " @rocket.chat/meteor " : minor
4+ ---
5+
6+ Adds the ` getUserRoomIds ` method to the ` UserRead ` accessor in the Apps-Engine, graduating it from the experimental bridge to the stable user bridge.
Original file line number Diff line number Diff line change 11import type { IAppServerOrchestrator } from '@rocket.chat/apps' ;
22import { ExperimentalBridge } from '@rocket.chat/apps-engine/server/bridges' ;
3- import { Subscriptions } from '@rocket.chat/models' ;
4-
5- import { metrics } from '../../../metrics/server/lib/metrics' ;
63
74export class AppExperimentalBridge extends ExperimentalBridge {
8- constructor ( private readonly orch : IAppServerOrchestrator ) {
5+ constructor ( protected readonly orch : IAppServerOrchestrator ) {
96 super ( ) ;
107 }
11-
12- protected async getUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] | undefined > {
13- const stopTimer = metrics . appBridgeMethods . startTimer ( {
14- bridge : 'experimental' ,
15- method : 'getUserRoomIds' ,
16- app_id : appId ,
17- } ) ;
18-
19- try {
20- this . orch . debugLog ( `The App ${ appId } is getting the room ids for the user: "${ userId } "` ) ;
21-
22- const subscriptions = await Subscriptions . findByUserId ( userId , { projection : { rid : 1 } } ) . toArray ( ) ;
23-
24- const result = subscriptions . map ( ( subscription ) => subscription . rid ) ;
25-
26- return result ;
27- } finally {
28- stopTimer ( ) ;
29- }
30- }
318}
Original file line number Diff line number Diff line change @@ -168,4 +168,12 @@ export class AppUserBridge extends UserBridge {
168168 protected async getUserUnreadMessageCount ( uid : string ) : Promise < number > {
169169 return Subscriptions . getBadgeCount ( uid ) ;
170170 }
171+
172+ protected async getUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] > {
173+ this . orch . debugLog ( `The App ${ appId } is getting the room ids for the user: "${ userId } "` ) ;
174+
175+ const subscriptions = await Subscriptions . findByUserId ( userId , { projection : { rid : 1 } } ) . toArray ( ) ;
176+
177+ return subscriptions . map ( ( subscription ) => subscription . rid ) ;
178+ }
171179}
Original file line number Diff line number Diff line change 55 * team evaluates the proper signature, underlying implementation and performance
66 * impact of candidates for future APIs
77 */
8- export interface IExperimentalRead {
9- /**
10- * Fetches the IDs of the rooms that the user is a member of.
11- *
12- * @returns an array of room ids or undefined if the app doesn't have the proper permission
13- * @experimental
14- */
15- getUserRoomIds ( userId : string ) : Promise < string [ ] | undefined > ;
16- }
8+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
9+ export interface IExperimentalRead { }
Original file line number Diff line number Diff line change @@ -19,4 +19,11 @@ export interface IUserRead {
1919 * @param uid user's id
2020 */
2121 getUserUnreadMessageCount ( uid : string ) : Promise < number | undefined > ;
22+
23+ /**
24+ * Fetches the IDs of the rooms that the user is a member of.
25+ *
26+ * @param userId the user whose memberships should be returned
27+ */
28+ getUserRoomIds ( userId : string ) : Promise < string [ ] > ;
2229}
Original file line number Diff line number Diff line change @@ -3,11 +3,7 @@ import type { ExperimentalBridge } from '../bridges';
33
44export class ExperimentalRead implements IExperimentalRead {
55 constructor (
6- private experimentalBridge : ExperimentalBridge ,
7- private appId : string ,
6+ protected readonly experimentalBridge : ExperimentalBridge ,
7+ protected readonly appId : string ,
88 ) { }
9-
10- public async getUserRoomIds ( userId : string ) : Promise < string [ ] | undefined > {
11- return this . experimentalBridge . doGetUserRoomIds ( userId , this . appId ) ;
12- }
139}
Original file line number Diff line number Diff line change @@ -23,4 +23,8 @@ export class UserRead implements IUserRead {
2323 public getUserUnreadMessageCount ( uid : string ) : Promise < number > {
2424 return this . userBridge . doGetUserUnreadMessageCount ( uid , this . appId ) ;
2525 }
26+
27+ public getUserRoomIds ( userId : string ) : Promise < string [ ] > {
28+ return this . userBridge . doGetUserRoomIds ( userId , this . appId ) ;
29+ }
2630}
Original file line number Diff line number Diff line change 11import { BaseBridge } from './BaseBridge' ;
2- import { PermissionDeniedError } from '../errors/PermissionDeniedError' ;
3- import { AppPermissionManager } from '../managers/AppPermissionManager' ;
4- import { AppPermissions } from '../permissions/AppPermissions' ;
52
63/**
74 * @description
@@ -10,31 +7,4 @@ import { AppPermissions } from '../permissions/AppPermissions';
107 * team evaluates the proper signature, underlying implementation and performance
118 * impact of candidates for future APIs
129 */
13- export abstract class ExperimentalBridge extends BaseBridge {
14- /**
15- *
16- * Candidate bridge: User bridge
17- */
18- public async doGetUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] | undefined > {
19- if ( this . hasPermission ( 'getUserRoomIds' , appId ) ) {
20- return this . getUserRoomIds ( userId , appId ) ;
21- }
22- }
23-
24- protected abstract getUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] | undefined > ;
25-
26- private hasPermission ( feature : keyof typeof AppPermissions . experimental , appId : string ) : boolean {
27- if ( AppPermissionManager . hasPermission ( appId , AppPermissions . experimental [ feature ] ) ) {
28- return true ;
29- }
30-
31- AppPermissionManager . notifyAboutError (
32- new PermissionDeniedError ( {
33- appId,
34- missingPermissions : [ AppPermissions . experimental [ feature ] ] ,
35- } ) ,
36- ) ;
37-
38- return false ;
39- }
40- }
10+ export abstract class ExperimentalBridge extends BaseBridge { }
Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ export abstract class UserBridge extends BaseBridge {
4545 }
4646 }
4747
48+ public async doGetUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] > {
49+ if ( this . hasReadPermission ( appId ) ) {
50+ return this . getUserRoomIds ( userId , appId ) ;
51+ }
52+ }
53+
4854 public async doDeleteUsersCreatedByApp ( appId : string , type : UserType . BOT | UserType . APP ) : Promise < boolean > {
4955 if ( this . hasWritePermission ( appId ) ) {
5056 return this . deleteUsersCreatedByApp ( appId , type ) ;
@@ -67,6 +73,8 @@ export abstract class UserBridge extends BaseBridge {
6773
6874 protected abstract getUserUnreadMessageCount ( uid : string , appId : string ) : Promise < number > ;
6975
76+ protected abstract getUserRoomIds ( userId : string , appId : string ) : Promise < string [ ] > ;
77+
7078 /**
7179 * Creates a user.
7280 * @param data the essential data for creating a user
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ export const AppPermissions = {
123123 provide : { name : 'outbound-communication.provide' } ,
124124 } ,
125125 'experimental' : {
126- getUserRoomIds : { name : 'experimental.getUserRoomIds ' } ,
126+ default : { name : 'experimental.default ' } ,
127127 } ,
128128} ;
129129
You can’t perform that action at this time.
0 commit comments