Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
658 stars 90 forks source link

Document still inserted/removed if my before-hook returns `false` #232

Closed SimonSimCity closed 6 years ago

SimonSimCity commented 6 years ago

In the documentation and in this change (https://github.com/matb33/meteor-collection-hooks/commit/2c986b3aeae7ad3ce3e146669675fd515db346b9) I saw that it shouldn't be possible to insert a document if the hook for before.insert returns false.

As I've tried this in my project, I was able to still insert or remove documents. Here's a very short sample for a test:

const MyCollection = new Mongo.Collection('my-collection');
MyCollection.before.insert(() => false);
MyCollection.insert({});
// MyCollection.find().count() === 0 --> is false

What works is throwing an error ...

const MyCollection = new Mongo.Collection('my-collection');
MyCollection.before.insert(() => { throw new Meteor.Error(0, 'not-allowed'); });
MyCollection.insert({}); // throws an error

But then not all before-hooks are run, which isn't much of a hassle to me, but maybe to others. What I specially dislike about this way is that I now both have to check for the outcome of the method as well as catching the error - and this on every method where I do something on this collection.

EDIT: I could confirm that updates stop, but not insert or remove calls ...

SimonSimCity commented 6 years ago

It seems like something on my setup here is ruining it for some collections ... I'm closing it until further notice.