Merge branch 'master' of github.com:Mailtrain-org/mailtrain into access
Conflicts: package.json
This commit is contained in:
commit
f776170854
16 changed files with 395 additions and 172 deletions
|
|
@ -43,9 +43,9 @@ if (config.redis && config.redis.enabled) {
|
|||
return setImmediate(() => callback());
|
||||
}
|
||||
module.exports.redis.multi().
|
||||
lpush('mailtrain:cache:' + key, stringifyDate.stringify(value)).
|
||||
expire('mailtrain:cache:' + key, 24 * 3600).
|
||||
exec(err => callback(err));
|
||||
lpush('mailtrain:cache:' + key, stringifyDate.stringify(value)).
|
||||
expire('mailtrain:cache:' + key, 24 * 3600).
|
||||
exec(err => callback(err));
|
||||
};
|
||||
|
||||
module.exports.getFromCache = (key, callback) => {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ const path = require('path');
|
|||
|
||||
function nameToFileName(name) {
|
||||
return name.
|
||||
trim().
|
||||
toLowerCase().
|
||||
replace(/[ .+/]/g, '-').
|
||||
replace(/[^a-z0-9\-_]/gi, '').
|
||||
replace(/--*/g, '-');
|
||||
trim().
|
||||
toLowerCase().
|
||||
replace(/[ .+/]/g, '-').
|
||||
replace(/[^a-z0-9\-_]/gi, '').
|
||||
replace(/--*/g, '-');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ function addCustomField(listId, name, defaultValue, type, group, groupTemplate,
|
|||
}
|
||||
|
||||
if (module.exports.grouped.indexOf(type) < 0) {
|
||||
column = ('custom_' + slugify(name, '_') + '_' + shortid.generate()).toLowerCase().replace(/[^a-z0-9\_]/g, '');
|
||||
column = ('custom_' + slugify(name, '_') + '_' + shortid.generate()).toLowerCase().replace(/[^a-z0-9_]/g, '');
|
||||
}
|
||||
|
||||
let query = 'INSERT INTO custom_fields (`list`, `name`, `key`,`default_value`, `type`, `group`, `group_template`, `column`, `visible`) VALUES(?,?,?,?,?,?,?,?,?)';
|
||||
|
|
@ -398,6 +398,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
// ignore missing values
|
||||
return;
|
||||
}
|
||||
/* eslint-disable indent */
|
||||
switch (field.type) {
|
||||
case 'text':
|
||||
case 'website':
|
||||
|
|
@ -413,7 +414,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
visible: !!field.visible,
|
||||
mergeTag: field.key,
|
||||
mergeValue: (valueList[field.column] || '').toString().trim() || field.defaultValue,
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|\-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
};
|
||||
row.push(item);
|
||||
break;
|
||||
|
|
@ -443,7 +444,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
visible: !!field.visible,
|
||||
mergeTag: field.key,
|
||||
mergeValue: value || field.defaultValue,
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|\-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
};
|
||||
row.push(item);
|
||||
break;
|
||||
|
|
@ -459,7 +460,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
visible: !!field.visible,
|
||||
mergeTag: field.key,
|
||||
mergeValue: (Number(valueList[field.column]) || Number(field.defaultValue) || 0).toString(),
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|\-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
};
|
||||
row.push(item);
|
||||
break;
|
||||
|
|
@ -476,7 +477,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
key: 'group-g' + field.id,
|
||||
mergeTag: field.key,
|
||||
mergeValue: field.defaultValue,
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|\-)([a-z])/g, (m, c) => c.toUpperCase())]: true,
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|-)([a-z])/g, (m, c) => c.toUpperCase())]: true,
|
||||
groupTemplate: field.groupTemplate,
|
||||
options: (field.options || []).map(subField => {
|
||||
if (onlyExisting && subField.column && !valueList.hasOwnProperty(subField.column)) {
|
||||
|
|
@ -507,7 +508,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
case 'date-us':
|
||||
case 'birthday-us':
|
||||
{
|
||||
let isUs = /\-us$/.test(field.type);
|
||||
let isUs = /-us$/.test(field.type);
|
||||
let isYear = field.type.indexOf('date-') === 0;
|
||||
let value = valueList[field.column];
|
||||
let day, month, year;
|
||||
|
|
@ -568,12 +569,13 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
|
|||
visible: !!field.visible,
|
||||
mergeTag: field.key,
|
||||
mergeValue: (useDate ? value : formatted) || field.defaultValue,
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|\-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
['type' + (field.type || '').toString().trim().replace(/(?:^|-)([a-z])/g, (m, c) => c.toUpperCase())]: true
|
||||
};
|
||||
row.push(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* eslint-enable indent */
|
||||
});
|
||||
|
||||
return row;
|
||||
|
|
|
|||
|
|
@ -414,7 +414,7 @@ module.exports.update = (listId, cid, updates, allowEmail, callback) => {
|
|||
}
|
||||
});
|
||||
|
||||
fields.getValues(fields.getRow(fieldList, updates, true, true), true).forEach(field => {
|
||||
fields.getValues(fields.getRow(fieldList, updates, true, true, true), true).forEach(field => {
|
||||
keys.push(field.key);
|
||||
values.push(field.value);
|
||||
});
|
||||
|
|
@ -495,7 +495,7 @@ module.exports.changeStatus = (listId, id, campaignId, status, callback) => {
|
|||
}
|
||||
|
||||
// status change is not related to a campaign or it marks message as bounced etc.
|
||||
if (!campaignId || status !== Status.SUBSCRIBED) {
|
||||
if (!campaignId || status !== Status.SUBSCRIBED && status !== Status.UNSUBSCRIBED) {
|
||||
return connection.commit(err => {
|
||||
if (err) {
|
||||
return helpers.rollbackAndReleaseConnection(connection, () => callback(err));
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ function sendMail(list, email, template, subject, relativeUrls, mailOpts, subscr
|
|||
}
|
||||
|
||||
if (!mailOpts.ignoreDisableConfirmations && configItems.disableConfirmations) {
|
||||
return;
|
||||
return callback();
|
||||
}
|
||||
|
||||
const data = {
|
||||
|
|
@ -110,7 +110,22 @@ function sendMail(list, email, template, subject, relativeUrls, mailOpts, subscr
|
|||
data[relativeUrlKey] = urllib.resolve(configItems.serviceUrl, relativeUrls[relativeUrlKey]);
|
||||
}
|
||||
|
||||
function sendMail(html, text) {
|
||||
let text = {
|
||||
template: 'subscription/mail-' + template + '-text.hbs'
|
||||
};
|
||||
|
||||
let html = {
|
||||
template: 'subscription/mail-' + template + '-html.mjml.hbs',
|
||||
layout: 'subscription/layout.mjml.hbs',
|
||||
type: 'mjml'
|
||||
};
|
||||
|
||||
helpers.injectCustomFormTemplates(list.defaultForm, { text, html }, (err, tmpl) => {
|
||||
if (!err && tmpl) {
|
||||
text = tmpl.text || text;
|
||||
html = tmpl.html || html;
|
||||
}
|
||||
|
||||
mailer.sendMail({
|
||||
from: {
|
||||
name: configItems.defaultFrom,
|
||||
|
|
@ -131,27 +146,10 @@ function sendMail(list, email, template, subject, relativeUrls, mailOpts, subscr
|
|||
log.error('Subscription', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let text = {
|
||||
template: 'subscription/mail-' + template + '-text.hbs'
|
||||
};
|
||||
callback();
|
||||
|
||||
let html = {
|
||||
template: 'subscription/mail-' + template + '-html.mjml.hbs',
|
||||
layout: 'subscription/layout.mjml.hbs',
|
||||
type: 'mjml'
|
||||
};
|
||||
|
||||
helpers.injectCustomFormTemplates(list.defaultForm, { text, html }, (err, tmpl) => {
|
||||
if (err) {
|
||||
return sendMail(html, text);
|
||||
}
|
||||
|
||||
sendMail(tmpl.html, tmpl.text);
|
||||
});
|
||||
|
||||
return callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
20
lib/tools.js
20
lib/tools.js
|
|
@ -35,12 +35,12 @@ module.exports = {
|
|||
|
||||
function toDbKey(key) {
|
||||
return key.
|
||||
replace(/[^a-z0-9\-_]/gi, '').
|
||||
replace(/\-+/g, '_').
|
||||
replace(/[A-Z]/g, c => '_' + c.toLowerCase()).
|
||||
replace(/^_+|_+$/g, '').
|
||||
replace(/_+/g, '_').
|
||||
trim();
|
||||
replace(/[^a-z0-9\-_]/gi, '').
|
||||
replace(/-+/g, '_').
|
||||
replace(/[A-Z]/g, c => '_' + c.toLowerCase()).
|
||||
replace(/^_+|_+$/g, '').
|
||||
replace(/_+/g, '_').
|
||||
trim();
|
||||
}
|
||||
|
||||
function fromDbKey(key) {
|
||||
|
|
@ -50,7 +50,7 @@ function fromDbKey(key) {
|
|||
prefix = '_';
|
||||
|
||||
}
|
||||
return prefix + key.replace(/[_\-]([a-z])/g, (m, c) => c.toUpperCase());
|
||||
return prefix + key.replace(/[_-]([a-z])/g, (m, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
function convertKeys(obj, options) {
|
||||
|
|
@ -71,9 +71,9 @@ function convertKeys(obj, options) {
|
|||
|
||||
function queryParams(obj) {
|
||||
return Object.keys(obj).
|
||||
filter(key => key !== '_csrf').
|
||||
map(key => encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])).
|
||||
join('&');
|
||||
filter(key => key !== '_csrf').
|
||||
map(key => encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])).
|
||||
join('&');
|
||||
}
|
||||
|
||||
function createSlug(table, name, callback) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue