Doing async stuff in allow rules, remove works and update doesn't


#1

I am developing a package and wanted to be clever how I synchronize a collection with some external resource (images, to be specific). The logic is simple, if I remove an image object, the Collection.remove will take care of deleting the images as well.

So the following works perfectly

Collection.allow({
 remove:function(userId, doc) {
  var future = new Future();
  Knox.deleteMultipleFiles( doc.files, function(err,res) {
   if(err) future.return(false); else future.return(true);
  }
  return future.wait();
 }
})

However, when I try to do the same with update, it does not work. For some reason the update never gets committed

Collection.allow({
 update:function(userId, doc, fieldNames, modifier) {
  var future = new Future();
  // find the file that has changed and delete it
  var file = doc.file;
  Knox.deleteFile( file, function(err,res) {
   if(err) future.return(false); else future.return(true);
  }
  return future.wait();
 }
})

this code will delete the file, but the update will not be written to mongo.

Has anybody else noticed this?


#2

I wonder if I should file an issue on github for this.