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/client/hasRole.ts

21 lines
733 B

import type { IUser, IRole, IRoom } from '@rocket.chat/core-typings';
import { watch } from '../../../client/meteor/watch';
import { Roles, Subscriptions, Users } from '../../../client/stores';
export const hasRole = (userId: IUser['_id'], roleId: IRole['_id'], scope?: IRoom['_id']): boolean => {
const roleScope = watch(Roles.use, (state) => state.get(roleId)?.scope ?? 'Users');
switch (roleScope) {
case 'Subscriptions':
if (!scope) return false;
return watch(Subscriptions.use, (state) => state.find((record) => record.rid === scope)?.roles?.includes(roleId) ?? false);
case 'Users':
return watch(Users.use, (state) => state.get(userId)?.roles?.includes(roleId) ?? false);
default:
return false;
}
};