diff --git a/design/create-design-docs.js b/design/create-design-docs.js index 840f1f825d..f92dde05b1 100644 --- a/design/create-design-docs.js +++ b/design/create-design-docs.js @@ -1,10 +1,11 @@ const fs = require('fs'); -const mime = require('mime'); -const basePath = require('path').basename(__dirname) + '/'; +const path = require('path'); +const basePath = __dirname; const readDirectories = (err, directories) => { directories.forEach((dir) => { - fs.stat(basePath + dir, (err, stat) => { + const dirFullPath = path.join(basePath, dir); + fs.stat(dirFullPath, (err, stat) => { if (stat.isDirectory()) { readDir(dir, readFiles(dir)); } @@ -14,24 +15,24 @@ const readDirectories = (err, directories) => { const readFiles = (dirPath) => (err, files) => { files.forEach((file) => { - const filePath = basePath + dirPath + '/' + file; + const filePath = path.join(basePath, dirPath, file); fs.stat(filePath, (err, stat) => { - if (mime.getType(file) === 'application/javascript' && file !== 'create-design-docs.js') { - writeDesignDoc(require('./' + dirPath + '/' + file), filePath); + if (path.extname(file) === '.js' && file !== 'create-design-docs.js') { + const modulePath = './' + path.join(dirPath, file); + writeDesignDoc(require(modulePath), filePath); } }); }); }; const readDir = (dirPath, callback) => { - fs.readdir(basePath + dirPath, callback); + fs.readdir(path.join(basePath, dirPath), callback); }; const writeDesignDoc = (design, filePath) => { - fs.writeFile(filePath + 'on', JSON.stringify(recurseObject(design)), (err) => { if (err) { - console.log(err); + console.error('Error writing design doc for:', filePath, err); } }); }; diff --git a/design/resources/resources-design.json b/design/resources/resources-design.json index aa979de7ab..64d1b13d58 100644 --- a/design/resources/resources-design.json +++ b/design/resources/resources-design.json @@ -1 +1 @@ -{"views":{"count_tags":{"map":"function (doc) {\n for (var i = 0; i < doc.tags.length; i++) {\n emit(doc.tags[i], 1);\n }\n }","reduce":"_count"},"titles":{"map":"function (doc) {\n emit(doc.title.toLowerCase().trim(), doc.privateFor);\n }"}},"validate_doc_update":"function (newDoc, oldDoc, userCtx, secObj) {\n var is_server_or_database_admin = function(userCtx, secObj) {\n // see if the user is a server admin\n if(userCtx.roles.indexOf('_admin') !== -1) {\n return true; // a server admin\n }\n\n // see if the user a database admin specified by name\n if(secObj && secObj.admins && secObj.admins.names) {\n if(secObj.admins.names.indexOf(userCtx.name) !== -1) {\n return true; // database admin\n }\n }\n\n // see if the user a database admin specified by role\n if(secObj && secObj.admins && secObj.admins.roles) {\n var db_roles = secObj.admins.roles;\n for(var idx = 0; idx < userCtx.roles.length; idx++) {\n var user_role = userCtx.roles[idx];\n if(db_roles.indexOf(user_role) !== -1) {\n return true; // role matches!\n }\n }\n }\n return false; // default to no admin\n }\n function writeAccess(userCtx, secObj) {\n var writeRoles = ['learner', 'leader'];\n return userCtx.roles.reduce(\n function(hasWriteRole, role) {\n return hasWriteRole || writeRoles.indexOf(role) > -1;\n },\n false\n ) || is_server_or_database_admin(userCtx, secObj);\n }\n var hasWriteAccess = writeAccess(userCtx);\n if(!hasWriteAccess) {\n throw { forbidden: 'You have only read-only access' };\n }\n }"} +{"views":{"count_tags":{"map":"function (doc) {\n for (var i = 0; i < doc.tags.length; i++) {\n emit(doc.tags[i], 1);\n }\n }","reduce":"_count"},"titles":{"map":"function (doc) {\n emit(doc.title.toLowerCase().trim(), doc.privateFor);\n }"}},"validate_doc_update":"function (newDoc, oldDoc, userCtx, secObj) {\n var is_server_or_database_admin = function(userCtx, secObj) {\n // see if the user is a server admin\n if(userCtx.roles.indexOf('_admin') !== -1) {\n return true; // a server admin\n }\n\n // see if the user a database admin specified by name\n if(secObj && secObj.admins && secObj.admins.names) {\n if(secObj.admins.names.indexOf(userCtx.name) !== -1) {\n return true; // database admin\n }\n }\n\n // see if the user a database admin specified by role\n if(secObj && secObj.admins && secObj.admins.roles) {\n var db_roles = secObj.admins.roles;\n for(var idx = 0; idx < userCtx.roles.length; idx++) {\n var user_role = userCtx.roles[idx];\n if(db_roles.indexOf(user_role) !== -1) {\n return true; // role matches!\n }\n }\n }\n return false; // default to no admin\n }\n function writeAccess(userCtx, secObj) {\n var writeRoles = ['learner', 'leader'];\n return userCtx.roles.reduce(\n function(hasWriteRole, role) {\n return hasWriteRole || writeRoles.indexOf(role) > -1;\n },\n false\n ) || is_server_or_database_admin(userCtx, secObj);\n }\n var hasWriteAccess = writeAccess(userCtx);\n if(!hasWriteAccess) {\n throw { forbidden: 'You have only read-only access' };\n }\n }"} \ No newline at end of file diff --git a/src/app/manager-dashboard/reports/reports-detail.component.ts b/src/app/manager-dashboard/reports/reports-detail.component.ts index fded6a350b..a75817ef52 100644 --- a/src/app/manager-dashboard/reports/reports-detail.component.ts +++ b/src/app/manager-dashboard/reports/reports-detail.component.ts @@ -1050,4 +1050,4 @@ export class ReportsDetailComponent implements OnInit, OnDestroy { this.planetMessageService.showMessage($localize`Comparison table downloaded as CSV`); } -} \ No newline at end of file +}