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-lib/server/methods/robotMethods.js

28 lines
781 B

import _ from 'underscore';
9 years ago
Meteor.methods({
'robot.modelCall'(model, method, args) {
check(model, String);
check(method, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'robot.modelCall'
});
}
if (!RocketChat.authz.hasRole(Meteor.userId(), 'robot')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'robot.modelCall'
});
}
const m = RocketChat.models[model];
if (!m || !_.isFunction(m[method])) {
throw new Meteor.Error('error-invalid-method', 'Invalid method', {
method: 'robot.modelCall'
});
}
const cursor = RocketChat.models[model][method].apply(RocketChat.models[model], args);
9 years ago
return cursor && cursor.fetch ? cursor.fetch() : cursor;
9 years ago
}
});