/*jslint node: true */
const pathresolver = require('angular-filemanager-nodejs-bridge').pathresolver;
const path = require('path');

pathresolver.baseDir = function(req) {

  if(!req.user || !req.user.username || !Array.isArray(req.user.global_roles)) {
    throw new Error("No valid user!");
  }

  // Admin users can see all the directories
  if(req.user.global_roles.indexOf('admin') >= 0) {
    return process.env.DATA_DIR;
  }

  // Other users can only see their own directory
  return path.join(process.env.DATA_DIR, req.user.username);
};

@@ -125,16 +125,48 @@
 'path');
+%0Aconst fs = require('fs.extra');
 %0A%0Apathre
@@ -511,22 +511,29 @@
 ctory%0A  
-return
+var baseDir =
  path.jo
@@ -576,12 +576,113 @@
 ername);
+%0A%0A  // Create the directory if it does not exist already%0A  fs.mkdirpSync(baseDir);%0A%0A  return baseDir;
 %0A%7D;%0A

Create user directories if they do not exist