Send test functionality for templates and campaigns
This commit is contained in:
parent
7e52000219
commit
2c73c536b7
22 changed files with 719 additions and 69 deletions
|
@ -254,6 +254,7 @@ async function getByIdTx(tx, context, id, withPermissions = true, content = Cont
|
|||
} else if (content === Content.ONLY_SOURCE_CUSTOM) {
|
||||
entity = {
|
||||
id: entity.id,
|
||||
send_configuration: entity.send_configuration,
|
||||
|
||||
data: {
|
||||
sourceCustom: entity.data.sourceCustom
|
||||
|
@ -502,13 +503,13 @@ function getMessageCid(campaignCid, listCid, subscriptionCid) {
|
|||
}
|
||||
|
||||
async function getMessageByCid(messageCid) {
|
||||
const messageCid = messageCid.split('.');
|
||||
const messageCidElems = messageCid.split('.');
|
||||
|
||||
if (messageCid.length !== 3) {
|
||||
if (messageCidElems.length !== 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [campaignCid, listCid, subscriptionCid] = messageCid;
|
||||
const [campaignCid, listCid, subscriptionCid] = messageCidElems;
|
||||
|
||||
await knex.transaction(async tx => {
|
||||
const list = await tx('lists').where('cid', listCid).select('id');
|
||||
|
|
|
@ -334,7 +334,7 @@ async function listGroupedTx(tx, listId) {
|
|||
|
||||
async function listGrouped(context, listId) {
|
||||
return await knex.transaction(async tx => {
|
||||
// It may seem odd why there is not 'manageFields' here. But it's just a result of strictly apply the "need-to-know" principle. Simply, at this point this function is needed only in managing subscriptions.
|
||||
// It may seem odd why there is not 'viewFields' here. Simply, at this point this function is needed only in managing subscriptions.
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, ['manageSubscriptions']);
|
||||
return await listGroupedTx(tx, listId);
|
||||
});
|
||||
|
|
|
@ -34,6 +34,18 @@ async function listDTAjax(context, params) {
|
|||
);
|
||||
}
|
||||
|
||||
async function listWithSendPermissionDTAjax(context, params) {
|
||||
return await dtHelpers.ajaxListWithPermissions(
|
||||
context,
|
||||
[{ entityTypeId: 'sendConfiguration', requiredOperations: ['sendWithoutOverrides', 'sendWithAllowedOverrides', 'sendWithAnyOverrides'] }],
|
||||
params,
|
||||
builder => builder
|
||||
.from('send_configurations')
|
||||
.innerJoin('namespaces', 'namespaces.id', 'send_configurations.namespace'),
|
||||
['send_configurations.id', 'send_configurations.name', 'send_configurations.cid', 'send_configurations.description', 'send_configurations.mailer_type', 'send_configurations.created', 'namespaces.name']
|
||||
);
|
||||
}
|
||||
|
||||
async function _getByTx(tx, context, key, id, withPermissions, withPrivateData) {
|
||||
let entity;
|
||||
|
||||
|
@ -164,6 +176,7 @@ async function getSystemSendConfiguration() {
|
|||
module.exports.MailerType = MailerType;
|
||||
module.exports.hash = hash;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listWithSendPermissionDTAjax = listWithSendPermissionDTAjax;
|
||||
module.exports.getByIdTx = getByIdTx;
|
||||
module.exports.getById = getById;
|
||||
module.exports.getByCid = getByCid;
|
||||
|
|
|
@ -14,6 +14,7 @@ const moment = require('moment');
|
|||
const { formatDate, formatBirthday } = require('../shared/date');
|
||||
const crypto = require('crypto');
|
||||
const campaigns = require('./campaigns');
|
||||
const lists = require('./lists');
|
||||
|
||||
const allowedKeysBase = new Set(['email', 'tz', 'is_test', 'status']);
|
||||
|
||||
|
@ -340,6 +341,33 @@ async function listDTAjax(context, listId, segmentId, params) {
|
|||
});
|
||||
}
|
||||
|
||||
async function listTestUsersDTAjax(context, listCid, params) {
|
||||
return await knex.transaction(async tx => {
|
||||
const list = await lists.getByCidTx(tx, context, listCid);
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', list.id, 'viewSubscriptions');
|
||||
|
||||
const listTable = getSubscriptionTableName(list.id);
|
||||
|
||||
const columns = [
|
||||
listTable + '.id',
|
||||
listTable + '.cid',
|
||||
listTable + '.email',
|
||||
listTable + '.status',
|
||||
listTable + '.created'
|
||||
];
|
||||
|
||||
return await dtHelpers.ajaxListTx(
|
||||
tx,
|
||||
params,
|
||||
builder => builder
|
||||
.from(listTable)
|
||||
.where('is_test', true),
|
||||
columns,
|
||||
{}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function list(context, listId, grouped = true, offset, limit) {
|
||||
return await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'viewSubscriptions');
|
||||
|
@ -714,10 +742,10 @@ async function getListsWithEmail(context, email) {
|
|||
// FIXME - this methods is rather suboptimal if there are many lists. It quite needs permission caching in shares.js
|
||||
|
||||
return await knex.transaction(async tx => {
|
||||
const lists = await tx('lists').select(['id', 'name']);
|
||||
const lsts = await tx('lists').select(['id', 'name']);
|
||||
const result = [];
|
||||
|
||||
for (const list of lists) {
|
||||
for (const list of lsts) {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', list.id, 'viewSubscriptions');
|
||||
const entity = await tx(getSubscriptionTableName(list.id)).where('email', email).first();
|
||||
if (entity) {
|
||||
|
@ -737,6 +765,7 @@ module.exports.getByCid = getByCid;
|
|||
module.exports.getByEmail = getByEmail;
|
||||
module.exports.list = list;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listTestUsersDTAjax = listTestUsersDTAjax;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
module.exports.create = create;
|
||||
module.exports.getGroupedFieldsMap = getGroupedFieldsMap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue