Preparation of merge with master
This commit is contained in:
parent
6648028270
commit
cd798b5af7
26 changed files with 607 additions and 285 deletions
|
@ -16,7 +16,7 @@ const sendConfigurations = require('./send-configurations');
|
|||
const triggers = require('./triggers');
|
||||
|
||||
const allowedKeysCommon = ['name', 'description', 'list', 'segment', 'namespace',
|
||||
'send_configuration', 'from_name_override', 'from_email_override', 'reply_to_override', 'subject_override', 'data', 'click_tracking_disabled', 'open_tracking_disabled'];
|
||||
'send_configuration', 'from_name_override', 'from_email_override', 'reply_to_override', 'subject_override', 'data', 'click_tracking_disabled', 'open_tracking_disabled', 'unsubscribe_url'];
|
||||
|
||||
const allowedKeysCreate = new Set(['type', 'source', ...allowedKeysCommon]);
|
||||
const allowedKeysUpdate = new Set([...allowedKeysCommon]);
|
||||
|
|
|
@ -49,6 +49,11 @@ async function _validateAndPreprocess(tx, listId, entity, isCreate) {
|
|||
enforce(entity.type >= ImportType.MIN && entity.type <= ImportType.MAX, 'Invalid import type');
|
||||
|
||||
entity.settings = entity.settings || {};
|
||||
|
||||
if (entity.type === ImportType.CSV_FILE) {
|
||||
entity.settings.csv = entity.settings.csv || {};
|
||||
enforce(entity.settings.csv.delimiter.trim(), 'CSV delimiter must not be empty');
|
||||
}
|
||||
}
|
||||
|
||||
async function create(context, listId, entity, files) {
|
||||
|
@ -68,10 +73,11 @@ async function create(context, listId, entity, files) {
|
|||
|
||||
entity.settings.csv = {
|
||||
originalname: csvFile.originalname,
|
||||
filename: csvFile.filename
|
||||
filename: csvFile.filename,
|
||||
delimiter: entity.settings.csv.delimiter
|
||||
};
|
||||
|
||||
entity.status = ImportStatus.NOT_READY;
|
||||
entity.status = ImportStatus.PREP_SCHEDULED;
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,6 +157,7 @@ async function removeAllByListIdTx(tx, context, listId) {
|
|||
|
||||
// This is to handle circular dependency with segments.js
|
||||
module.exports = {
|
||||
filesDir,
|
||||
hash,
|
||||
getById,
|
||||
listDTAjax,
|
||||
|
|
|
@ -98,11 +98,12 @@ async function create(context, entity) {
|
|||
await knex.schema.raw('CREATE TABLE `subscription__' + id + '` (\n' +
|
||||
' `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n' +
|
||||
' `cid` varchar(255) CHARACTER SET ascii NOT NULL,\n' +
|
||||
' `email` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT \'\',\n' +
|
||||
' `email` varchar(255) CHARACTER SET utf8 NOT NULL,\n' +
|
||||
' `hash_email` varchar(255) CHARACTER SET ascii NOT NULL,\n' +
|
||||
' `source_email` int(10) unsigned,\n' + // This references imports if the source is an import, 0 means some import in version 1, NULL if the source is via subscription or edit of the subscription
|
||||
' `opt_in_ip` varchar(100) DEFAULT NULL,\n' +
|
||||
' `opt_in_country` varchar(2) DEFAULT NULL,\n' +
|
||||
' `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL,\n' +
|
||||
' `imported` int(11) unsigned DEFAULT NULL,\n' +
|
||||
' `status` tinyint(4) unsigned NOT NULL DEFAULT \'1\',\n' +
|
||||
' `is_test` tinyint(4) unsigned NOT NULL DEFAULT \'0\',\n' +
|
||||
' `status_change` timestamp NULL DEFAULT NULL,\n' +
|
||||
|
|
|
@ -10,7 +10,7 @@ const namespaceHelpers = require('../lib/namespace-helpers');
|
|||
const {MailerType, getSystemSendConfigurationId} = require('../shared/send-configurations');
|
||||
const contextHelpers = require('../lib/context-helpers');
|
||||
|
||||
const allowedKeys = new Set(['name', 'description', 'from_email', 'from_email_overridable', 'from_name', 'from_name_overridable', 'reply_to', 'reply_to_overridable', 'subject', 'subject_overridable', 'verp_hostname', 'mailer_type', 'mailer_settings', 'namespace']);
|
||||
const allowedKeys = new Set(['name', 'description', 'from_email', 'from_email_overridable', 'from_name', 'from_name_overridable', 'reply_to', 'reply_to_overridable', 'subject', 'subject_overridable', 'x_mailer', 'verp_hostname', 'mailer_type', 'mailer_settings', 'namespace']);
|
||||
|
||||
const allowedMailerTypes = new Set(Object.values(MailerType));
|
||||
|
||||
|
|
|
@ -425,6 +425,32 @@ async function _validateAndPreprocess(tx, listId, groupedFieldsMap, entity, meta
|
|||
}
|
||||
}
|
||||
|
||||
function updateSourcesAndHash(subscription, source, groupedFieldsMap) {
|
||||
if ('email' in subscription) {
|
||||
subscription.hash_email = crypto.createHash('sha512').update(subscription.email).digest("base64");
|
||||
subscription.source_email = source;
|
||||
}
|
||||
|
||||
for (const fldKey in groupedFieldsMap) {
|
||||
const fld = groupedFieldsMap[fldKey];
|
||||
|
||||
const fieldType = fields.getFieldType(fld.type);
|
||||
if (fieldType.grouped) {
|
||||
for (const optionKey in fld.groupedOptions) {
|
||||
const option = fld.groupedOptions[optionKey];
|
||||
|
||||
if (option.column in subscription) {
|
||||
subscription['source_' + option.column] = source;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fldKey in subscription) {
|
||||
subscription['source_' + fldKey] = source;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function _update(tx, listId, existing, filteredEntity) {
|
||||
if ('status' in filteredEntity) {
|
||||
if (existing.status !== filteredEntity.status) {
|
||||
|
@ -464,7 +490,7 @@ async function _create(tx, listId, filteredEntity) {
|
|||
If it is unsubscribed and meta.updateOfUnsubscribedAllowed, the existing subscription is changed based on the provided data.
|
||||
If meta.updateAllowed is true, it updates even an active subscription.
|
||||
*/
|
||||
async function create(context, listId, entity, meta /* meta is provided when called from /confirm/subscribe/:cid */) {
|
||||
async function create(context, listId, entity, source, meta /* meta is provided when called from /confirm/subscribe/:cid */) {
|
||||
return await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'manageSubscriptions');
|
||||
|
||||
|
@ -478,6 +504,8 @@ async function create(context, listId, entity, meta /* meta is provided when cal
|
|||
|
||||
ungroupSubscription(groupedFieldsMap, filteredEntity);
|
||||
|
||||
updateSourcesAndHash(filteredEntity, source, groupedFieldsMap);
|
||||
|
||||
filteredEntity.opt_in_ip = meta && meta.ip;
|
||||
filteredEntity.opt_in_country = meta && meta.country;
|
||||
filteredEntity.imported = meta && !!meta.imported;
|
||||
|
@ -498,7 +526,7 @@ async function create(context, listId, entity, meta /* meta is provided when cal
|
|||
});
|
||||
}
|
||||
|
||||
async function updateWithConsistencyCheck(context, listId, entity) {
|
||||
async function updateWithConsistencyCheck(context, listId, entity, source) {
|
||||
await knex.transaction(async tx => {
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'manageSubscriptions');
|
||||
|
||||
|
@ -523,6 +551,8 @@ async function updateWithConsistencyCheck(context, listId, entity) {
|
|||
|
||||
ungroupSubscription(groupedFieldsMap, filteredEntity);
|
||||
|
||||
updateSourcesAndHash(filteredEntity, source, groupedFieldsMap);
|
||||
|
||||
await _update(tx, listId, existing, filteredEntity);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue