notifications: send backup fail only to owner

only superadmin has access to server and can adjust backup config
This commit is contained in:
Girish Ramakrishnan
2021-04-19 20:52:10 -07:00
parent 613da5fff9
commit 0c8e0c4715
3 changed files with 45 additions and 18 deletions

View File

@@ -17,7 +17,7 @@ exports = module.exports = {
ALERT_REBOOT: 'reboot',
ALERT_BOX_UPDATE: 'boxUpdate',
alert: alert,
alert,
// exported for testing
_add: add
@@ -113,6 +113,22 @@ function forEachAdmin(options, iterator, callback) {
});
}
function forEachSuperadmin(options, iterator, callback) {
assert(Array.isArray(options.skip));
assert.strictEqual(typeof iterator, 'function');
assert.strictEqual(typeof callback, 'function');
users.getSuperadmins(function (error, result) {
if (error && error.reason === BoxError.NOT_FOUND) return callback();
if (error) return callback(error);
// filter out users we want to skip (like the user who did the action or the user the action was performed on)
result = result.filter(function (r) { return options.skip.indexOf(r.id) === -1; });
async.each(result, iterator, callback);
});
}
function oomEvent(eventId, app, addon, containerId, event, callback) {
assert.strictEqual(typeof eventId, 'string');
assert.strictEqual(typeof app, 'object');
@@ -249,7 +265,7 @@ function backupFailed(eventId, taskId, errorMessage, callback) {
assert.strictEqual(typeof errorMessage, 'string');
assert.strictEqual(typeof callback, 'function');
forEachAdmin({ skip: [] }, function (admin, callback) {
forEachSuperadmin({ skip: [] }, function (admin, callback) {
mailer.backupFailed(admin.email, errorMessage, `${settings.adminOrigin()}/logs.html?taskId=${taskId}`);
add(admin.id, eventId, 'Backup failed', `Backup failed: ${errorMessage}. Logs are available [here](/logs.html?taskId=${taskId}).`, callback);
}, callback);