Merge remote-tracking branch 'upstream/master' into development

This commit is contained in:
Tomas Bures 2018-02-24 23:05:01 +01:00
commit 7750232716
18 changed files with 558 additions and 344 deletions

View file

@ -348,7 +348,7 @@ function addCustomField(listId, name, defaultValue, type, group, groupTemplate,
case 'date-eur':
case 'birthday-us':
case 'birthday-eur':
query = 'ALTER TABLE `subscription__' + listId + '` ADD COLUMN `' + column + '` TIMESTAMP NULL DEFAULT NULL';
query = 'ALTER TABLE `subscription__' + listId + '` ADD COLUMN `' + column + '` DATETIME NULL DEFAULT NULL';
indexQuery = 'CREATE INDEX ' + column + '_index ON `subscription__' + listId + '` (`column`);';
break;
default:
@ -469,6 +469,7 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
case 'radio':
case 'checkbox':
{
let hasSelectedOption = (field.options || []).some(subField => subField.column && valueList[subField.column]);
let item = {
id: field.id,
type: field.type,
@ -481,8 +482,15 @@ module.exports.getRow = (fieldList, values, useDate, showAll, onlyExisting) => {
groupTemplate: field.groupTemplate,
options: (field.options || []).map(subField => {
if (onlyExisting && subField.column && !valueList.hasOwnProperty(subField.column)) {
// ignore missing values
return false;
if (hasSelectedOption && field.type !== 'checkbox') {
// Set all radio or dropdown options if a selection for the group is present
} else if (field.type === 'checkbox' && values['originGroupG' + field.id] === 'webform') {
// Set all checkbox options if origin is webform (subscribe, manage, or admin edit) #333
// Atomic updates via API call or CSV import still possible
} else {
// ignore missing values
return false;
}
}
return {
type: subField.type,

View file

@ -4,6 +4,7 @@ let db = require('../db');
let tools = require('../tools');
let shortid = require('shortid');
let segments = require('./segments');
let subscriptions = require('./subscriptions');
let _ = require('../translate')._;
let tableHelpers = require('../table-helpers');
const UnsubscriptionMode = require('../../shared/lists').UnsubscriptionMode;
@ -56,6 +57,37 @@ module.exports.quicklist = callback => {
});
};
module.exports.getListsWithEmail = (email, callback) => {
db.getConnection((err, connection) => {
if (err) {
return callback(err);
}
connection.query('SELECT id, name FROM lists', (err, rows) => {
connection.release();
if (err) {
return callback(err);
}
let lists = (rows || []).map(tools.convertKeys);
const results = [];
lists.forEach((list, index, arr) => {
subscriptions.getByEmail(list.id, email, (err, sub) => {
if (err) {
return callback(err);
}
if (sub) {
results.push(list.id);
}
if (index === arr.length - 1) {
return callback(null, lists.filter(list => results.includes(list.id)));
}
});
});
});
});
};
module.exports.getByCid = (cid, callback) => {
resolveCid(cid, (err, id) => {
if (err) {

View file

@ -155,6 +155,9 @@ module.exports.insert = (listId, meta, subscriptionData, callback) => {
let entryId = existing ? existing.id : false;
meta.cid = existing ? rows[0].cid : meta.cid;
// meta.status may be 'undefined' or '0' when adding a subscription via API call or CSV import. In both cases meta.partial is 'true'.
// This must either update an existing subscription without changing its status or insert a new subscription with status SUBSCRIBED.
meta.status = meta.status || (existing ? existing.status : Status.SUBSCRIBED);
let statusChange = !existing || existing.status !== meta.status;
@ -618,7 +621,7 @@ module.exports.delete = (listId, cid, callback) => {
module.exports.createImport = (listId, type, path, size, delimiter, emailcheck, mapping, callback) => {
listId = Number(listId) || 0;
type = Number(type) || 1;
type = Number(type) || 0;
if (listId < 1) {
return callback(new Error('Missing List ID'));

View file

@ -61,15 +61,17 @@ module.exports.create = (template, callback) => {
let values = [name];
Object.keys(template).forEach(key => {
let value = template[key].trim();
let value = template[key];
key = tools.toDbKey(key);
if (!allowedKeys.includes(key)) {
return;
}
value = value.trim();
if (key === 'description') {
value = tools.purifyHTML(value);
}
if (allowedKeys.indexOf(key) >= 0) {
keys.push(key);
values.push(value);
}
keys.push(key);
values.push(value);
});
db.getConnection((err, connection) => {
@ -137,6 +139,17 @@ module.exports.update = (id, updates, callback) => {
});
};
module.exports.duplicate = (id, callback) => module.exports.get(id, (err, template) => {
if (err) {
return callback(err);
}
if (!template) {
return callback(new Error(_('Template does not exist')));
}
template.name = template.name + ' Copy';
return module.exports.create(template, callback);
});
module.exports.delete = (id, callback) => {
id = Number(id) || 0;