add inboxDomain fk constraint

This commit is contained in:
Girish Ramakrishnan
2024-02-27 13:45:08 +01:00
parent 5927f397a3
commit aecc16af5d
3 changed files with 33 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
'use strict';
exports.up = function(db, callback) {
db.runSql('ALTER TABLE apps ADD CONSTRAINT inbox_domain_constraint FOREIGN KEY(inboxDomain) REFERENCES domains(domain)', function (error)
{
if (error) console.error(error);
callback(error);
});
};
exports.down = function(db, callback) {
db.runSql('ALTER TABLE apps DROP FOREIGN KEY inbox_domain_constraint', function (error) {
if (error) console.error(error);
callback(error);
});
};

View File

@@ -105,6 +105,7 @@ CREATE TABLE IF NOT EXISTS apps(
upstreamUri VARCHAR(256) DEFAULT "", upstreamUri VARCHAR(256) DEFAULT "",
FOREIGN KEY(mailboxDomain) REFERENCES domains(domain), FOREIGN KEY(mailboxDomain) REFERENCES domains(domain),
FOREIGN KEY(inboxDomain) REFERENCES domains(domain),
FOREIGN KEY(taskId) REFERENCES tasks(id), FOREIGN KEY(taskId) REFERENCES tasks(id),
FOREIGN KEY(storageVolumeId) REFERENCES volumes(id), FOREIGN KEY(storageVolumeId) REFERENCES volumes(id),
UNIQUE (storageVolumeId, storageVolumePrefix), UNIQUE (storageVolumeId, storageVolumePrefix),

View File

@@ -1994,6 +1994,11 @@ async function updateApp(app, data, auditSource) {
values.mailboxDomain = app.domain; values.mailboxDomain = app.domain;
} }
if (!manifest.addons?.recvmail) { // clear if the update removed addon. required for fk constraint
values.enableInbox = false;
values.inboxName = values.inboxDomain = null;
}
const hasSso = !!updateConfig.manifest.addons?.proxyAuth || !!updateConfig.manifest.addons?.ldap || !!manifest.addons?.oidc; const hasSso = !!updateConfig.manifest.addons?.proxyAuth || !!updateConfig.manifest.addons?.ldap || !!manifest.addons?.oidc;
if (!hasSso && app.sso) values.sso = false; // turn off sso flag, if the update removes sso options if (!hasSso && app.sso) values.sso = false; // turn off sso flag, if the update removes sso options
@@ -2149,6 +2154,11 @@ async function restore(app, backupId, auditSource) {
values.mailboxDomain = app.domain; values.mailboxDomain = app.domain;
} }
if (!manifest.addons?.recvmail) { // recvmail is always optional. clear if restore removed addon
values.enableInbox = false;
values.inboxName = values.inboxDomain = null;
}
const restoreConfig = { remotePath: backupInfo.remotePath, backupFormat: backupInfo.format }; const restoreConfig = { remotePath: backupInfo.remotePath, backupFormat: backupInfo.format };
const task = { const task = {
@@ -2290,7 +2300,7 @@ async function clone(app, data, user, auditSource) {
error = validatePortBindings(data.portBindings || null, manifest); error = validatePortBindings(data.portBindings || null, manifest);
if (error) throw error; if (error) throw error;
const newPortBindings = translatePortBindings(data.portBindings || null, manifest); const portBindings = translatePortBindings(data.portBindings || null, manifest);
// should we copy the original app's mailbox settings instead? // should we copy the original app's mailbox settings instead?
const mailboxName = manifest.addons?.sendmail ? mailboxNameForSubdomain(subdomain, manifest) : null; const mailboxName = manifest.addons?.sendmail ? mailboxNameForSubdomain(subdomain, manifest) : null;
@@ -2304,6 +2314,8 @@ async function clone(app, data, user, auditSource) {
'enableMailbox', 'mailboxDisplayName', 'mailboxName', 'mailboxDomain', 'enableInbox', 'inboxName', 'inboxDomain', 'enableMailbox', 'mailboxDisplayName', 'mailboxName', 'mailboxDomain', 'enableInbox', 'inboxName', 'inboxDomain',
'enableTurn', 'enableRedis', 'mounts', 'enableBackup', 'enableAutomaticUpdate', 'accessRestriction', 'operators', 'sso'); 'enableTurn', 'enableRedis', 'mounts', 'enableBackup', 'enableAutomaticUpdate', 'accessRestriction', 'operators', 'sso');
if (!manifest.addons?.recvmail) dolly.inboxDomain = null; // needed because we are cloning _current_ app settings with old manifest
const obj = Object.assign(dolly, { const obj = Object.assign(dolly, {
installationState: exports.ISTATE_PENDING_CLONE, installationState: exports.ISTATE_PENDING_CLONE,
runState: exports.RSTATE_RUNNING, runState: exports.RSTATE_RUNNING,
@@ -2316,8 +2328,8 @@ async function clone(app, data, user, auditSource) {
icon: icons.icon, icon: icons.icon,
}); });
const [addError] = await safe(add(newAppId, appStoreId, manifest, subdomain, domain, newPortBindings, obj)); const [addError] = await safe(add(newAppId, appStoreId, manifest, subdomain, domain, portBindings, obj));
if (addError && addError.reason === BoxError.ALREADY_EXISTS) throw getDuplicateErrorDetails(addError.message, locations, newPortBindings); if (addError && addError.reason === BoxError.ALREADY_EXISTS) throw getDuplicateErrorDetails(addError.message, locations, portBindings);
if (addError) throw addError; if (addError) throw addError;
await purchaseApp({ appId: newAppId, appstoreId: app.appStoreId, manifestId: manifest.id || 'customapp' }); await purchaseApp({ appId: newAppId, appstoreId: app.appStoreId, manifestId: manifest.id || 'customapp' });