Commit 5b62d634 authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

clear mailbox on update and restore

part of #669
parent 3fec599c
......@@ -524,14 +524,7 @@ function teardownAddons(app, addons, callback) {
debugApp(app, 'Tearing down addon %s with options %j', addon, addons[addon]);
KNOWN_ADDONS[addon].teardown(app, addons[addon], iteratorCallback);
}, function (error) {
if (error) return callback(error);
if (app.manifest.addons.sendmail || app.manifest.addons.recvmail) return callback();
// clear mailbox name if neither are used
appdb.update(app.id, { mailboxName: null, mailboxDomain: null }, callback);
});
}, callback);
}
function backupAddons(app, addons, callback) {
......
......@@ -1240,6 +1240,8 @@ function update(app, data, auditSource, callback) {
appId = app.id,
manifest = data.manifest;
let values = {};
if (app.runState === exports.RSTATE_STOPPED) return callback(new BoxError(BoxError.BAD_STATE, 'Stopped apps cannot be updated'));
let error = checkAppState(app, exports.ISTATE_PENDING_UPDATE);
......@@ -1289,9 +1291,16 @@ function update(app, data, auditSource, callback) {
updateConfig.memoryLimit = updateConfig.manifest.memoryLimit;
}
if (!hasMailAddon(manifest)) { // clear if the update removed addon
values.mailboxName = values.mailboxDomain = null;
} else if (!app.mailboxName || app.mailboxName.endsWith('.app')) { // allocate since restore added the addon
values.mailboxName = mailboxNameForLocation(app.location, manifest);
values.mailboxDomain = app.domain;
}
const task = {
args: { updateConfig },
values: {}
values
};
addTask(appId, exports.ISTATE_PENDING_UPDATE, task, function (error, result) {
if (error) return callback(error);
......@@ -1382,6 +1391,13 @@ function repair(app, data, auditSource, callback) {
error = checkManifestConstraints(data.manifest);
if (error) return callback(error);
if (!hasMailAddon(data.manifest)) { // clear if repair removed addon
task.values.mailboxName = task.values.mailboxDomain = null;
} else if (!app.mailboxName || app.mailboxName.endsWith('.app')) { // allocate since repair added the addon
task.values.mailboxName = mailboxNameForLocation(app.location, data.manifest);
task.values.mailboxDomain = app.domain;
}
task.values.manifest = data.manifest;
task.args.oldManifest = app.manifest;
}
......@@ -1425,6 +1441,14 @@ function restore(app, backupId, auditSource, callback) {
error = checkManifestConstraints(backupInfo.manifest);
if (error) return callback(error);
let values = { manifest: backupInfo.manifest };
if (!hasMailAddon(backupInfo.manifest)) { // clear if restore removed addon
values.mailboxName = values.mailboxDomain = null;
} else if (!app.mailboxName || app.mailboxName.endsWith('.app')) { // allocate since restore added the addon
values.mailboxName = mailboxNameForLocation(app.location, backupInfo.manifest);
values.mailboxDomain = app.domain;
}
const restoreConfig = { backupId, backupFormat: backupInfo.format };
const task = {
......@@ -1433,9 +1457,7 @@ function restore(app, backupId, auditSource, callback) {
oldManifest: app.manifest,
overwriteDns: true
},
values: {
manifest: backupInfo.manifest
}
values
};
addTask(appId, exports.ISTATE_PENDING_RESTORE, task, function (error, result) {
if (error) return callback(error);
......@@ -1542,11 +1564,9 @@ function clone(app, data, user, auditSource, callback) {
error = validatePortBindings(portBindings, manifest);
if (error) return callback(error);
let mailboxName = null, mailboxDomain = null;
if (hasMailAddon(manifest)) {
mailboxName = app.mailboxName.endsWith('.app') ? mailboxNameForLocation(location, manifest) : app.mailboxName;
mailboxDomain = domain;
}
// should we copy the original app's mailbox settings instead?
let mailboxName = hasMailAddon(manifest) ? mailboxNameForLocation(location, manifest) : null;
let mailboxDomain = hasMailAddon(manifest) ? domain : null;
const locations = [{subdomain: location, domain}];
validateLocations(locations, function (error, domainObjectMap) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment