|
|
|
@ -2,9 +2,34 @@ const { |
|
|
|
BUILTIN_PERMISSIONS, |
|
|
|
PermissionLevels, |
|
|
|
} = require("../../utilities/security/permissions") |
|
|
|
const { getRoleParams } = require("../../db/utils") |
|
|
|
const CouchDB = require("../../db") |
|
|
|
|
|
|
|
function updatePermissionOnRole(roleId, permissions, remove = false) { |
|
|
|
async function updatePermissionOnRole( |
|
|
|
appId, |
|
|
|
roleId, |
|
|
|
permissions, |
|
|
|
remove = false |
|
|
|
) { |
|
|
|
const db = new CouchDB(appId) |
|
|
|
const body = await db.allDocs( |
|
|
|
getRoleParams(null, { |
|
|
|
include_docs: true, |
|
|
|
}) |
|
|
|
) |
|
|
|
const dbRoles = body.rows.map(row => row.doc) |
|
|
|
const docUpdates = [] |
|
|
|
|
|
|
|
// now try to find any roles which need updated, e.g. removing the
|
|
|
|
// resource from another role and then adding to the new role
|
|
|
|
for (let role of dbRoles) { |
|
|
|
if (role.permissions) { |
|
|
|
// TODO
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: NEED TO WORK THIS PART OUT
|
|
|
|
return await db.bulkDocs(docUpdates) |
|
|
|
} |
|
|
|
|
|
|
|
exports.fetchBuiltin = function(ctx) { |
|
|
|
@ -16,10 +41,15 @@ exports.fetchLevels = function(ctx) { |
|
|
|
} |
|
|
|
|
|
|
|
exports.addPermission = async function(ctx) { |
|
|
|
const permissions = ctx.body.permissions, appId = ctx.appId |
|
|
|
updatePermissionOnRole |
|
|
|
const appId = ctx.appId, |
|
|
|
roleId = ctx.params.roleId, |
|
|
|
resourceId = ctx.params.resourceId |
|
|
|
ctx.body = await updatePermissionOnRole(appId, roleId, resourceId) |
|
|
|
} |
|
|
|
|
|
|
|
exports.removePermission = async function(ctx) { |
|
|
|
const permissions = ctx.body.permissions, appId = ctx.appId |
|
|
|
const appId = ctx.appId, |
|
|
|
roleId = ctx.params.roleId, |
|
|
|
resourceId = ctx.params.resourceId |
|
|
|
ctx.body = await updatePermissionOnRole(appId, roleId, resourceId, true) |
|
|
|
} |
|
|
|
|