Created
October 8, 2014 19:26
-
-
Save anonymous/ae6905cd1e6981baa7a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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