Some fixes so that the subscription forms work with the new mailer

This commit is contained in:
Tomas Bures 2018-05-20 20:27:35 +02:00
parent 446d75ce71
commit 1f5566ca9b
5 changed files with 22 additions and 9 deletions

View file

@ -65,11 +65,13 @@ hbs.registerPartials(__dirname + '/views/subscription/partials/');
* and the message is never displayed
*/
hbs.registerHelper('flash_messages', function () { // eslint-disable-line prefer-arrow-callback
console.log(this.flash);
if (typeof this.flash !== 'function') { // eslint-disable-line no-invalid-this
return '';
}
let messages = this.flash(); // eslint-disable-line no-invalid-this
console.log(messages);
let response = [];
// group messages by type
@ -185,9 +187,15 @@ function createApp(trusted) {
useWith404Fallback('/mailtrain', express.static(path.join(__dirname, 'client', 'dist')));
useWith404Fallback('/locales', express.static(path.join(__dirname, 'client', 'locales')));
/* FIXME - can we remove this???
// make sure flash messages are available
// Make sure flash messages are available
// Currently, flash messages are used only from routes/subscription.js
app.use((req, res, next) => {
res.locals.flash = req.flash.bind(req);
next();
});
/* FIXME - can we remove this???
app.use((req, res, next) => {
res.locals.flash = req.flash.bind(req);
res.locals.user = req.user;

View file

@ -35,9 +35,13 @@ Handlebars.registerHelper('translate', function (context, options) { // eslint-d
const transports = new Map();
async function getOrCreateMailer(sendConfiguration) {
async function getOrCreateMailer(sendConfigurationId) {
let sendConfiguration;
if (!sendConfiguration) {
sendConfiguration = sendConfigurations.getSystemSendConfiguration();
sendConfiguration = await sendConfigurations.getSystemSendConfiguration();
} else {
sendConfiguration = await sendConfigurations.getById(contextHelpers.getAdminContext(), sendConfigurationId, false);
}
const transport = transports.get(sendConfiguration.id) || await _createTransport(sendConfiguration);
@ -65,8 +69,8 @@ async function _sendMail(transport, mail, template) {
const preparedHtml = await tools.prepareHtml(mail.html);
if (prepareHtml) {
mail.html = prepareHtml;
if (preparedHtml) {
mail.html = preparedHtml;
}
const textRenderer = await tools.getTemplate(template.text);

View file

@ -67,7 +67,7 @@ async function mergeTemplateIntoLayout(template, layout) {
}
if (template.endsWith('.hbs')) {
template = readFile(template);
template = await readFile(template);
}
const source = layout.replace(/\{\{\{body\}\}\}/g, template);
@ -121,7 +121,7 @@ async function prepareHtml(html) {
FetchExternalResources: false, // disables resource loading over HTTP / filesystem
ProcessExternalResources: false // do not execute JS within script blocks
}
})
});
const head = win.document.querySelector('head');
let hasCharsetTag = false;

View file

@ -114,7 +114,7 @@ async function remove(context, id) {
}
async function getSystemSendConfiguration() {
return await getById(contextHelpers.getAdminContext(), getSystemSendConfigurationId());
return await getById(contextHelpers.getAdminContext(), getSystemSendConfigurationId(), false);
}
module.exports = {

View file

@ -185,6 +185,7 @@ async function _renderSubscribe(req, res, list, subscription) {
data.isWeb = true;
data.needsJsWarning = true;
data.flashMessages = await captureFlashMessages(res);
const result = htmlRenderer(data);