chore: remove meteor calls from permissions (server) (#35750)

pull/35768/head
Marcos Spessatto Defendi 9 months ago committed by GitHub
parent cd5af1776c
commit 5ef707f27a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      apps/meteor/app/api/server/v1/permissions.ts
  2. 27
      apps/meteor/app/authorization/server/streamer/permissions/index.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,

@ -14,22 +14,27 @@ declare module '@rocket.chat/ddp-client' {
}
}
export const permissionsGetMethod = async (
updatedAt?: Date,
): Promise<IPermission[] | { update: IPermission[]; remove: WithId<RocketChatRecordDeleted<IPermission>>[] }> => {
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<ServerMethods>({
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);
},
});

Loading…
Cancel
Save