Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions design/create-design-docs.js
Original file line number Diff line number Diff line change
@@ -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));
}
Expand All @@ -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);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion design/resources/resources-design.json
Original file line number Diff line number Diff line change
@@ -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 }"}
Original file line number Diff line number Diff line change
Expand Up @@ -1050,4 +1050,4 @@ export class ReportsDetailComponent implements OnInit, OnDestroy {

this.planetMessageService.showMessage($localize`Comparison table downloaded as CSV`);
}
}
}
Loading