remove mail domain add/remove API
merge this as a transaction into domains API fixes #669
This commit is contained in:
+10
-25
@@ -7,10 +7,11 @@ exports = module.exports = {
|
||||
getDomains: getDomains,
|
||||
|
||||
getDomain: getDomain,
|
||||
addDomain: addDomain,
|
||||
removeDomain: removeDomain,
|
||||
clearDomains: clearDomains,
|
||||
|
||||
onDomainAdded: onDomainAdded,
|
||||
onDomainRemoved: onDomainRemoved,
|
||||
|
||||
removePrivateFields: removePrivateFields,
|
||||
|
||||
setDnsRecords: setDnsRecords,
|
||||
@@ -904,37 +905,21 @@ function onMailFqdnChanged(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function addDomain(domain, callback) {
|
||||
function onDomainAdded(domain, callback) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const dkimSelector = domain === settings.adminDomain() ? 'cloudron' : ('cloudron-' + settings.adminDomain().replace(/\./g, ''));
|
||||
|
||||
maildb.add(domain, { dkimSelector }, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
async.series([
|
||||
upsertDnsRecords.bind(null, domain, settings.mailFqdn()), // do this first to ensure DKIM keys
|
||||
restartMailIfActivated
|
||||
], NOOP_CALLBACK); // do these asynchronously
|
||||
|
||||
callback();
|
||||
});
|
||||
async.series([
|
||||
upsertDnsRecords.bind(null, domain, settings.mailFqdn()), // do this first to ensure DKIM keys
|
||||
restartMailIfActivated
|
||||
], callback);
|
||||
}
|
||||
|
||||
function removeDomain(domain, callback) {
|
||||
function onDomainRemoved(domain, callback) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (domain === settings.adminDomain()) return callback(new BoxError(BoxError.CONFLICT));
|
||||
|
||||
maildb.del(domain, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
restartMail(NOOP_CALLBACK);
|
||||
|
||||
callback();
|
||||
});
|
||||
restartMail(callback);
|
||||
}
|
||||
|
||||
function clearDomains(callback) {
|
||||
|
||||
Reference in New Issue
Block a user