work in progress on segments

some cleanup of models - handling dependencies in delete
This commit is contained in:
Tomas Bures 2017-08-14 22:53:29 +02:00
parent b23529a75b
commit 0bfb30817b
29 changed files with 553 additions and 990 deletions

View file

@ -115,14 +115,16 @@ async function assign(context, entityTypeId, entityId, userId, role) {
await tx(entityType.permissionsTable).where({user: userId, entity: entityId}).del();
if (entityTypeId === 'namespace') {
await rebuildPermissions(tx, {userId});
await rebuildPermissionsTx(tx, {userId});
} else if (role) {
await rebuildPermissions(tx, { entityTypeId, entityId, userId });
await rebuildPermissionsTx(tx, { entityTypeId, entityId, userId });
}
});
}
async function _rebuildPermissions(tx, restriction) {
async function rebuildPermissionsTx(tx, restriction) {
restriction = restriction || {};
const namespaceEntityType = permissions.getEntityType('namespace');
// Collect entity types we care about
@ -358,16 +360,10 @@ async function _rebuildPermissions(tx, restriction) {
}
}
async function rebuildPermissions(tx, restriction) {
restriction = restriction || {};
if (tx) {
await _rebuildPermissions(tx, restriction);
} else {
await knex.transaction(async tx => {
await _rebuildPermissions(tx, restriction);
});
}
async function rebuildPermissions(restriction) {
await knex.transaction(async tx => {
await rebuildPermissionsTx(tx, restriction);
});
}
async function regenerateRoleNamesTable() {
@ -556,6 +552,7 @@ module.exports = {
listUnassignedUsersDTAjax,
listRolesDTAjax,
assign,
rebuildPermissionsTx,
rebuildPermissions,
removeDefaultShares,
enforceEntityPermission,