- More options how to send test emails. - Fixed problems with pausing a campaign (#593) - Started rework of transactional sender of templates (#606), however this contains functionality regression at the moment because it does not interpret templates as HBS. It needs HBS option for templates as described in https://github.com/Mailtrain-org/mailtrain/issues/611#issuecomment-502345227 TODO: - detect sending errors connected to not able to contact the mailer and pause/retry campaing and queued sending - don't mark the recipients as BOUNCED - add FAILED campaign state and fall into it if sending to campaign consistently fails (i.e. the error with sending is not temporary) - if the same happends for queued email, delete the message
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const knex = require('./knex');
|
|
const interoperableErrors = require('../../shared/interoperable-errors');
|
|
const entitySettings = require('./entity-settings');
|
|
const shares = require('../models/shares');
|
|
|
|
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).forShare().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;
|