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/packages/rocketchat-authorization/server/models/Base.js

45 lines
1.2 KiB

RocketChat.models._Base.prototype.roleBaseQuery = function(/*userId, scope*/) {
return;
};
RocketChat.models._Base.prototype.findRolesByUserId = function(userId/*, options*/) {
const query = this.roleBaseQuery(userId);
return this.find(query, { fields: { roles: 1 } });
};
RocketChat.models._Base.prototype.isUserInRole = function(userId, roleName, scope) {
const query = this.roleBaseQuery(userId, scope);
if (query == null) {
return false;
}
query.roles = roleName;
return !_.isUndefined(this.findOne(query));
};
RocketChat.models._Base.prototype.addRolesByUserId = function(userId, roles, scope) {
roles = [].concat(roles);
const query = this.roleBaseQuery(userId, scope);
const update = {
$addToSet: {
roles: { $each: roles }
}
};
return this.update(query, update);
};
RocketChat.models._Base.prototype.removeRolesByUserId = function(userId, roles, scope) {
roles = [].concat(roles);
const query = this.roleBaseQuery(userId, scope);
const update = {
$pullAll: {
roles
}
};
return this.update(query, update);
};
RocketChat.models._Base.prototype.findUsersInRoles = function() {
throw new Meteor.Error('overwrite-function', 'You must overwrite this function in the extended classes');
};