Throw meteor error when Acl fails for subscriptions

This commit is contained in:
Oswaldo Acauan 2017-12-13 14:54:01 -02:00
parent 62454b826b
commit 2faf40e381

View File

@ -1,13 +1,14 @@
import Acl from '/imports/startup/acl';
import { Meteor } from 'meteor/meteor';
import Logger from '/imports/startup/server/logger';
const injectAclActionCheck = (name, handler) => (
(...args) => {
const credentials = args[0];
if (!Acl.can(name, credentials)) {
throw new Meteor.Error('acl-not-allowed',
`The user can't perform the action "${name}".`);
throw new Meteor.Error(
'acl-not-allowed',
`The user can't perform the action "${name}".`,
);
}
return handler(...args);
@ -18,8 +19,7 @@ const injectAclSubscribeCheck = (name, handler) => (
(...args) => {
const credentials = args[args.length - 1];
if (!Acl.can(name, ...credentials)) {
Logger.error(`acl-not-allowed, the user can't perform the subscription "${name}".`);
return [];
throw new Meteor.Error(`acl-not-allowed, the user can't perform the subscription "${name}".`);
}
return handler(...credentials);