Skip to content

Instantly share code, notes, and snippets.

Created October 8, 2014 19:26
Show Gist options
  • Select an option

  • Save anonymous/ae6905cd1e6981baa7a8 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/ae6905cd1e6981baa7a8 to your computer and use it in GitHub Desktop.
// Folder.js has folders object and files object
// Here we need to load a Folder's files and update some permission, until there is no folder anymore
function shareFolderRecursively(id, permission,cb){
Folder
.findOne({ id: id })
.populate('files')
.populate('folders')
.exec(function(err,folder){
if(err){
console.log(err);
}
/** Loop trough all the current folder's files and update their permissions **/
async.each(
folder.files,
function shareFile(file,callback){
file.permission = permission;
file.save(function(err){
if(err){
callback(err);
}
else{
callback();
}
});
},
function(err){
if(err){
console.log(err);
}
else if(folder.folders.length > 0 ){
async.each(
folder.folders,
function reLoop(folder,callback2){
shareFolderRecursively(folder.id,permission,callback2);
},
function(err){
if(err){
console.log(err);
}
console.log('EVERYTHING IS DONE ');
}
);
}
else{
cb();
}
}
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment