The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/api/server/lib/projectionAllowsAttribute.ts

19 lines
795 B

import type { IRocketChatRecord } from '@rocket.chat/core-typings';
import type { FindOptions } from 'mongodb';
export function projectionAllowsAttribute(attributeName: string, options?: FindOptions<IRocketChatRecord>): boolean {
if (!options?.projection) {
return true;
}
if (attributeName in options.projection) {
return Boolean(options.projection[attributeName]);
}
const projectingAllowedFields = Object.values(options.projection).some((value) => Boolean(value));
// If the attribute is not on the projection list, return the opposite of the values in the projection. aka:
// if the projection is specifying blocked fields, then this field is allowed;
// if the projection is specifying allowed fields, then this field is blocked;
return !projectingAllowedFields;
}