diff --git a/CHANGES b/CHANGES index 038e12fa1..4f185baf4 100644 --- a/CHANGES +++ b/CHANGES @@ -2397,4 +2397,5 @@ * Fix LE account key re-use issue in DO 1-click image * mail: add non-tls ports for recvmail addon * backups: fix issue where mail backups where not cleaned up +* notifications: fix automatic app update notifications diff --git a/src/apps.js b/src/apps.js index d90e57cfc..0f44ca820 100644 --- a/src/apps.js +++ b/src/apps.js @@ -141,7 +141,6 @@ exports = module.exports = { const appstore = require('./appstore.js'), appTaskManager = require('./apptaskmanager.js'), assert = require('assert'), - AuditSource = require('./auditsource.js'), backups = require('./backups.js'), BoxError = require('./boxerror.js'), constants = require('./constants.js'), @@ -1036,7 +1035,13 @@ function mailboxNameForLocation(location, manifest) { return 'noreply.app'; } -async function onTaskFinished(appId, installationState, taskId, error) { +async function onTaskFinished(error, appId, installationState, taskId, auditSource) { + assert(!error || typeof error === 'object'); + assert.strictEqual(typeof appId, 'string'); + assert.strictEqual(typeof installationState, 'string'); + assert.strictEqual(typeof taskId, 'string'); + assert.strictEqual(typeof auditSource, 'object'); + const success = !error; const errorMessage = error?.message || null; @@ -1046,25 +1051,26 @@ async function onTaskFinished(appId, installationState, taskId, error) { switch (installationState) { case exports.ISTATE_PENDING_DATA_DIR_MIGRATION: - if (success) await safe(services.rebuildService('sftp', AuditSource.APPTASK), { debug }); + if (success) await safe(services.rebuildService('sftp', auditSource), { debug }); break; case exports.ISTATE_PENDING_UPDATE: { const fromManifest = success ? task.args[1].updateConfig.manifest : app.manifest; const toManifest = success ? app.manifest : task.args[1].updateConfig.manifest; - await eventlog.add(eventlog.ACTION_APP_UPDATE_FINISH, AuditSource.APPTASK, { app, toManifest, fromManifest, success, errorMessage }); + await eventlog.add(eventlog.ACTION_APP_UPDATE_FINISH, auditSource, { app, toManifest, fromManifest, success, errorMessage }); break; } case exports.ISTATE_PENDING_BACKUP: - await eventlog.add(eventlog.ACTION_APP_BACKUP_FINISH, AuditSource.APPTASK, { app, success, errorMessage, backupId: task.result }); + await eventlog.add(eventlog.ACTION_APP_BACKUP_FINISH, auditSource, { app, success, errorMessage, backupId: task.result }); break; } } -async function scheduleTask(appId, installationState, taskId) { +async function scheduleTask(appId, installationState, taskId, auditSource) { assert.strictEqual(typeof appId, 'string'); assert.strictEqual(typeof installationState, 'string'); assert.strictEqual(typeof taskId, 'string'); + assert.strictEqual(typeof auditSource, 'object'); const backupConfig = await settings.getBackupConfig(); @@ -1093,7 +1099,7 @@ async function scheduleTask(appId, installationState, taskId) { await safe(update(appId, { taskId: null }), { debug }); } - await safe(onTaskFinished(appId, installationState, taskId, error), { debug }); // ignore error + await safe(onTaskFinished(error, appId, installationState, taskId, auditSource), { debug }); // ignore error }); } @@ -1115,7 +1121,7 @@ async function addTask(appId, installationState, task, auditSource) { if (updateError && updateError.reason === BoxError.NOT_FOUND) throw new BoxError(BoxError.BAD_STATE, 'Another task is scheduled for this app'); // could be because app went away OR a taskId exists if (updateError) throw updateError; - if (scheduleNow) await safe(scheduleTask(appId, installationState, taskId), { debug }); // ignore error + if (scheduleNow) await safe(scheduleTask(appId, installationState, taskId, auditSource), { debug }); // ignore error return taskId; } @@ -2455,7 +2461,7 @@ async function schedulePendingTasks(auditSource) { debug(`schedulePendingTasks: schedule task for ${app.fqdn} ${app.id}: state=${app.installationState},taskId=${app.taskId}`); - await safe(scheduleTask(app.id, app.installationState, app.taskId), { debug }); // ignore error + await safe(scheduleTask(app.id, app.installationState, app.taskId, auditSource), { debug }); // ignore error } }