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/models/client/models/Users.js

31 lines
798 B

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
export const Users = {
findOneById(userId, options = {}) {
const query = {
_id: userId,
};
return this.findOne(query, options);
},
isUserInRole(userId, roleName) {
const user = this.findOneById(userId, { fields: { roles: 1 } });
return user && Array.isArray(user.roles) && user.roles.includes(roleName);
},
findUsersInRoles(roles, scope, options) {
roles = [].concat(roles);
const query = {
roles: { $in: roles },
};
return this.find(query, options);
},
};
// overwrite Meteor.users collection so records on it don't get erased whenever the client reconnects to websocket
Meteor.users = new Mongo.Collection(null);
Meteor.user = () => Meteor.users.findOne({ _id: Meteor.userId() });