mail: restart apps using email addon

move this logic from frontend to backend
This commit is contained in:
Girish Ramakrishnan
2025-03-10 21:14:55 +01:00
parent 72635c8711
commit 8a51582d8a
3 changed files with 18 additions and 3 deletions

View File

@@ -75,6 +75,7 @@ const assert = require('assert'),
nodemailer = require('nodemailer'),
notifications = require('./notifications.js'),
path = require('path'),
platform = require('./platforms.js'),
safe = require('safetydance'),
services = require('./services.js'),
shell = require('./shell.js')('mail'),
@@ -856,9 +857,10 @@ async function setMailEnabled(domain, enabled, auditSource) {
assert.strictEqual(typeof enabled, 'boolean');
assert.strictEqual(typeof auditSource, 'object');
await updateDomain(domain, { enabled: enabled });
await updateDomain(domain, { enabled });
safe(mailServer.restart(), { debug });
await mailServer.restart();
await platform.onMailServerIncomingDomainsChanged();
await eventlog.add(enabled ? eventlog.ACTION_MAIL_ENABLED : eventlog.ACTION_MAIL_DISABLED, auditSource, { domain });
}

View File

@@ -8,6 +8,7 @@ exports = module.exports = {
onDashboardLocationSet,
onDashboardLocationChanged,
onMailServerLocationChanged,
onMailServerIncomingDomainsChanged,
getStatus
};
@@ -251,3 +252,12 @@ async function onMailServerLocationChanged(auditSource) {
const appsUsingEmail = installedApps.filter((a) => !!a.manifest.addons?.email || a.manifest.addons?.sendmail?.requiresValidCertificate);
await safe(apps.configureApps(appsUsingEmail, { scheduleNow: true }, auditSource), { debug });
}
async function onMailServerIncomingDomainsChanged(auditSource) {
assert.strictEqual(typeof auditSource, 'object');
// mark apps using email addon to be reconfigured
const [, installedApps] = await safe(apps.list());
const appsUsingEmail = installedApps.filter((a) => !!a.manifest.addons?.email);
await safe(apps.configureApps(appsUsingEmail, { scheduleNow: true }, auditSource), { debug });
}

View File

@@ -114,6 +114,9 @@ async function setMailEnabled(req, res, next) {
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled is required'));
// can take a while to restart the mail container
req.clearTimeout();
const [error] = await safe(mail.setMailEnabled(req.params.domain, !!req.body.enabled, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
@@ -237,7 +240,7 @@ async function setAliases(req, res, next) {
if (!Array.isArray(req.body.aliases)) return next(new HttpError(400, 'aliases must be an array'));
for (let alias of req.body.aliases) {
for (const alias of req.body.aliases) {
if (!alias || typeof alias !== 'object') return next(new HttpError(400, 'each alias must have a name and domain'));
if (typeof alias.name !== 'string') return next(new HttpError(400, 'name must be a string'));
if (typeof alias.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));