updates: only send email notifications when not auto-updating
fixes #749
This commit is contained in:
@@ -12,14 +12,10 @@ var apps = require('./apps.js'),
|
||||
appstore = require('./appstore.js'),
|
||||
assert = require('assert'),
|
||||
async = require('async'),
|
||||
constants = require('./constants.js'),
|
||||
debug = require('debug')('box:updatechecker'),
|
||||
mailer = require('./mailer.js'),
|
||||
notifications = require('./notifications.js'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('./settings.js'),
|
||||
users = require('./users.js');
|
||||
safe = require('safetydance');
|
||||
|
||||
function setUpdateInfo(state) {
|
||||
// appid -> update info { creationDate, manifest }
|
||||
@@ -44,55 +40,38 @@ function checkAppUpdates(options, callback) {
|
||||
let state = getUpdateInfo();
|
||||
let newState = { }; // create new state so that old app ids are removed
|
||||
|
||||
settings.getAutoupdatePattern(function (error, result) {
|
||||
var pendingNotifications = [];
|
||||
|
||||
apps.getAll(function (error, result) {
|
||||
if (error) return callback(error);
|
||||
const autoupdatesEnabled = (result !== constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
|
||||
var notificationPending = [];
|
||||
async.eachSeries(result, function (app, iteratorDone) {
|
||||
if (app.appStoreId === '') return iteratorDone(); // appStoreId can be '' for dev apps
|
||||
|
||||
apps.getAll(function (error, result) {
|
||||
if (error) return callback(error);
|
||||
appstore.getAppUpdate(app, options, function (error, updateInfo) {
|
||||
if (error) {
|
||||
debug('Error getting app update info for %s', app.id, error);
|
||||
return iteratorDone(); // continue to next
|
||||
}
|
||||
|
||||
async.eachSeries(result, function (app, iteratorDone) {
|
||||
if (app.appStoreId === '') return iteratorDone(); // appStoreId can be '' for dev apps
|
||||
if (!updateInfo) return iteratorDone(); // skip if no next version is found
|
||||
|
||||
appstore.getAppUpdate(app, options, function (error, updateInfo) {
|
||||
if (error) {
|
||||
debug('Error getting app update info for %s', app.id, error);
|
||||
return iteratorDone(); // continue to next
|
||||
}
|
||||
newState[app.id] = updateInfo;
|
||||
|
||||
if (!updateInfo) return iteratorDone(); // skip if no next version is found
|
||||
if (safe.query(state[app.id], 'manifest.version') === updateInfo.manifest.version) {
|
||||
debug(`Skipping app update notification of ${app.id} since user was already notified of ${updateInfo.manifest.version}`);
|
||||
return iteratorDone();
|
||||
}
|
||||
|
||||
newState[app.id] = updateInfo;
|
||||
|
||||
if (safe.query(state[app.id], 'manifest.version') === updateInfo.manifest.version) {
|
||||
debug(`Skipping app update notification of ${app.id} since user was already notified of ${updateInfo.manifest.version}`);
|
||||
return iteratorDone();
|
||||
}
|
||||
|
||||
const canAutoupdateApp = apps.canAutoupdateApp(app, updateInfo);
|
||||
if (autoupdatesEnabled && canAutoupdateApp) return iteratorDone();
|
||||
|
||||
debug(`Notifying of app update for ${app.id} from ${app.manifest.version} to ${updateInfo.manifest.version}`);
|
||||
notificationPending.push({ app, updateInfo });
|
||||
iteratorDone();
|
||||
});
|
||||
}, function () {
|
||||
if ('box' in state) newState.box = state.box; // preserve the latest box state information
|
||||
setUpdateInfo(newState);
|
||||
|
||||
if (notificationPending.length === 0) return callback();
|
||||
|
||||
users.getAdmins(function (error, admins) {
|
||||
if (error) {
|
||||
debug('checkAppUpdates: failed to get admins', error);
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.eachSeries(admins, (admin, done) => mailer.appUpdatesAvailable(admin.email, notificationPending, done), callback);
|
||||
});
|
||||
pendingNotifications.push({ app, updateInfo });
|
||||
iteratorDone();
|
||||
});
|
||||
}, function () {
|
||||
if ('box' in state) newState.box = state.box; // preserve the latest box state information
|
||||
|
||||
setUpdateInfo(newState);
|
||||
|
||||
notifications.appUpdatesAvailable(pendingNotifications, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -123,7 +102,7 @@ function checkBoxUpdates(options, callback) {
|
||||
state.box = updateInfo;
|
||||
setUpdateInfo(state);
|
||||
|
||||
callback();
|
||||
notifications.boxUpdateAvailable(updateInfo, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user