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

18 lines
819 B

import { Roles } from '../../../models/server/raw';
import { ISubscription } from '../../../../definition/ISubscription';
export const hasAnyRoleAsync = async (userId: string, roleNames: string[], scope?: string | undefined): Promise<boolean> => {
if (!userId || userId === '') {
return false;
}
return Roles.isUserInRoles(userId, roleNames, scope);
};
export const hasRole = (userId: string, roleNames: string, scope?: string | undefined): boolean =>
Promise.await(hasAnyRoleAsync(userId, [roleNames], scope));
export const hasAnyRole = (userId: string, roleNames: string[], scope?: string | undefined): boolean =>
Promise.await(hasAnyRoleAsync(userId, roleNames, scope));
export const subscriptionHasRole = (sub: ISubscription, role: string): boolean | undefined => sub.roles && sub.roles.includes(role);