New project structure
Beta of extract.js for extracting english locale
This commit is contained in:
parent
e18d2b2f84
commit
2edbd67205
247 changed files with 6405 additions and 4237 deletions
58
server/lib/dependency-helpers.js
Normal file
58
server/lib/dependency-helpers.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
'use strict';
|
||||
|
||||
const knex = require('./knex');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
const entitySettings = require('./entity-settings');
|
||||
const shares = require('../models/shares');
|
||||
const { enforce } = require('./helpers');
|
||||
|
||||
const defaultNoOfDependenciesReported = 20;
|
||||
|
||||
async function ensureNoDependencies(tx, context, id, depSpecs) {
|
||||
|
||||
const deps = [];
|
||||
let andMore = false;
|
||||
|
||||
for (const depSpec of depSpecs) {
|
||||
const entityType = entitySettings.getEntityType(depSpec.entityTypeId);
|
||||
|
||||
let rows;
|
||||
|
||||
if (depSpec.query) {
|
||||
rows = await depSpec.query(tx).limit(defaultNoOfDependenciesReported + 1);
|
||||
} else if (depSpec.column) {
|
||||
rows = await tx(entityType.entitiesTable).where(depSpec.column, id).select(['id', 'name']).limit(defaultNoOfDependenciesReported + 1);
|
||||
} else if (depSpec.rows) {
|
||||
rows = await depSpec.rows(tx, defaultNoOfDependenciesReported + 1)
|
||||
}
|
||||
|
||||
for (const row of rows) {
|
||||
if (deps.length === defaultNoOfDependenciesReported) {
|
||||
andMore = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (await shares.checkEntityPermissionTx(tx, context, depSpec.entityTypeId, row.id, 'view')) {
|
||||
deps.push({
|
||||
entityTypeId: depSpec.entityTypeId,
|
||||
name: row.name,
|
||||
link: entityType.clientLink(row.id)
|
||||
});
|
||||
} else {
|
||||
deps.push({
|
||||
entityTypeId: depSpec.entityTypeId,
|
||||
id: row.id
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (deps.length > 0) {
|
||||
throw new interoperableErrors.DependencyPresentError('', {
|
||||
dependencies: deps,
|
||||
andMore
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.ensureNoDependencies = ensureNoDependencies;
|
Loading…
Add table
Add a link
Reference in a new issue