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

46 lines
1.2 KiB

10 years ago
RocketChat.models._Base.prototype.roleBaseQuery = function(/*userId, scope*/) {
return;
10 years ago
};
10 years ago
RocketChat.models._Base.prototype.findRolesByUserId = function(userId/*, options*/) {
const query = this.roleBaseQuery(userId);
return this.find(query, { fields: { roles: 1 } });
10 years ago
};
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));
10 years ago
};
RocketChat.models._Base.prototype.addRolesByUserId = function(userId, roles, scope) {
10 years ago
roles = [].concat(roles);
const query = this.roleBaseQuery(userId, scope);
const update = {
$addToSet: {
roles: { $each: roles }
}
10 years ago
};
return this.update(query, update);
10 years ago
};
RocketChat.models._Base.prototype.removeRolesByUserId = function(userId, roles, scope) {
10 years ago
roles = [].concat(roles);
const query = this.roleBaseQuery(userId, scope);
const update = {
$pullAll: {
roles
}
10 years ago
};
return this.update(query, update);
10 years ago
};
RocketChat.models._Base.prototype.findUsersInRoles = function() {
throw new Meteor.Error('overwrite-function', 'You must overwrite this function in the extended classes');
10 years ago
};