From 5ef707f27ae56ff59aaea1702244bc67f13effb0 Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Thu, 10 Apr 2025 15:05:42 -0300 Subject: [PATCH] chore: remove meteor calls from permissions (server) (#35750) --- apps/meteor/app/api/server/v1/permissions.ts | 5 ++-- .../server/streamer/permissions/index.ts | 27 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/apps/meteor/app/api/server/v1/permissions.ts b/apps/meteor/app/api/server/v1/permissions.ts index 65dfafe5ccc..9b7cee5d3c7 100644 --- a/apps/meteor/app/api/server/v1/permissions.ts +++ b/apps/meteor/app/api/server/v1/permissions.ts @@ -3,6 +3,7 @@ import { Permissions, Roles } from '@rocket.chat/models'; import { isBodyParamsValidPermissionUpdate } from '@rocket.chat/rest-typings'; import { Meteor } from 'meteor/meteor'; +import { permissionsGetMethod } from '../../../authorization/server/streamer/permissions'; import { notifyOnPermissionChangedById } from '../../../lib/server/lib/notifyListener'; import { API } from '../api'; @@ -21,7 +22,7 @@ API.v1.addRoute( updatedSinceDate = new Date(updatedSince); } - const result = (await Meteor.callAsync('permissions/get', updatedSinceDate)) as { + const result = (await permissionsGetMethod(updatedSinceDate)) as { update: IPermission[]; remove: IPermission[]; }; @@ -69,7 +70,7 @@ API.v1.addRoute( void notifyOnPermissionChangedById(permission._id); } - const result = (await Meteor.callAsync('permissions/get')) as IPermission[]; + const result = (await permissionsGetMethod()) as IPermission[]; return API.v1.success({ permissions: result, diff --git a/apps/meteor/app/authorization/server/streamer/permissions/index.ts b/apps/meteor/app/authorization/server/streamer/permissions/index.ts index e74cf37869f..545b7067e67 100644 --- a/apps/meteor/app/authorization/server/streamer/permissions/index.ts +++ b/apps/meteor/app/authorization/server/streamer/permissions/index.ts @@ -14,22 +14,27 @@ declare module '@rocket.chat/ddp-client' { } } +export const permissionsGetMethod = async ( + updatedAt?: Date, +): Promise>[] }> => { + const records = await Permissions.find(updatedAt && { _updatedAt: { $gt: updatedAt } }).toArray(); + + if (updatedAt instanceof Date) { + return { + update: records, + remove: await Permissions.trashFindDeletedAfter(updatedAt, {}, { projection: { _id: 1, _deletedAt: 1 } }).toArray(), + }; + } + + return records; +}; + Meteor.methods({ async 'permissions/get'(updatedAt?: Date) { check(updatedAt, Match.Maybe(Date)); - // TODO: should we return this for non logged users? // TODO: we could cache this collection - const records = await Permissions.find(updatedAt && { _updatedAt: { $gt: updatedAt } }).toArray(); - - if (updatedAt instanceof Date) { - return { - update: records, - remove: await Permissions.trashFindDeletedAfter(updatedAt, {}, { projection: { _id: 1, _deletedAt: 1 } }).toArray(), - }; - } - - return records; + return permissionsGetMethod(updatedAt); }, });