notifications: send email when manual platform update is required
This commit is contained in:
+20
-3
@@ -29,6 +29,7 @@ const TYPE_UPDATE_UBUNTU = 'ubuntuUpdate';
|
||||
const TYPE_BOX_UPDATE = 'boxUpdate';
|
||||
const TYPE_MANUAL_APP_UPDATE_NEEDED = 'manualAppUpdate';
|
||||
const TYPE_APP_AUTO_UPDATE_FAILED = 'appAutoUpdateFailed';
|
||||
const TYPE_MANUAL_UPDATE_REQUIRED = 'manualUpdateRequired';
|
||||
|
||||
const NOTIFICATION_FIELDS = [ 'id', 'eventId', 'type', 'title', 'message', 'creationTime', 'acknowledged', 'context' ];
|
||||
|
||||
@@ -298,15 +299,30 @@ async function lowDiskSpace(message) {
|
||||
}
|
||||
}
|
||||
|
||||
async function onPin(type, message) {
|
||||
async function boxManualUpdateRequired(version, changelogText) {
|
||||
assert.strictEqual(typeof version, 'string');
|
||||
assert.strictEqual(typeof changelogText, 'string');
|
||||
|
||||
const admins = await users.getAdmins();
|
||||
for (const admin of admins) {
|
||||
if (admin.notificationConfig.includes(TYPE_MANUAL_UPDATE_REQUIRED)) {
|
||||
await safe(mailer.boxManualUpdateRequired(admin.email, version, changelogText), { debug: log });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function onPin(type, message, options) {
|
||||
assert.strictEqual(typeof type, 'string'); // TYPE_
|
||||
assert.strictEqual(typeof message, 'string');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
|
||||
switch (type) {
|
||||
case TYPE_REBOOT:
|
||||
return await rebootRequired();
|
||||
case TYPE_DISK_SPACE:
|
||||
return await lowDiskSpace(message);
|
||||
case TYPE_BOX_UPDATE:
|
||||
return await boxManualUpdateRequired(options.context, message);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -320,7 +336,7 @@ async function pin(type, title, message, options) {
|
||||
|
||||
const result = await getByType(type, options.context || '');
|
||||
if (!result) {
|
||||
await onPin(type, message);
|
||||
await onPin(type, message, options);
|
||||
return await add(type, title, message, { eventId: null, context: options.context || '' });
|
||||
}
|
||||
|
||||
@@ -328,7 +344,7 @@ async function pin(type, title, message, options) {
|
||||
const isUpdateType = type === TYPE_BOX_UPDATE || type === TYPE_MANUAL_APP_UPDATE_NEEDED;
|
||||
const acknowledged = (isUpdateType && result.message === message) ? result.acknowledged : false;
|
||||
|
||||
if (result.acknowledged && !acknowledged) await onPin(type, message);
|
||||
if (result.acknowledged && !acknowledged) await onPin(type, message, options);
|
||||
|
||||
await update(result, { title, message, acknowledged, creationTime: new Date() });
|
||||
return result.id;
|
||||
@@ -412,6 +428,7 @@ export default {
|
||||
TYPE_BOX_UPDATE,
|
||||
TYPE_MANUAL_APP_UPDATE_NEEDED,
|
||||
TYPE_APP_AUTO_UPDATE_FAILED,
|
||||
TYPE_MANUAL_UPDATE_REQUIRED,
|
||||
TYPE_DOMAIN_CONFIG_CHECK_FAILED,
|
||||
pin,
|
||||
unpin,
|
||||
|
||||
Reference in New Issue
Block a user