mail: restart apps using email addon
move this logic from frontend to backend
This commit is contained in:
@@ -75,6 +75,7 @@ const assert = require('assert'),
|
|||||||
nodemailer = require('nodemailer'),
|
nodemailer = require('nodemailer'),
|
||||||
notifications = require('./notifications.js'),
|
notifications = require('./notifications.js'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
platform = require('./platforms.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
services = require('./services.js'),
|
services = require('./services.js'),
|
||||||
shell = require('./shell.js')('mail'),
|
shell = require('./shell.js')('mail'),
|
||||||
@@ -856,9 +857,10 @@ async function setMailEnabled(domain, enabled, auditSource) {
|
|||||||
assert.strictEqual(typeof enabled, 'boolean');
|
assert.strictEqual(typeof enabled, 'boolean');
|
||||||
assert.strictEqual(typeof auditSource, 'object');
|
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 });
|
await eventlog.add(enabled ? eventlog.ACTION_MAIL_ENABLED : eventlog.ACTION_MAIL_DISABLED, auditSource, { domain });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ exports = module.exports = {
|
|||||||
onDashboardLocationSet,
|
onDashboardLocationSet,
|
||||||
onDashboardLocationChanged,
|
onDashboardLocationChanged,
|
||||||
onMailServerLocationChanged,
|
onMailServerLocationChanged,
|
||||||
|
onMailServerIncomingDomainsChanged,
|
||||||
|
|
||||||
getStatus
|
getStatus
|
||||||
};
|
};
|
||||||
@@ -251,3 +252,12 @@ async function onMailServerLocationChanged(auditSource) {
|
|||||||
const appsUsingEmail = installedApps.filter((a) => !!a.manifest.addons?.email || a.manifest.addons?.sendmail?.requiresValidCertificate);
|
const appsUsingEmail = installedApps.filter((a) => !!a.manifest.addons?.email || a.manifest.addons?.sendmail?.requiresValidCertificate);
|
||||||
await safe(apps.configureApps(appsUsingEmail, { scheduleNow: true }, auditSource), { debug });
|
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 });
|
||||||
|
}
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ async function setMailEnabled(req, res, next) {
|
|||||||
|
|
||||||
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled is required'));
|
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)));
|
const [error] = await safe(mail.setMailEnabled(req.params.domain, !!req.body.enabled, AuditSource.fromRequest(req)));
|
||||||
if (error) return next(BoxError.toHttpError(error));
|
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'));
|
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 (!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.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'));
|
if (typeof alias.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
||||||
|
|||||||
Reference in New Issue
Block a user