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/authorization/server/functions/hasRole.ts

31 lines
930 B

import type { IRole, IUser, IRoom, ISubscription } from '@rocket.chat/core-typings';
import { Roles } from '@rocket.chat/models';
/**
* @deprecated use `Authorization.hasAnyRole` instead
*/
export const hasAnyRoleAsync = async (
userId: IUser['_id'],
roleIds: IRole['_id'][],
scope?: IRoom['_id'] | undefined,
): Promise<boolean> => {
if (!Array.isArray(roleIds)) {
throw new Error('error-invalid-arguments');
}
if (!userId || userId === '') {
return false;
}
return Roles.isUserInRoles(userId, roleIds, scope);
};
export const hasRoleAsync = async (userId: IUser['_id'], roleId: IRole['_id'], scope?: IRoom['_id'] | undefined): Promise<boolean> => {
if (Array.isArray(roleId)) {
throw new Error('error-invalid-arguments');
}
return hasAnyRoleAsync(userId, [roleId], scope);
};
export const subscriptionHasRole = (sub: ISubscription, role: IRole['_id']): boolean | undefined => sub.roles?.includes(role);