make mailbox domain nullable

for apps that do not use sendmail/recvmail addon, these are now null.
otherwise, there is no way to edit the mailbox in the UI

part of #669
This commit is contained in:
Girish Ramakrishnan
2020-03-30 22:18:39 -07:00
parent 7cb0c31c59
commit e30ea9f143
4 changed files with 59 additions and 9 deletions

View File

@@ -699,6 +699,10 @@ function validateLocations(locations, callback) {
});
}
function hasMailAddon(manifest) {
return manifest.addons.sendmail || manifest.addons.recvmail;
}
function install(data, auditSource, callback) {
assert(data && typeof data === 'object');
assert.strictEqual(typeof auditSource, 'object');
@@ -757,7 +761,8 @@ function install(data, auditSource, callback) {
error = validateEnv(env);
if (error) return callback(error);
const mailboxName = mailboxNameForLocation(location, manifest);
const mailboxName = hasMailAddon(manifest) ? mailboxNameForLocation(location, manifest) : null;
const mailboxDomain = hasMailAddon(manifest) ? domain : null;
const appId = uuid.v4();
if (icon) {
@@ -785,7 +790,7 @@ function install(data, auditSource, callback) {
sso: sso,
debugMode: debugMode,
mailboxName: mailboxName,
mailboxDomain: domain,
mailboxDomain: mailboxDomain,
enableBackup: enableBackup,
enableAutomaticUpdate: enableAutomaticUpdate,
alternateDomains: alternateDomains,
@@ -1026,6 +1031,8 @@ function setMailbox(app, mailboxName, mailboxDomain, auditSource, callback) {
let error = checkAppState(app, exports.ISTATE_PENDING_RECREATE_CONTAINER);
if (error) return callback(error);
if (!hasMailAddon(app.manifest)) return callback(new BoxError(BoxError.BAD_FIELD, 'App does not use mail addons'));
mail.getDomain(mailboxDomain, function (error) {
if (error) return callback(error);
@@ -1033,7 +1040,7 @@ function setMailbox(app, mailboxName, mailboxDomain, auditSource, callback) {
error = mail.validateName(mailboxName);
if (error) return callback(new BoxError(BoxError.BAD_FIELD, error.message, { field: 'mailboxName' }));
} else {
mailboxName = mailboxNameForLocation(app.location, app.manifest);
mailboxName = mailboxNameForLocation(app.location, app.domain, app.manifest);
}
const task = {
@@ -1161,7 +1168,10 @@ function setLocation(app, data, auditSource, callback) {
}
// move the mailbox name to match the new location
if (app.mailboxName.endsWith('.app')) values.mailboxName = mailboxNameForLocation(values.location, app.manifest);
if (hasMailAddon(app.manifest) && app.mailboxName.endsWith('.app')) {
values.mailboxName = mailboxNameForLocation(values.location, app.manifest);
values.mailboxDomain = values.domain;
}
if ('alternateDomains' in data) {
values.alternateDomains = data.alternateDomains;
@@ -1532,7 +1542,12 @@ function clone(app, data, user, auditSource, callback) {
error = validatePortBindings(portBindings, manifest);
if (error) return callback(error);
const mailboxName = app.mailboxName.endsWith('.app') ? mailboxNameForLocation(location, manifest) : app.mailboxName;
let mailboxName = null, mailboxDomain = null;
if (hasMailAddon(manifest)) {
mailboxName = app.mailboxName.endsWith('.app') ? mailboxNameForLocation(location, manifest) : app.mailboxName;
mailboxDomain = domain;
}
const locations = [{subdomain: location, domain}];
validateLocations(locations, function (error, domainObjectMap) {
if (error) return callback(error);
@@ -1546,7 +1561,7 @@ function clone(app, data, user, auditSource, callback) {
accessRestriction: app.accessRestriction,
sso: !!app.sso,
mailboxName: mailboxName,
mailboxDomain: domain,
mailboxDomain: mailboxDomain,
enableBackup: app.enableBackup,
reverseProxyConfig: app.reverseProxyConfig,
env: app.env,