rework notifications
notifications are now system level instead of user level. To clarify the use events/notifications/email: * eventlog - everything that is happenning on server * notifications - specific important events (alerts) * email - these are really urgent things that require immediate attention. this is for the case where an admin does not visit the dashboard often. can also be alerts like bad backup config or reboot required which are not events per-se. Notes on notifications * oom - notification only * appUpdated - notification only * cert renewal failure - only raise when < 10 days to go. also send email thereafter (todo). * Backup failure - only if last 5 backups failed (todo). * Box update - notification only. we anyway send newsletter. * box update available - we raise a notification. no email. * app update available - we already have update indicator on dashboard. so, no notification or email. Alerts: * backup config * disk space * mail status * reboot * box updated * ubuntu update required
This commit is contained in:
+3
-100
@@ -2,8 +2,6 @@
|
||||
|
||||
exports = module.exports = {
|
||||
passwordReset,
|
||||
boxUpdateAvailable,
|
||||
appUpdatesAvailable,
|
||||
|
||||
sendInvite,
|
||||
sendNewLoginLocation,
|
||||
@@ -11,14 +9,13 @@ exports = module.exports = {
|
||||
backupFailed,
|
||||
|
||||
certificateRenewalError,
|
||||
boxUpdateError,
|
||||
|
||||
sendTestMail,
|
||||
|
||||
_mailQueue: [] // accumulate mails in test mode
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
const assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
debug = require('debug')('box:mailer'),
|
||||
ejs = require('ejs'),
|
||||
@@ -27,13 +24,12 @@ var assert = require('assert'),
|
||||
path = require('path'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('./settings.js'),
|
||||
showdown = require('showdown'),
|
||||
translation = require('./translation.js'),
|
||||
smtpTransport = require('nodemailer-smtp-transport');
|
||||
|
||||
var NOOP_CALLBACK = function (error) { if (error) debug(error); };
|
||||
const NOOP_CALLBACK = function (error) { if (error) debug(error); };
|
||||
|
||||
var MAIL_TEMPLATES_DIR = path.join(__dirname, 'mail_templates');
|
||||
const MAIL_TEMPLATES_DIR = path.join(__dirname, 'mail_templates');
|
||||
|
||||
// This will collect the most common details required for notification emails
|
||||
function getMailConfig(callback) {
|
||||
@@ -215,81 +211,6 @@ function passwordReset(user) {
|
||||
});
|
||||
}
|
||||
|
||||
function boxUpdateAvailable(mailTo, updateInfo, callback) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof updateInfo, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
getMailConfig(function (error, mailConfig) {
|
||||
if (error) return debug('Error getting mail details:', error);
|
||||
|
||||
var converter = new showdown.Converter();
|
||||
|
||||
var templateData = {
|
||||
webadminUrl: settings.dashboardOrigin(),
|
||||
newBoxVersion: updateInfo.version,
|
||||
changelog: updateInfo.changelog,
|
||||
changelogHTML: updateInfo.changelog.map(function (e) { return converter.makeHtml(e); }),
|
||||
cloudronName: mailConfig.cloudronName,
|
||||
cloudronAvatarUrl: settings.dashboardOrigin() + '/api/v1/cloudron/avatar'
|
||||
};
|
||||
|
||||
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
||||
templateDataText.format = 'text';
|
||||
|
||||
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
||||
templateDataHTML.format = 'html';
|
||||
|
||||
var mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] Cloudron update available`,
|
||||
text: render('box_update_available.ejs', templateDataText),
|
||||
html: render('box_update_available.ejs', templateDataHTML)
|
||||
};
|
||||
|
||||
sendMail(mailOptions, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function appUpdatesAvailable(mailTo, apps, callback) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof apps, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
getMailConfig(function (error, mailConfig) {
|
||||
if (error) return debug('Error getting mail details:', error);
|
||||
|
||||
var converter = new showdown.Converter();
|
||||
apps.forEach(function (app) {
|
||||
app.changelogHTML = converter.makeHtml(app.updateInfo.manifest.changelog);
|
||||
});
|
||||
|
||||
var templateData = {
|
||||
webadminUrl: settings.dashboardOrigin(),
|
||||
apps: apps,
|
||||
cloudronName: mailConfig.cloudronName,
|
||||
cloudronAvatarUrl: settings.dashboardOrigin() + '/api/v1/cloudron/avatar'
|
||||
};
|
||||
|
||||
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
||||
templateDataText.format = 'text';
|
||||
|
||||
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
||||
templateDataHTML.format = 'html';
|
||||
|
||||
var mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] App update available`,
|
||||
text: render('app_updates_available.ejs', templateDataText),
|
||||
html: render('app_updates_available.ejs', templateDataHTML)
|
||||
};
|
||||
|
||||
sendMail(mailOptions, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function backupFailed(mailTo, errorMessage, logUrl) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
|
||||
@@ -326,24 +247,6 @@ function certificateRenewalError(mailTo, domain, message) {
|
||||
});
|
||||
}
|
||||
|
||||
function boxUpdateError(mailTo, message) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof message, 'string');
|
||||
|
||||
getMailConfig(function (error, mailConfig) {
|
||||
if (error) return debug('Error getting mail details:', error);
|
||||
|
||||
var mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: mailTo,
|
||||
subject: `[${mailConfig.cloudronName}] Cloudron update error`,
|
||||
text: render('box_update_error.ejs', { message: message, format: 'text' })
|
||||
};
|
||||
|
||||
sendMail(mailOptions);
|
||||
});
|
||||
}
|
||||
|
||||
function sendTestMail(domain, email, callback) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof email, 'string');
|
||||
|
||||
Reference in New Issue
Block a user