clear mailbox on update and restore

part of #669
This commit is contained in:
Girish Ramakrishnan
2020-03-31 15:44:46 -07:00
parent 3fec599c0c
commit 5b62d63463
2 changed files with 30 additions and 17 deletions
+29 -9
View File
@@ -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) {