WiP on mailers

This commit is contained in:
Tomas Bures 2018-04-29 18:13:40 +02:00
parent e97415c237
commit a4ee1534cc
46 changed files with 1263 additions and 529 deletions

View file

@ -3,7 +3,7 @@
const knex = require('../lib/knex');
const dtHelpers = require('../lib/dt-helpers');
const shares = require('./shares');
const tools = require('../lib/tools-async');
const tools = require('../lib/tools');
async function listDTAjax(context, params) {
shares.enforceGlobalPermission(context, 'manageBlacklist');

View file

@ -8,6 +8,7 @@ const interoperableErrors = require('../shared/interoperable-errors');
const shares = require('./shares');
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', 'subject', 'subject_overridable', 'verp_hostname', 'mailer_type', 'mailer_settings', 'namespace']);
@ -92,6 +93,9 @@ async function updateWithConsistencyCheck(context, entity) {
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'sendConfiguration', entityId: entity.id });
});
// FIXME - recreate respective mailer, notify senders to recreate the mailer
}
async function remove(context, id) {
@ -102,10 +106,16 @@ async function remove(context, id) {
await knex.transaction(async tx => {
await shares.enforceEntityPermissionTx(tx, context, 'sendConfiguration', id, 'delete');
// FIXME - delete send configuration assignment in campaigns
await tx('lists').update({send_configuration: null}).where('send_configuration', id);
await tx('send_configurations').where('id', id).del();
});
}
async function getSystemSendConfiguration() {
return await getById(contextHelpers.getAdminContext(), getSystemSendConfigurationId());
}
module.exports = {
MailerType,
@ -114,5 +124,6 @@ module.exports = {
getById,
create,
updateWithConsistencyCheck,
remove
remove,
getSystemSendConfiguration
};

View file

@ -51,6 +51,8 @@ async function set(context, data) {
}
}
}
// FIXME - recreate mailers, notify senders to recreate the mailers
}
module.exports = {

View file

@ -7,10 +7,10 @@ const { enforce, filterObject } = require('../lib/helpers');
const interoperableErrors = require('../shared/interoperable-errors');
const passwordValidator = require('../shared/password-validator')();
const dtHelpers = require('../lib/dt-helpers');
const tools = require('../lib/tools-async');
const tools = require('../lib/tools');
const crypto = require('crypto');
const settings = require('./settings');
const urllib = require('url');
const {getTrustedUrl} = require('../lib/urls');
const _ = require('../lib/translate')._;
const bluebird = require('bluebird');
@ -19,8 +19,7 @@ const bcrypt = require('bcrypt-nodejs');
const bcryptHash = bluebird.promisify(bcrypt.hash);
const bcryptCompare = bluebird.promisify(bcrypt.compare);
const mailer = require('../lib/mailer');
const mailerSendMail = bluebird.promisify(mailer.sendMail);
const mailers = require('../lib/mailers');
const passport = require('../lib/passport');
@ -301,9 +300,10 @@ async function sendPasswordReset(usernameOrEmail) {
reset_expire: new Date(Date.now() + 60 * 60 * 1000)
});
const { serviceUrl, adminEmail } = await settings.get(['serviceUrl', 'adminEmail']);
const { adminEmail } = await settings.get(contextHelpers.getAdminContext(), ['adminEmail']);
await mailerSendMail({
const mailer = await mailers.getOrCreateMailer();
await mailer.sendMail({
from: {
address: adminEmail
},
@ -318,7 +318,7 @@ async function sendPasswordReset(usernameOrEmail) {
title: 'Mailtrain',
username: user.username,
name: user.name,
confirmUrl: urllib.resolve(serviceUrl, `/account/reset/${encodeURIComponent(user.username)}/${encodeURIComponent(resetToken)}`)
confirmUrl: getTrustedUrl(`/account/reset/${encodeURIComponent(user.username)}/${encodeURIComponent(resetToken)}`)
}
});
}