Work on sending campaigns. Campaign status page half-way done, but does not work yet.
This commit is contained in:
parent
67d7129f7b
commit
d1fa4f4211
66 changed files with 1653 additions and 525 deletions
|
@ -69,11 +69,9 @@ async function serverValidate(context, data) {
|
|||
return result;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
listDTAjax,
|
||||
add,
|
||||
remove,
|
||||
search,
|
||||
isBlacklisted,
|
||||
serverValidate
|
||||
};
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.add = add;
|
||||
module.exports.remove = remove;
|
||||
module.exports.search = search;
|
||||
module.exports.isBlacklisted = isBlacklisted;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
|
|
|
@ -10,10 +10,13 @@ const shares = require('./shares');
|
|||
const namespaceHelpers = require('../lib/namespace-helpers');
|
||||
const files = require('./files');
|
||||
const templates = require('./templates');
|
||||
const { CampaignSource, CampaignType, getSendConfigurationPermissionRequiredForSend} = require('../shared/campaigns');
|
||||
const segments = require('./segments');
|
||||
const { CampaignStatus, CampaignSource, CampaignType, getSendConfigurationPermissionRequiredForSend} = require('../shared/campaigns');
|
||||
const sendConfigurations = require('./send-configurations');
|
||||
const triggers = require('./triggers');
|
||||
const {SubscriptionStatus} = require('../shared/lists');
|
||||
const subscriptions = require('./subscriptions');
|
||||
const segments = require('./segments');
|
||||
const senders = require('../lib/senders');
|
||||
|
||||
const allowedKeysCommon = ['name', 'description', 'segment', 'namespace',
|
||||
'send_configuration', 'from_name_override', 'from_email_override', 'reply_to_override', 'subject_override', 'data', 'click_tracking_disabled', 'open_tracking_disabled', 'unsubscribe_url'];
|
||||
|
@ -25,9 +28,11 @@ const Content = {
|
|||
ALL: 0,
|
||||
WITHOUT_SOURCE_CUSTOM: 1,
|
||||
ONLY_SOURCE_CUSTOM: 2,
|
||||
RSS_ENTRY: 3
|
||||
RSS_ENTRY: 3,
|
||||
SETTINGS_WITH_STATS: 4
|
||||
};
|
||||
|
||||
|
||||
function hash(entity, content) {
|
||||
let filteredEntity;
|
||||
|
||||
|
@ -88,6 +93,67 @@ async function listOthersWhoseListsAreIncludedDTAjax(context, campaignId, listId
|
|||
);
|
||||
}
|
||||
|
||||
async function listTestUsersDTAjax(context, campaignId, params) {
|
||||
return await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', campaignId, 'view');
|
||||
|
||||
const subscriptionsQueries = [];
|
||||
const cpgLists = await tx('campaign_lists').where('campaign', campaignId);
|
||||
|
||||
for (const cpgList of cpgLists) {
|
||||
const addSegmentQuery = cpgList.segment ? await segments.getQueryGeneratorTx(tx, cpgList.list, cpgList.segment) : () => {
|
||||
};
|
||||
const subsTable = subscriptions.getSubscriptionTableName(cpgList.list);
|
||||
|
||||
subscriptionsQueries.push(function () {
|
||||
this.from(subsTable)
|
||||
.where(subsTable + '.status', SubscriptionStatus.SUBSCRIBED)
|
||||
.where(subsTable + '.is_test', true)
|
||||
.where(function() {
|
||||
addSegmentQuery(this);
|
||||
})
|
||||
.select([subsTable + '.email', knex.raw('? AS campaign_list_id', [cpgList.id]), knex.raw('? AS list', [cpgList.list]), knex.raw('? AS segment', [cpgList.segment])]);
|
||||
});
|
||||
}
|
||||
|
||||
if (subscriptionsQueries.length > 0) {
|
||||
return await dtHelpers.ajaxListWithPermissions(
|
||||
context,
|
||||
[{ entityTypeId: 'list', requiredOperations: ['viewSubscriptions'] }],
|
||||
params,
|
||||
builder => {
|
||||
let ret;
|
||||
if (subscriptionsQueries.length > 1) {
|
||||
ret = builder.unionAll(subscriptionsQueries, true)
|
||||
.as('test_subscriptions');
|
||||
} else {
|
||||
ret = builder.from(function () { subscriptionsQueries[0].apply(this); this.as('test_subscriptions'); })
|
||||
.as('test_subscriptions');
|
||||
}
|
||||
|
||||
ret = ret
|
||||
.innerJoin('lists', 'test_subscriptions.list', 'lists.id')
|
||||
.innerJoin('segments', 'test_subscriptions.segment', 'segments.id')
|
||||
.innerJoin('namespaces', 'lists.namespace', 'namespaces.id');
|
||||
|
||||
return ret;
|
||||
},
|
||||
['test_subscriptions.campaign_list_id', 'test_subscriptions.email', 'test_subscriptions.list', 'test_subscriptions.segment', 'lists.cid', 'lists.name', 'segments.name', 'namespaces.name']
|
||||
);
|
||||
|
||||
} else {
|
||||
const result = {
|
||||
draw: params.draw,
|
||||
recordsTotal: 0,
|
||||
recordsFiltered: 0,
|
||||
data: []
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function rawGetByIdTx(tx, id) {
|
||||
const entity = await tx('campaigns').where('campaigns.id', id)
|
||||
.innerJoin('campaign_lists', 'campaigns.id', 'campaign_lists.campaign')
|
||||
|
@ -121,7 +187,27 @@ async function getByIdTx(tx, context, id, withPermissions = true, content = Cont
|
|||
|
||||
let entity = await rawGetByIdTx(tx, id);
|
||||
|
||||
if (content === Content.WITHOUT_SOURCE_CUSTOM) {
|
||||
if (content === Content.ALL || content === Content.RSS_ENTRY) {
|
||||
// Return everything
|
||||
|
||||
} else if (content === Content.SETTINGS_WITH_STATS) {
|
||||
delete entity.data.sourceCustom;
|
||||
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', id, 'viewStats');
|
||||
|
||||
const unsentQryGen = await getSubscribersQueryGeneratorTx(tx, id, true);
|
||||
if (unsentQryGen) {
|
||||
const res = await unsentQryGen(tx).count('* AS subscriptionsToSend').first();
|
||||
entity.subscriptionsToSend = res.subscriptionsToSend;
|
||||
}
|
||||
|
||||
const totalQryGen = await getSubscribersQueryGeneratorTx(tx, id, false);
|
||||
if (totalQryGen) {
|
||||
const res = await totalQryGen(tx).count('* AS subscriptionsTotal').first();
|
||||
entity.subscriptionsTotal = res.subscriptionsTotal;
|
||||
}
|
||||
|
||||
} else if (content === Content.WITHOUT_SOURCE_CUSTOM) {
|
||||
delete entity.data.sourceCustom;
|
||||
|
||||
} else if (content === Content.ONLY_SOURCE_CUSTOM) {
|
||||
|
@ -251,37 +337,6 @@ async function _createTx(tx, context, entity, content) {
|
|||
|
||||
await tx('campaign_lists').insert(entity.lists.map(x => ({campaign: id, ...x})));
|
||||
|
||||
await knex.schema.raw('CREATE TABLE `campaign__' + id + '` (\n' +
|
||||
' `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n' +
|
||||
' `list` int(10) unsigned NOT NULL,\n' +
|
||||
' `segment` int(10) unsigned NOT NULL,\n' +
|
||||
' `subscription` int(10) unsigned NOT NULL,\n' +
|
||||
' `status` tinyint(4) unsigned NOT NULL DEFAULT \'0\',\n' +
|
||||
' `response` varchar(255) DEFAULT NULL,\n' +
|
||||
' `response_id` varchar(255) CHARACTER SET ascii DEFAULT NULL,\n' +
|
||||
' `updated` timestamp NULL DEFAULT NULL,\n' +
|
||||
' `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n' +
|
||||
' PRIMARY KEY (`id`),\n' +
|
||||
' UNIQUE KEY `list` (`list`,`segment`,`subscription`),\n' +
|
||||
' KEY `created` (`created`),\n' +
|
||||
' KEY `response_id` (`response_id`),\n' +
|
||||
' KEY `status_index` (`status`),\n' +
|
||||
' KEY `subscription_index` (`subscription`)\n' +
|
||||
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n');
|
||||
|
||||
await knex.schema.raw('CREATE TABLE `campaign__tracker' + id + '` (\n' +
|
||||
' `list` int(10) unsigned NOT NULL,\n' +
|
||||
' `subscriber` int(10) unsigned NOT NULL,\n' +
|
||||
' `link` int(10) NOT NULL,\n' +
|
||||
' `ip` varchar(100) CHARACTER SET ascii DEFAULT NULL,\n' +
|
||||
' `device_type` varchar(50) DEFAULT NULL,\n' +
|
||||
' `country` varchar(2) CHARACTER SET ascii DEFAULT NULL,\n' +
|
||||
' `count` int(11) unsigned NOT NULL DEFAULT \'1\',\n' +
|
||||
' `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n' +
|
||||
' PRIMARY KEY (`list`,`subscriber`,`link`),\n' +
|
||||
' KEY `created_index` (`created`)\n' +
|
||||
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n');
|
||||
|
||||
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'campaign', entityId: id });
|
||||
|
||||
if (copyFilesFrom) {
|
||||
|
@ -351,13 +406,16 @@ async function remove(context, id) {
|
|||
await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', id, 'delete');
|
||||
|
||||
const existing = tx('campaigns').where('id', id);
|
||||
if (existing.status === CampaignStatus.SENDING) {
|
||||
return new interoperableErrors.InvalidStateError;
|
||||
}
|
||||
|
||||
// FIXME - deal with deletion of dependent entities (files)
|
||||
|
||||
await triggers.removeAllByCampaignIdTx(tx, context, id);
|
||||
|
||||
await tx('campaigns').where('id', id).del();
|
||||
await knex.schema.dropTableIfExists('campaign__' + id);
|
||||
await knex.schema.dropTableIfExists('campaign_tracker__' + id);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -371,18 +429,253 @@ async function enforceSendPermissionTx(tx, context, campaignId) {
|
|||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', campaignId, 'send');
|
||||
}
|
||||
|
||||
// This is to handle circular dependency with triggers.js
|
||||
Object.assign(module.exports, {
|
||||
Content,
|
||||
hash,
|
||||
listDTAjax,
|
||||
listWithContentDTAjax,
|
||||
listOthersWhoseListsAreIncludedDTAjax,
|
||||
getByIdTx,
|
||||
getById,
|
||||
create,
|
||||
createRssTx,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
enforceSendPermissionTx
|
||||
});
|
||||
|
||||
// Message API
|
||||
|
||||
function getMessageCid(campaignCid, listCid, subscriptionCid) {
|
||||
return [campaignCid, listCid, subscriptionCid].join('.')
|
||||
}
|
||||
|
||||
async function getMessageByCid(messageCid) {
|
||||
const messageCid = messageCid.split('.');
|
||||
|
||||
if (messageCid.length !== 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [campaignCid, listCid, subscriptionCid] = messageCid;
|
||||
|
||||
await knex.transaction(async tx => {
|
||||
const list = await tx('lists').where('cid', listCid).select('id');
|
||||
const subscrTblName = subscriptions.getSubscriptionTableName(list.id);
|
||||
|
||||
const message = await tx('campaign_messages')
|
||||
.innerJoin('campaigns', 'campaign_messages.campaign', 'campaigns.id')
|
||||
.innerJoin(subscrTblName, subscrTblName + '.id', 'campaign_messages.subscription')
|
||||
.leftJoin('segments', 'segment.id', 'campaign_messages.segment') // This is just to make sure that the respective segment still exists or return null if it doesn't
|
||||
.leftJoin('send_configurations', 'send_configurations.id', 'campaign_messages.send_configuration') // This is just to make sure that the respective send_configuration still exists or return null if it doesn't
|
||||
.where(subscrTblName + '.cid', subscriptionCid)
|
||||
.where('campaigns.cid', campaignCid)
|
||||
.select([
|
||||
'campaign_messages.id', 'campaign_messages.campaign', 'campaign_messages.list', 'segments.id AS segment', 'campaign_messages.subscription',
|
||||
'send_configurations.id AS send_configuration', 'campaign_messages.status', 'campaign_messages.response', 'campaign_messages.response_id',
|
||||
'campaign_messages.updated', 'campaign_messages.created', 'send_configurations.verp_hostname AS verp_hostname'
|
||||
]);
|
||||
|
||||
if (message) {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', message.campaign, 'manageMessages');
|
||||
}
|
||||
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
async function getMessageByResponseId(responseId) {
|
||||
await knex.transaction(async tx => {
|
||||
const message = await tx('campaign_messages')
|
||||
.leftJoin('segments', 'segment.id', 'campaign_messages.segment') // This is just to make sure that the respective segment still exists or return null if it doesn't
|
||||
.leftJoin('send_configurations', 'send_configurations.id', 'campaign_messages.send_configuration') // This is just to make sure that the respective send_configuration still exists or return null if it doesn't
|
||||
.where('campaign_messages.response_id', responseId)
|
||||
.select([
|
||||
'campaign_messages.id', 'campaign_messages.campaign', 'campaign_messages.list', 'segments.id AS segment', 'campaign_messages.subscription',
|
||||
'send_configurations.id AS send_configuration', 'campaign_messages.status', 'campaign_messages.response', 'campaign_messages.response_id',
|
||||
'campaign_messages.updated', 'campaign_messages.created', 'send_configurations.verp_hostname AS verp_hostname'
|
||||
]);
|
||||
|
||||
if (message) {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', message.campaign, 'manageMessages');
|
||||
}
|
||||
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
const statusFieldMapping = {
|
||||
[SubscriptionStatus.UNSUBSCRIBED]: 'unsubscribed',
|
||||
[SubscriptionStatus.BOUNCED]: 'bounced',
|
||||
[SubscriptionStatus.COMPLAINED]: 'complained'
|
||||
};
|
||||
|
||||
async function _changeStatusByMessageTx(tx, context, message, subscriptionStatus) {
|
||||
enforce(subscriptionStatus !== SubscriptionStatus.SUBSCRIBED);
|
||||
|
||||
if (message.status === SubscriptionStatus.SUBSCRIBED) {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', message.campaign, 'manageMessages');
|
||||
|
||||
if (!subscriptionStatus in statusFieldMapping) {
|
||||
throw new Error('Unrecognized message status');
|
||||
}
|
||||
|
||||
const statusField = statusFieldMapping[subscriptionStatus];
|
||||
|
||||
if (message.status === SubscriptionStatus.SUBSCRIBED) {
|
||||
await tx('campaigns').increment(statusField, 1).where('id', message.campaign);
|
||||
}
|
||||
|
||||
await tx('campaign_messages')
|
||||
.where('id', message.id)
|
||||
.update({
|
||||
status: subscriptionStatus,
|
||||
updated: knex.fn.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function changeStatusByCampaignCidAndSubscriptionIdTx(tx, context, campaignCid, listId, subscriptionId, subscriptionStatus) {
|
||||
const campaign = await tx('campaigns').where('cid', campaignCid);
|
||||
const message = await tx('campaign_messages')
|
||||
.innerJoin('campaigns', 'campaign_messages.campaign', 'campaigns.id')
|
||||
.where('campaigns.cid', campaignCid)
|
||||
.where({subscription: subscriptionId, list: listId});
|
||||
|
||||
if (!message) {
|
||||
throw new Error('Invalid campaign.')
|
||||
}
|
||||
|
||||
await _changeStatusByMessageTx(tx, context, message, subscriptionStatus);
|
||||
}
|
||||
|
||||
async function changeStatusByMessage(context, message, subscriptionStatus, updateSubscription) {
|
||||
await knex.transaction(async tx => {
|
||||
if (updateSubscription) {
|
||||
await subscriptions.changeStatusTx(tx, context, message.list, message.subscription, subscriptionStatus);
|
||||
}
|
||||
|
||||
await _changeStatusByMessageTx(tx, context, message, subscriptionStatus);
|
||||
});
|
||||
}
|
||||
|
||||
async function getSubscribersQueryGeneratorTx(tx, campaignId, onlyUnsent, batchSize) {
|
||||
const subscriptionsQueries = [];
|
||||
const cpgLists = await tx('campaign_lists').where('campaign', campaignId);
|
||||
|
||||
for (const cpgList of cpgLists) {
|
||||
const addSegmentQuery = cpgList.segment ? await segments.getQueryGeneratorTx(tx, cpgList.list, cpgList.segment) : () => {};
|
||||
const subsTable = subscriptions.getSubscriptionTableName(cpgList.list);
|
||||
|
||||
subscriptionsQueries.push(function() {
|
||||
this.from(subsTable)
|
||||
.leftJoin('campaign_messages', 'campaign_messages.subscription', subsTable + '.id')
|
||||
.where('campaign_messages.campaign', cpgList.campaign)
|
||||
.where('campaign_messages.list', cpgList.list)
|
||||
.where(subsTable + '.status', SubscriptionStatus.SUBSCRIBED)
|
||||
.where(function() {
|
||||
addSegmentQuery(this);
|
||||
})
|
||||
.select([subsTable + '.email', knex.raw('? AS campaign_list_id', [cpgList.id]), knex.raw('campaign_messages.id IS NOT NULL AS sent')]);
|
||||
});
|
||||
}
|
||||
|
||||
if (subscriptionsQueries.length > 0) {
|
||||
return knx => knx.from('campaign_lists')
|
||||
.where('campaign_lists.campaign', campaignId)
|
||||
.innerJoin(
|
||||
function () {
|
||||
let ret;
|
||||
if (subscriptionsQueries.length > 1) {
|
||||
ret = this.unionAll(subscriptionsQueries, true)
|
||||
.groupBy('email')
|
||||
.select(['email']).min('campaign_list_id AS campaign_list_id')
|
||||
.select(['sent']).max('sent AS sent');
|
||||
} else {
|
||||
ret = this.from(function () { subscriptionsQueries[0].apply(this); this.as('pending_subscriptions'); })
|
||||
.select(['email', 'sent', 'campaign_list_id']);
|
||||
}
|
||||
|
||||
ret = ret.where('sent', false)
|
||||
.as('pending_subscriptions');
|
||||
|
||||
if (batchSize) {
|
||||
ret = ret.limit(retrieveBatchSize);
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
'campaign_lists.id',
|
||||
'pending_subscriptions.campaign_list_id'
|
||||
);
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function _changeStatus(context, campaignId, permittedCurrentStates, newState, invalidStateMessage, scheduled = null) {
|
||||
await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', campaignId, 'send');
|
||||
|
||||
const entity = await tx('campaigns').where('id', campaignId).first();
|
||||
if (!entity) {
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
if (!permittedCurrentStates.includes(entity.status)) {
|
||||
throw new interoperableErrors.InvalidStateError(invalidStateMessage);
|
||||
}
|
||||
|
||||
await tx('campaigns').where('id', campaignId).update({
|
||||
status: newState,
|
||||
scheduled
|
||||
});
|
||||
});
|
||||
|
||||
senders.scheduleCheck();
|
||||
}
|
||||
|
||||
|
||||
async function start(context, campaignId, startAt) {
|
||||
await _changeStatus(context, campaignId, [CampaignStatus.IDLE, CampaignStatus.PAUSED], CampaignStatus.SCHEDULED, 'Cannot start campaign until it is in IDLE or PAUSED state', startAt);
|
||||
}
|
||||
|
||||
async function stop(context, campaignId) {
|
||||
await _changeStatus(context, campaignId, [CampaignStatus.SCHEDULED], CampaignStatus.PAUSED, 'Cannot stop campaign until it is in SCHEDULED state');
|
||||
}
|
||||
|
||||
async function reset(context, campaignId) {
|
||||
await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'campaign', campaignId, 'send');
|
||||
|
||||
const entity = await tx('campaigns').where('id', campaignId).first();
|
||||
if (!entity) {
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
if (entity.status !== CampaignStatus.FINISHED && entity.status !== CampaignStatus.PAUSED) {
|
||||
throw new interoperableErrors.InvalidStateError('Cannot reset campaign until it is FINISHED or PAUSED state');
|
||||
}
|
||||
|
||||
await tx('campaigns').where('id', campaignId).update({
|
||||
status: CampaignStatus.IDLE
|
||||
});
|
||||
|
||||
await tx('campaign_messages').where('campaign', campaignId).del();
|
||||
await tx('campaign_links').where('campaign', campaignId).del();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.Content = Content;
|
||||
module.exports.hash = hash;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listWithContentDTAjax = listWithContentDTAjax;
|
||||
module.exports.listOthersWhoseListsAreIncludedDTAjax = listOthersWhoseListsAreIncludedDTAjax;
|
||||
module.exports.listTestUsersDTAjax = listTestUsersDTAjax;
|
||||
module.exports.getByIdTx = getByIdTx;
|
||||
module.exports.getById = getById;
|
||||
module.exports.create = create;
|
||||
module.exports.createRssTx = createRssTx;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.enforceSendPermissionTx = enforceSendPermissionTx;
|
||||
|
||||
module.exports.getMessageCid = getMessageCid;
|
||||
module.exports.getMessageByCid = getMessageByCid;
|
||||
module.exports.getMessageByResponseId = getMessageByResponseId;
|
||||
|
||||
module.exports.changeStatusByCampaignCidAndSubscriptionIdTx = changeStatusByCampaignCidAndSubscriptionIdTx;
|
||||
module.exports.changeStatusByMessage = changeStatusByMessage;
|
||||
|
||||
module.exports.getSubscribersQueryGeneratorTx = getSubscribersQueryGeneratorTx;
|
||||
|
||||
module.exports.start = start;
|
||||
module.exports.stop = stop;
|
||||
module.exports.reset = reset;
|
|
@ -45,7 +45,5 @@ async function takeConfirmation(cid) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addConfirmation,
|
||||
takeConfirmation
|
||||
};
|
||||
module.exports.addConfirmation = addConfirmation;
|
||||
module.exports.takeConfirmation = takeConfirmation;
|
||||
|
|
|
@ -724,26 +724,23 @@ function fromImport(listId, flds, data) { // assumes ungrouped subscription and
|
|||
return _fromText(listId, data, flds, true, 'column', false);
|
||||
}
|
||||
|
||||
// This is to handle circular dependency with segments.js
|
||||
Object.assign(module.exports, {
|
||||
Cardinality,
|
||||
getFieldType,
|
||||
hash,
|
||||
getById,
|
||||
list,
|
||||
listTx,
|
||||
listGrouped,
|
||||
listGroupedTx,
|
||||
listByOrderListTx,
|
||||
listDTAjax,
|
||||
listGroupedDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
removeAllByListIdTx,
|
||||
serverValidate,
|
||||
forHbs,
|
||||
fromPost,
|
||||
fromAPI,
|
||||
fromImport
|
||||
});
|
||||
module.exports.Cardinality = Cardinality;
|
||||
module.exports.getFieldType = getFieldType;
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.list = list;
|
||||
module.exports.listTx = listTx;
|
||||
module.exports.listGrouped = listGrouped;
|
||||
module.exports.listGroupedTx = listGroupedTx;
|
||||
module.exports.listByOrderListTx = listByOrderListTx;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listGroupedDTAjax = listGroupedDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeAllByListIdTx = removeAllByListIdTx;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
module.exports.forHbs = forHbs;
|
||||
module.exports.fromPost = fromPost;
|
||||
module.exports.fromAPI = fromAPI;
|
||||
module.exports.fromImport = fromImport;
|
||||
|
|
|
@ -302,18 +302,16 @@ async function copyAllTx(tx, context, fromType, fromSubType, fromEntityId, toTyp
|
|||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
filesDir,
|
||||
listDTAjax,
|
||||
list,
|
||||
getFileById,
|
||||
getFileByFilename,
|
||||
getFileByUrl,
|
||||
getFileByOriginalName,
|
||||
createFiles,
|
||||
removeFile,
|
||||
getFileUrl,
|
||||
getFilePath,
|
||||
copyAllTx,
|
||||
ReplacementBehavior
|
||||
};
|
||||
module.exports.filesDir = filesDir;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.list = list;
|
||||
module.exports.getFileById = getFileById;
|
||||
module.exports.getFileByFilename = getFileByFilename;
|
||||
module.exports.getFileByUrl = getFileByUrl;
|
||||
module.exports.getFileByOriginalName = getFileByOriginalName;
|
||||
module.exports.createFiles = createFiles;
|
||||
module.exports.removeFile = removeFile;
|
||||
module.exports.getFileUrl = getFileUrl;
|
||||
module.exports.getFilePath = getFilePath;
|
||||
module.exports.copyAllTx = copyAllTx;
|
||||
module.exports.ReplacementBehavior = ReplacementBehavior;
|
||||
|
|
|
@ -265,13 +265,11 @@ function checkForMjmlErrors(form) {
|
|||
return errors;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
listDTAjax,
|
||||
hash,
|
||||
getById,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
getDefaultCustomFormValues,
|
||||
serverValidate
|
||||
};
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.getDefaultCustomFormValues = getDefaultCustomFormValues;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
|
|
|
@ -62,8 +62,6 @@ async function listFailedDTAjax(context, listId, importId, importRunId, params)
|
|||
|
||||
|
||||
|
||||
module.exports = {
|
||||
getById,
|
||||
listDTAjax,
|
||||
listFailedDTAjax
|
||||
};
|
||||
module.exports.getById = getById;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listFailedDTAjax = listFailedDTAjax;
|
||||
|
|
|
@ -238,16 +238,13 @@ async function stop(context, listId, id) {
|
|||
}
|
||||
|
||||
|
||||
// This is to handle circular dependency with segments.js
|
||||
module.exports = {
|
||||
filesDir,
|
||||
hash,
|
||||
getById,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
removeAllByListIdTx,
|
||||
start,
|
||||
stop
|
||||
};
|
||||
module.exports.filesDir = filesDir;
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeAllByListIdTx = removeAllByListIdTx;
|
||||
module.exports.start = start;
|
||||
module.exports.stop = stop;
|
||||
|
|
|
@ -45,6 +45,22 @@ async function listDTAjax(context, params) {
|
|||
);
|
||||
}
|
||||
|
||||
async function listWithSegmentByCampaignDTAjax(context, campaignId, params) {
|
||||
return await dtHelpers.ajaxListWithPermissions(
|
||||
context,
|
||||
[{ entityTypeId: 'list', requiredOperations: ['view'] }],
|
||||
params,
|
||||
builder => builder
|
||||
.from('lists')
|
||||
.innerJoin('campaign_lists', 'campaign_lists.list', 'lists.id')
|
||||
.leftJoin('segments', 'segments.id', 'campaign_lists.segment')
|
||||
.innerJoin('namespaces', 'namespaces.id', 'lists.namespace')
|
||||
.where('campaign_lists.campaign', campaignId)
|
||||
.orderBy('campaign_lists.id', 'asc'),
|
||||
['lists.id', 'lists.name', 'lists.cid', 'namespaces.name', 'segments.name']
|
||||
);
|
||||
}
|
||||
|
||||
async function _getByIdTx(tx, context, id) {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', id, 'view');
|
||||
const entity = await tx('lists').where('id', id).first();
|
||||
|
@ -192,16 +208,15 @@ async function getMergeTags(context, id) {
|
|||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
UnsubscriptionMode,
|
||||
hash,
|
||||
listDTAjax,
|
||||
getById,
|
||||
getByIdWithListFields,
|
||||
getByCid,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
removeFormFromAllTx,
|
||||
getMergeTags
|
||||
};
|
||||
module.exports.UnsubscriptionMode = UnsubscriptionMode;
|
||||
module.exports.hash = hash;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listWithSegmentByCampaignDTAjax = listWithSegmentByCampaignDTAjax;
|
||||
module.exports.getById = getById;
|
||||
module.exports.getByIdWithListFields = getByIdWithListFields;
|
||||
module.exports.getByCid = getByCid;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeFormFromAllTx = removeFormFromAllTx;
|
||||
module.exports.getMergeTags = getMergeTags;
|
||||
|
|
|
@ -97,11 +97,9 @@ async function remove(context, id) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hash,
|
||||
getById,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove
|
||||
};
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
|
|
|
@ -187,11 +187,9 @@ async function remove(context, id) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hash,
|
||||
listTree,
|
||||
getById,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove
|
||||
};
|
||||
module.exports.hash = hash;
|
||||
module.exports.listTree = listTree;
|
||||
module.exports.getById = getById;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
|
|
|
@ -91,12 +91,10 @@ async function getUserFieldsById(context, id) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hash,
|
||||
getById,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
getUserFieldsById
|
||||
};
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.getUserFieldsById = getUserFieldsById;
|
||||
|
|
|
@ -147,13 +147,13 @@ async function bulkChangeState(oldState, newState) {
|
|||
|
||||
|
||||
const campaignFieldsMapping = {
|
||||
tracker_count: 'tracker.count',
|
||||
country: 'tracker.country',
|
||||
device_type: 'tracker.device_type',
|
||||
status: 'campaign.status',
|
||||
first_name: 'subscribers.first_name',
|
||||
last_name: 'subscribers.last_name',
|
||||
email: 'subscribers.email'
|
||||
tracker_count: 'campaign_links.count',
|
||||
country: 'campaign_links.country',
|
||||
device_type: 'campaign_links.device_type',
|
||||
status: 'campaign_messages.status',
|
||||
first_name: 'subscriptions.first_name',
|
||||
last_name: 'subscriptions.last_name',
|
||||
email: 'subscriptions.email'
|
||||
};
|
||||
|
||||
async function getCampaignResults(context, campaign, select, extra) {
|
||||
|
@ -164,7 +164,7 @@ async function getCampaignResults(context, campaign, select, extra) {
|
|||
/* Dropdown and checkbox groups have field.column == null
|
||||
TODO - For the time being, we don't group options and we don't expand enums. We just provide it as it is in the DB. */
|
||||
if (fld.column) {
|
||||
fieldsMapping[fld.key.toLowerCase()] = 'subscribers.' + fld.column;
|
||||
fieldsMapping[fld.key.toLowerCase()] = 'subscriptions.' + fld.column;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,9 +180,11 @@ async function getCampaignResults(context, campaign, select, extra) {
|
|||
}
|
||||
}
|
||||
|
||||
let query = knex(`subscription__${campaign.list} AS subscribers`)
|
||||
.innerJoin(`campaign__${campaign.id} AS campaign`, 'subscribers.id', 'campaign.subscription')
|
||||
.leftJoin(`campaign_tracker__${campaign.id} AS tracker`, 'subscribers.id', 'tracker.subscriber')
|
||||
let query = knex(`subscription__${campaign.list} AS subscriptions`)
|
||||
.innerJoin('campaign_messages', 'subscriptions.id', 'campaign_messages.subscription')
|
||||
.leftJoin('campaign_links', 'subscriptions.id', 'campaign_links.subscription')
|
||||
.where('campaign_messages.list', campaign.list)
|
||||
.where('campaign_links.list', campaign.list)
|
||||
.select(selFields);
|
||||
|
||||
if (extra) {
|
||||
|
@ -194,17 +196,15 @@ async function getCampaignResults(context, campaign, select, extra) {
|
|||
|
||||
|
||||
|
||||
module.exports = {
|
||||
ReportState,
|
||||
hash,
|
||||
getByIdWithTemplate,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
removeAllByReportTemplateIdTx,
|
||||
updateFields,
|
||||
listByState,
|
||||
bulkChangeState,
|
||||
getCampaignResults,
|
||||
};
|
||||
module.exports.ReportState = ReportState;
|
||||
module.exports.hash = hash;
|
||||
module.exports.getByIdWithTemplate = getByIdWithTemplate;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeAllByReportTemplateIdTx = removeAllByReportTemplateIdTx;
|
||||
module.exports.updateFields = updateFields;
|
||||
module.exports.listByState = listByState;
|
||||
module.exports.bulkChangeState = bulkChangeState;
|
||||
module.exports.getCampaignResults = getCampaignResults;
|
||||
|
|
|
@ -408,16 +408,14 @@ async function getQueryGeneratorTx(tx, listId, id) {
|
|||
}
|
||||
|
||||
// This is to handle circular dependency with fields.js
|
||||
Object.assign(module.exports, {
|
||||
hash,
|
||||
listDTAjax,
|
||||
listIdName,
|
||||
getById,
|
||||
getByIdTx,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
removeAllByListIdTx,
|
||||
removeRulesByColumnTx,
|
||||
getQueryGeneratorTx
|
||||
});
|
||||
module.exports.hash = hash;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listIdName = listIdName;
|
||||
module.exports.getById = getById;
|
||||
module.exports.getByIdTx = getByIdTx;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeAllByListIdTx = removeAllByListIdTx;
|
||||
module.exports.removeRulesByColumnTx = removeRulesByColumnTx;
|
||||
module.exports.getQueryGeneratorTx = getQueryGeneratorTx;
|
||||
|
|
|
@ -132,14 +132,12 @@ async function getSystemSendConfiguration() {
|
|||
return await getById(contextHelpers.getAdminContext(), getSystemSendConfigurationId(), false);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
MailerType,
|
||||
hash,
|
||||
listDTAjax,
|
||||
getByIdTx,
|
||||
getById,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
getSystemSendConfiguration
|
||||
};
|
||||
module.exports.MailerType = MailerType;
|
||||
module.exports.hash = hash;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.getByIdTx = getByIdTx;
|
||||
module.exports.getById = getById;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.getSystemSendConfiguration = getSystemSendConfiguration;
|
||||
|
|
|
@ -55,9 +55,7 @@ async function set(context, data) {
|
|||
// FIXME - recreate mailers, notify senders to recreate the mailers
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hash,
|
||||
get,
|
||||
set
|
||||
};
|
||||
module.exports.hash = hash;
|
||||
module.exports.get = get;
|
||||
module.exports.set = set;
|
||||
|
||||
|
|
|
@ -614,25 +614,23 @@ async function getPermissionsTx(tx, context, entityTypeId, entityId) {
|
|||
return rows.map(x => x.operation);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
listByEntityDTAjax,
|
||||
listByUserDTAjax,
|
||||
listUnassignedUsersDTAjax,
|
||||
listRolesDTAjax,
|
||||
assign,
|
||||
rebuildPermissionsTx,
|
||||
rebuildPermissions,
|
||||
removeDefaultShares,
|
||||
enforceEntityPermission,
|
||||
enforceEntityPermissionTx,
|
||||
enforceTypePermission,
|
||||
enforceTypePermissionTx,
|
||||
checkEntityPermission,
|
||||
checkTypePermission,
|
||||
enforceGlobalPermission,
|
||||
checkGlobalPermission,
|
||||
throwPermissionDenied,
|
||||
regenerateRoleNamesTable,
|
||||
getGlobalPermissions,
|
||||
getPermissionsTx
|
||||
};
|
||||
module.exports.listByEntityDTAjax = listByEntityDTAjax;
|
||||
module.exports.listByUserDTAjax = listByUserDTAjax;
|
||||
module.exports.listUnassignedUsersDTAjax = listUnassignedUsersDTAjax;
|
||||
module.exports.listRolesDTAjax = listRolesDTAjax;
|
||||
module.exports.assign = assign;
|
||||
module.exports.rebuildPermissionsTx = rebuildPermissionsTx;
|
||||
module.exports.rebuildPermissions = rebuildPermissions;
|
||||
module.exports.removeDefaultShares = removeDefaultShares;
|
||||
module.exports.enforceEntityPermission = enforceEntityPermission;
|
||||
module.exports.enforceEntityPermissionTx = enforceEntityPermissionTx;
|
||||
module.exports.enforceTypePermission = enforceTypePermission;
|
||||
module.exports.enforceTypePermissionTx = enforceTypePermissionTx;
|
||||
module.exports.checkEntityPermission = checkEntityPermission;
|
||||
module.exports.checkTypePermission = checkTypePermission;
|
||||
module.exports.enforceGlobalPermission = enforceGlobalPermission;
|
||||
module.exports.checkGlobalPermission = checkGlobalPermission;
|
||||
module.exports.throwPermissionDenied = throwPermissionDenied;
|
||||
module.exports.regenerateRoleNamesTable = regenerateRoleNamesTable;
|
||||
module.exports.getGlobalPermissions = getGlobalPermissions;
|
||||
module.exports.getPermissionsTx = getPermissionsTx;
|
||||
|
|
|
@ -13,6 +13,7 @@ const { enforce, filterObject } = require('../lib/helpers');
|
|||
const moment = require('moment');
|
||||
const { formatDate, formatBirthday } = require('../shared/date');
|
||||
const crypto = require('crypto');
|
||||
const campaigns = require('./campaigns');
|
||||
|
||||
const allowedKeysBase = new Set(['email', 'tz', 'is_test', 'status']);
|
||||
|
||||
|
@ -79,10 +80,6 @@ function getSubscriptionTableName(listId) {
|
|||
return `subscription__${listId}`;
|
||||
}
|
||||
|
||||
function getCampaignTableName(campaignId) {
|
||||
return `campaign__${campaignId}`;
|
||||
}
|
||||
|
||||
async function getGroupedFieldsMap(tx, listId) {
|
||||
const groupedFields = await fields.listGroupedTx(tx, listId);
|
||||
const result = {};
|
||||
|
@ -596,58 +593,54 @@ async function removeByEmailAndGet(context, listId, email) {
|
|||
}
|
||||
|
||||
|
||||
async function _unsubscribeAndGetTx(tx, context, listId, existingSubscription, campaignCid) {
|
||||
async function _changeStatusTx(tx, context, listId, existing, newStatus) {
|
||||
enforce(newStatus !== SubscriptionStatus.SUBSCRIBED);
|
||||
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'manageSubscriptions');
|
||||
|
||||
if (!(existingSubscription && existingSubscription.status === SubscriptionStatus.SUBSCRIBED)) {
|
||||
await tx(getSubscriptionTableName(listId)).where('id', existing.id).update({
|
||||
status: newStatus
|
||||
});
|
||||
|
||||
if (existing.status === SubscriptionStatus.SUBSCRIBED) {
|
||||
await tx('lists').where('id', listId).decrement('subscribers', 1);
|
||||
}
|
||||
}
|
||||
|
||||
async function _unsubscribeExistingAndGetTx(tx, context, listId, existing) {
|
||||
if (!(existing && existing.status === SubscriptionStatus.SUBSCRIBED)) {
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
existingSubscription.status = SubscriptionStatus.UNSUBSCRIBED;
|
||||
await _changeStatusTx(tx, context, listId, existing, SubscriptionStatus.UNSUBSCRIBED);
|
||||
|
||||
await tx(getSubscriptionTableName(listId)).where('id', existingSubscription.id).update({
|
||||
status: SubscriptionStatus.UNSUBSCRIBED
|
||||
});
|
||||
existing.status = SubscriptionStatus.SUBSCRIBED;
|
||||
|
||||
await tx('lists').where('id', listId).decrement('subscribers', 1);
|
||||
|
||||
if (campaignCid) {
|
||||
const campaign = await tx('campaigns').where('cid', campaignCid);
|
||||
const subscriptionInCampaign = await tx(getCampaignTableName(campaign.id)).where({subscription: existingSubscription.id, list: listId});
|
||||
|
||||
if (!subscriptionInCampaign) {
|
||||
throw new Error('Invalid campaign.')
|
||||
}
|
||||
|
||||
if (subscriptionInCampaign.status === SubscriptionStatus.SUBSCRIBED) {
|
||||
await tx('campaigns').where('id', campaign.id).increment('unsubscribed', 1);
|
||||
await tx(getCampaignTableName(campaign.id)).where({subscription: existingSubscription.id, list: listId}).update({
|
||||
status: SubscriptionStatus.UNSUBSCRIBED
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return existingSubscription;
|
||||
return existing;
|
||||
}
|
||||
|
||||
|
||||
async function unsubscribeByIdAndGet(context, listId, subscriptionId) {
|
||||
return await knex.transaction(async tx => {
|
||||
const existing = await tx(getSubscriptionTableName(listId)).where('id', subscriptionId).first();
|
||||
return await _unsubscribeAndGetTx(tx, context, listId, existing);
|
||||
return await _unsubscribeExistingAndGetTx(tx, context, listId, existing);
|
||||
});
|
||||
}
|
||||
|
||||
async function unsubscribeByCidAndGet(context, listId, subscriptionCid, campaignCid) {
|
||||
return await knex.transaction(async tx => {
|
||||
const existing = await tx(getSubscriptionTableName(listId)).where('cid', subscriptionCid).first();
|
||||
return await _unsubscribeAndGetTx(tx, context, listId, existing, campaignCid);
|
||||
|
||||
if (campaignCid) {
|
||||
await campaigns.changeStatusByCampaignCidAndSubscriptionIdTx(tx, context, campaignCid, listId, existing.id, SubscriptionStatus.UNSUBSCRIBED);
|
||||
}
|
||||
|
||||
return await _unsubscribeExistingAndGetTx(tx, context, listId, existing);
|
||||
});
|
||||
}
|
||||
|
||||
async function unsubscribeByEmailAndGetTx(tx, context, listId, email) {
|
||||
const existing = await tx(getSubscriptionTableName(listId)).where('hash_email', hashEmail(email)).first();
|
||||
return await _unsubscribeAndGetTx(tx, context, listId, existing);
|
||||
return await _unsubscribeExistingAndGetTx(tx, context, listId, existing);
|
||||
}
|
||||
|
||||
async function unsubscribeByEmailAndGet(context, listId, email) {
|
||||
|
@ -656,6 +649,13 @@ async function unsubscribeByEmailAndGet(context, listId, email) {
|
|||
});
|
||||
}
|
||||
|
||||
async function changeStatusTx(tx, context, listId, subscriptionId, subscriptionStatus) {
|
||||
const existing = await tx(getSubscriptionTableName(listId)).where('id', subscriptionId).first();
|
||||
await _changeStatusTx(tx, context, listId, existing, subscriptionStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function updateAddressAndGet(context, listId, subscriptionId, emailNew) {
|
||||
return await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'manageSubscriptions');
|
||||
|
@ -722,25 +722,25 @@ async function getListsWithEmail(context, email) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hashByList,
|
||||
getById,
|
||||
getByCid,
|
||||
getByEmail,
|
||||
list,
|
||||
listDTAjax,
|
||||
serverValidate,
|
||||
create,
|
||||
getGroupedFieldsMap,
|
||||
createTxWithGroupedFieldsMap,
|
||||
updateWithConsistencyCheck,
|
||||
remove,
|
||||
removeByEmailAndGet,
|
||||
unsubscribeByCidAndGet,
|
||||
unsubscribeByIdAndGet,
|
||||
unsubscribeByEmailAndGet,
|
||||
unsubscribeByEmailAndGetTx,
|
||||
updateAddressAndGet,
|
||||
updateManaged,
|
||||
getListsWithEmail
|
||||
};
|
||||
module.exports.getSubscriptionTableName = getSubscriptionTableName;
|
||||
module.exports.hashByList = hashByList;
|
||||
module.exports.getById = getById;
|
||||
module.exports.getByCid = getByCid;
|
||||
module.exports.getByEmail = getByEmail;
|
||||
module.exports.list = list;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
module.exports.create = create;
|
||||
module.exports.getGroupedFieldsMap = getGroupedFieldsMap;
|
||||
module.exports.createTxWithGroupedFieldsMap = createTxWithGroupedFieldsMap;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeByEmailAndGet = removeByEmailAndGet;
|
||||
module.exports.unsubscribeByCidAndGet = unsubscribeByCidAndGet;
|
||||
module.exports.unsubscribeByIdAndGet = unsubscribeByIdAndGet;
|
||||
module.exports.unsubscribeByEmailAndGet = unsubscribeByEmailAndGet;
|
||||
module.exports.unsubscribeByEmailAndGetTx = unsubscribeByEmailAndGetTx;
|
||||
module.exports.updateAddressAndGet = updateAddressAndGet;
|
||||
module.exports.updateManaged = updateManaged;
|
||||
module.exports.getListsWithEmail = getListsWithEmail;
|
||||
module.exports.changeStatusTx = changeStatusTx;
|
|
@ -102,12 +102,10 @@ async function remove(context, id) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hash,
|
||||
getByIdTx,
|
||||
getById,
|
||||
listDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
remove
|
||||
};
|
||||
module.exports.hash = hash;
|
||||
module.exports.getByIdTx = getByIdTx;
|
||||
module.exports.getById = getById;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
|
|
|
@ -137,14 +137,12 @@ async function removeAllByCampaignIdTx(tx, context, campaignId) {
|
|||
|
||||
|
||||
// This is to handle circular dependency with campaigns.js
|
||||
Object.assign(module.exports, {
|
||||
hash,
|
||||
getById,
|
||||
listByCampaignDTAjax,
|
||||
listByListDTAjax,
|
||||
create,
|
||||
updateWithConsistencyCheck,
|
||||
removeTx,
|
||||
remove,
|
||||
removeAllByCampaignIdTx
|
||||
});
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.listByCampaignDTAjax = listByCampaignDTAjax;
|
||||
module.exports.listByListDTAjax = listByListDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.removeTx = removeTx;
|
||||
module.exports.remove = remove;
|
||||
module.exports.removeAllByCampaignIdTx = removeAllByCampaignIdTx;
|
||||
|
|
|
@ -418,24 +418,22 @@ async function getByRestrictedAccessToken(token) {
|
|||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
listDTAjax,
|
||||
remove,
|
||||
updateWithConsistencyCheck,
|
||||
create,
|
||||
hash,
|
||||
getById,
|
||||
serverValidate,
|
||||
getByAccessToken,
|
||||
getByUsername,
|
||||
getByUsernameIfPasswordMatch,
|
||||
getAccessToken,
|
||||
resetAccessToken,
|
||||
sendPasswordReset,
|
||||
isPasswordResetTokenValid,
|
||||
resetPassword,
|
||||
getByRestrictedAccessToken,
|
||||
getRestrictedAccessToken,
|
||||
refreshRestrictedAccessToken,
|
||||
registerRestrictedAccessTokenMethod
|
||||
};
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.remove = remove;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.create = create;
|
||||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.serverValidate = serverValidate;
|
||||
module.exports.getByAccessToken = getByAccessToken;
|
||||
module.exports.getByUsername = getByUsername;
|
||||
module.exports.getByUsernameIfPasswordMatch = getByUsernameIfPasswordMatch;
|
||||
module.exports.getAccessToken = getAccessToken;
|
||||
module.exports.resetAccessToken = resetAccessToken;
|
||||
module.exports.sendPasswordReset = sendPasswordReset;
|
||||
module.exports.isPasswordResetTokenValid = isPasswordResetTokenValid;
|
||||
module.exports.resetPassword = resetPassword;
|
||||
module.exports.getByRestrictedAccessToken = getByRestrictedAccessToken;
|
||||
module.exports.getRestrictedAccessToken = getRestrictedAccessToken;
|
||||
module.exports.refreshRestrictedAccessToken = refreshRestrictedAccessToken;
|
||||
module.exports.registerRestrictedAccessTokenMethod = registerRestrictedAccessTokenMethod;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue