2018-01-20 18:30:14 -08:00
'use strict' ;
exports = module . exports = {
2020-07-15 15:33:53 -07:00
getDomain ,
2018-01-24 21:15:58 -08:00
2020-07-15 15:33:53 -07:00
getStatus ,
2018-01-20 18:56:17 -08:00
2020-07-15 15:33:53 -07:00
setMailFromValidation ,
setCatchAllAddress ,
setMailRelay ,
setMailEnabled ,
2020-08-23 14:33:58 -07:00
setBanner ,
2018-01-23 16:10:23 -08:00
2020-07-15 15:33:53 -07:00
sendTestMail ,
2018-01-24 13:11:35 +01:00
2020-07-15 15:33:53 -07:00
listMailboxes ,
getMailbox ,
addMailbox ,
updateMailbox ,
2021-08-17 15:45:57 -07:00
delMailbox ,
2018-01-25 18:03:02 +01:00
2020-07-15 15:33:53 -07:00
getAliases ,
setAliases ,
2018-01-26 10:22:50 +01:00
2020-07-15 15:33:53 -07:00
getLists ,
getList ,
addList ,
updateList ,
2021-08-17 15:45:57 -07:00
delList ,
2020-07-15 15:33:53 -07:00
getMailboxCount
2018-01-20 18:30:14 -08:00
} ;
2021-06-29 14:26:34 -07:00
const assert = require ( 'assert' ) ,
2021-09-30 09:50:30 -07:00
AuditSource = require ( '../auditsource.js' ) ,
2019-10-24 13:34:14 -07:00
BoxError = require ( '../boxerror.js' ) ,
2018-01-20 18:56:17 -08:00
mail = require ( '../mail.js' ) ,
2018-01-20 18:30:14 -08:00
HttpError = require ( 'connect-lastmile' ) . HttpError ,
2021-06-29 14:26:34 -07:00
HttpSuccess = require ( 'connect-lastmile' ) . HttpSuccess ,
safe = require ( 'safetydance' ) ;
2018-01-20 18:30:14 -08:00
2021-06-29 14:26:34 -07:00
async function getDomain ( req , res , next ) {
2018-01-20 22:56:45 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2021-06-29 14:26:34 -07:00
const [ error , result ] = await safe ( mail . getDomain ( req . params . domain ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
if ( ! result ) return next ( new HttpError ( 404 , 'Mail domain not found' ) ) ;
2018-01-20 18:30:14 -08:00
2021-06-29 14:26:34 -07:00
next ( new HttpSuccess ( 200 , mail . removePrivateFields ( result ) ) ) ;
2018-01-20 18:30:14 -08:00
}
2018-01-20 18:56:17 -08:00
2021-08-27 09:52:24 -07:00
async function getStatus ( req , res , next ) {
2018-01-20 23:17:39 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-03-08 09:32:06 -08:00
// can take a while to query all the DNS entries
req . clearTimeout ( ) ;
2021-08-27 09:52:24 -07:00
const [ error , records ] = await safe ( mail . getStatus ( req . params . domain ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-20 18:56:17 -08:00
2021-08-27 09:52:24 -07:00
next ( new HttpSuccess ( 200 , records ) ) ;
2018-01-20 18:56:17 -08:00
}
2021-06-29 14:26:34 -07:00
async function setMailFromValidation ( req , res , next ) {
2018-01-20 23:17:39 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-01-20 18:56:17 -08:00
assert . strictEqual ( typeof req . body , 'object' ) ;
if ( typeof req . body . enabled !== 'boolean' ) return next ( new HttpError ( 400 , 'enabled is required' ) ) ;
2021-06-29 14:26:34 -07:00
const [ error ] = await safe ( mail . setMailFromValidation ( req . params . domain , req . body . enabled ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-20 18:56:17 -08:00
2021-06-29 14:26:34 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2018-01-20 18:56:17 -08:00
}
2021-06-29 14:26:34 -07:00
async function setCatchAllAddress ( req , res , next ) {
2018-01-20 23:17:39 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-01-20 18:56:17 -08:00
assert . strictEqual ( typeof req . body , 'object' ) ;
2018-04-12 12:35:56 +02:00
if ( ! req . body . addresses ) return next ( new HttpError ( 400 , 'addresses is required' ) ) ;
if ( ! Array . isArray ( req . body . addresses ) ) return next ( new HttpError ( 400 , 'addresses must be an array of strings' ) ) ;
2018-01-20 18:56:17 -08:00
2021-06-29 14:26:34 -07:00
for ( let i = 0 ; i < req . body . addresses . length ; i ++ ) {
2018-04-12 12:35:56 +02:00
if ( typeof req . body . addresses [ i ] !== 'string' ) return next ( new HttpError ( 400 , 'addresses must be an array of strings' ) ) ;
2018-01-20 18:56:17 -08:00
}
2021-06-29 14:26:34 -07:00
const [ error ] = await safe ( mail . setCatchAllAddress ( req . params . domain , req . body . addresses ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-20 18:56:17 -08:00
2021-06-29 14:26:34 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2018-01-20 18:56:17 -08:00
}
2021-06-29 14:26:34 -07:00
async function setMailRelay ( req , res , next ) {
2018-01-20 23:17:39 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-01-20 18:56:17 -08:00
assert . strictEqual ( typeof req . body , 'object' ) ;
if ( typeof req . body . provider !== 'string' ) return next ( new HttpError ( 400 , 'provider is required' ) ) ;
if ( 'host' in req . body && typeof req . body . host !== 'string' ) return next ( new HttpError ( 400 , 'host must be a string' ) ) ;
if ( 'port' in req . body && typeof req . body . port !== 'number' ) return next ( new HttpError ( 400 , 'port must be a string' ) ) ;
if ( 'username' in req . body && typeof req . body . username !== 'string' ) return next ( new HttpError ( 400 , 'username must be a string' ) ) ;
if ( 'password' in req . body && typeof req . body . password !== 'string' ) return next ( new HttpError ( 400 , 'password must be a string' ) ) ;
2019-04-23 15:19:33 -07:00
if ( 'acceptSelfSignedCerts' in req . body && typeof req . body . acceptSelfSignedCerts !== 'boolean' ) return next ( new HttpError ( 400 , 'acceptSelfSignedCerts must be a boolean' ) ) ;
2018-01-20 18:56:17 -08:00
2021-06-29 14:26:34 -07:00
const [ error ] = await safe ( mail . setMailRelay ( req . params . domain , req . body , { skipVerify : false } ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-20 18:56:17 -08:00
2021-06-29 14:26:34 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2018-01-20 18:56:17 -08:00
}
2021-06-29 14:26:34 -07:00
async function setMailEnabled ( req , res , next ) {
2018-01-20 23:17:39 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-01-20 18:56:17 -08:00
assert . strictEqual ( typeof req . body , 'object' ) ;
if ( typeof req . body . enabled !== 'boolean' ) return next ( new HttpError ( 400 , 'enabled is required' ) ) ;
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . setMailEnabled ( req . params . domain , ! ! req . body . enabled , AuditSource . fromRequest ( req ) ) ) ;
2021-06-29 14:26:34 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-20 18:56:17 -08:00
2021-06-29 14:26:34 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2018-01-20 18:56:17 -08:00
}
2018-01-23 16:10:23 -08:00
2021-08-19 12:32:23 -07:00
async function sendTestMail ( req , res , next ) {
2018-01-23 16:10:23 -08:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
assert . strictEqual ( typeof req . body , 'object' ) ;
if ( ! req . body . to || typeof req . body . to !== 'string' ) return next ( new HttpError ( 400 , 'to must be a non-empty string' ) ) ;
2021-08-19 12:32:23 -07:00
const [ error ] = await safe ( mail . sendTestMail ( req . params . domain , req . body . to ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-23 16:10:23 -08:00
2021-08-19 12:32:23 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2018-01-23 16:10:23 -08:00
}
2018-01-24 13:11:35 +01:00
2021-08-17 15:45:57 -07:00
async function listMailboxes ( req , res , next ) {
2018-01-24 13:11:35 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2021-08-17 15:45:57 -07:00
const page = typeof req . query . page !== 'undefined' ? parseInt ( req . query . page ) : 1 ;
2020-02-07 14:11:52 -08:00
if ( ! page || page < 0 ) return next ( new HttpError ( 400 , 'page query param has to be a positive number' ) ) ;
2019-10-22 10:11:35 -07:00
2021-08-17 15:45:57 -07:00
const perPage = typeof req . query . per _page !== 'undefined' ? parseInt ( req . query . per _page ) : 25 ;
2020-02-07 14:11:52 -08:00
if ( ! perPage || perPage < 0 ) return next ( new HttpError ( 400 , 'per_page query param has to be a positive number' ) ) ;
2019-10-22 10:11:35 -07:00
2020-07-05 11:23:53 -07:00
if ( req . query . search && typeof req . query . search !== 'string' ) return next ( new HttpError ( 400 , 'search must be a string' ) ) ;
2021-08-17 15:45:57 -07:00
const [ error , mailboxes ] = await safe ( mail . listMailboxes ( req . params . domain , req . query . search || null , page , perPage ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-24 13:11:35 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 200 , { mailboxes } ) ) ;
2018-01-24 13:11:35 +01:00
}
2021-08-17 15:45:57 -07:00
async function getMailboxCount ( req , res , next ) {
2020-07-15 15:33:53 -07:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2021-08-17 15:45:57 -07:00
const [ error , count ] = await safe ( mail . getMailboxCount ( req . params . domain ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2020-07-15 15:33:53 -07:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 200 , { count } ) ) ;
2020-07-15 15:33:53 -07:00
}
2021-08-17 15:45:57 -07:00
async function getMailbox ( req , res , next ) {
2018-01-24 13:11:35 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 12:18:26 -07:00
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-01-24 13:11:35 +01:00
2021-08-17 15:45:57 -07:00
const [ error , result ] = await safe ( mail . getMailbox ( req . params . name , req . params . domain ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
if ( ! result ) return next ( new HttpError ( 404 , 'Mailbox not found' ) ) ;
2018-01-24 13:11:35 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 200 , { mailbox : result } ) ) ;
2018-01-24 13:11:35 +01:00
}
2021-08-17 15:45:57 -07:00
async function addMailbox ( req , res , next ) {
2018-01-24 13:11:35 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 12:18:26 -07:00
if ( typeof req . body . name !== 'string' ) return next ( new HttpError ( 400 , 'name must be a string' ) ) ;
2020-11-12 23:25:33 -08:00
if ( typeof req . body . ownerId !== 'string' ) return next ( new HttpError ( 400 , 'ownerId must be a string' ) ) ;
if ( typeof req . body . ownerType !== 'string' ) return next ( new HttpError ( 400 , 'ownerType must be a string' ) ) ;
2021-04-14 22:37:01 -07:00
if ( typeof req . body . active !== 'boolean' ) return next ( new HttpError ( 400 , 'active must be a boolean' ) ) ;
2018-04-03 12:18:26 -07:00
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . addMailbox ( req . body . name , req . params . domain , req . body , AuditSource . fromRequest ( req ) ) ) ;
2021-08-17 15:45:57 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-24 13:11:35 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 201 , { } ) ) ;
2018-01-24 13:11:35 +01:00
}
2021-08-17 15:45:57 -07:00
async function updateMailbox ( req , res , next ) {
2018-04-03 14:12:43 -07:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2020-11-12 23:25:33 -08:00
if ( typeof req . body . ownerId !== 'string' ) return next ( new HttpError ( 400 , 'ownerId must be a string' ) ) ;
if ( typeof req . body . ownerType !== 'string' ) return next ( new HttpError ( 400 , 'ownerType must be a string' ) ) ;
2021-04-14 22:37:01 -07:00
if ( typeof req . body . active !== 'boolean' ) return next ( new HttpError ( 400 , 'active must be a boolean' ) ) ;
2021-10-08 10:15:48 -07:00
if ( typeof req . body . enablePop3 !== 'boolean' ) return next ( new HttpError ( 400 , 'enablePop3 must be a boolean' ) ) ;
2018-04-03 14:12:43 -07:00
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . updateMailbox ( req . params . name , req . params . domain , req . body , AuditSource . fromRequest ( req ) ) ) ;
2021-08-17 15:45:57 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-04-03 14:12:43 -07:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 204 ) ) ;
2018-04-03 14:12:43 -07:00
}
2021-08-17 15:45:57 -07:00
async function delMailbox ( req , res , next ) {
2018-01-24 13:11:35 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 12:18:26 -07:00
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-01-24 13:11:35 +01:00
2020-07-27 22:26:10 -07:00
if ( typeof req . body . deleteMails !== 'boolean' ) return next ( new HttpError ( 400 , 'deleteMails must be a boolean' ) ) ;
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . delMailbox ( req . params . name , req . params . domain , req . body , AuditSource . fromRequest ( req ) ) ) ;
2021-08-17 15:45:57 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-24 13:11:35 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 201 , { } ) ) ;
2018-01-24 13:11:35 +01:00
}
2018-01-25 18:03:02 +01:00
2021-08-17 15:45:57 -07:00
async function getAliases ( req , res , next ) {
2018-04-01 18:23:54 +02:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 12:18:26 -07:00
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-01-25 18:03:02 +01:00
2021-08-17 15:45:57 -07:00
const [ error , aliases ] = await safe ( mail . getAliases ( req . params . name , req . params . domain ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-25 18:03:02 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 200 , { aliases } ) ) ;
2018-01-25 18:03:02 +01:00
}
2021-08-17 15:45:57 -07:00
async function setAliases ( req , res , next ) {
2018-01-25 18:03:02 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 12:18:26 -07:00
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-01-25 18:03:02 +01:00
assert . strictEqual ( typeof req . body , 'object' ) ;
if ( ! Array . isArray ( req . body . aliases ) ) return next ( new HttpError ( 400 , 'aliases must be an array' ) ) ;
2020-04-19 18:44:16 -07:00
for ( let 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' ) ) ;
2018-01-25 18:03:02 +01:00
}
2021-08-17 15:45:57 -07:00
const [ error ] = await safe ( mail . setAliases ( req . params . name , req . params . domain , req . body . aliases ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-25 18:03:02 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2018-01-25 18:03:02 +01:00
}
2018-01-26 10:22:50 +01:00
2021-06-29 14:26:34 -07:00
async function setBanner ( req , res , next ) {
2020-08-23 14:33:58 -07:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
assert . strictEqual ( typeof req . body , 'object' ) ;
if ( typeof req . body . text !== 'string' ) return res . status ( 400 ) . send ( { message : 'text must be a string' } ) ;
if ( 'html' in req . body && typeof req . body . html !== 'string' ) return res . status ( 400 ) . send ( { message : 'html must be a string' } ) ;
2021-06-29 14:26:34 -07:00
const [ error ] = await safe ( mail . setBanner ( req . params . domain , { text : req . body . text , html : req . body . html || null } ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2020-08-23 14:33:58 -07:00
2021-06-29 14:26:34 -07:00
next ( new HttpSuccess ( 202 ) ) ;
2020-08-23 14:33:58 -07:00
}
2021-08-17 15:45:57 -07:00
async function getLists ( req , res , next ) {
2018-01-26 10:22:50 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2020-07-05 10:36:17 -07:00
const page = typeof req . query . page !== 'undefined' ? parseInt ( req . query . page ) : 1 ;
if ( ! page || page < 0 ) return next ( new HttpError ( 400 , 'page query param has to be a positive number' ) ) ;
const perPage = typeof req . query . per _page !== 'undefined' ? parseInt ( req . query . per _page ) : 25 ;
if ( ! perPage || perPage < 0 ) return next ( new HttpError ( 400 , 'per_page query param has to be a positive number' ) ) ;
2020-07-05 11:23:53 -07:00
if ( req . query . search && typeof req . query . search !== 'string' ) return next ( new HttpError ( 400 , 'search must be a string' ) ) ;
2021-08-17 15:45:57 -07:00
const [ error , lists ] = await safe ( mail . getLists ( req . params . domain , req . query . search || null , page , perPage ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-26 10:22:50 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 200 , { lists } ) ) ;
2018-01-26 10:22:50 +01:00
}
2021-08-17 15:45:57 -07:00
async function getList ( req , res , next ) {
2018-01-26 10:22:50 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 09:34:33 -07:00
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-01-26 10:22:50 +01:00
2021-08-17 15:45:57 -07:00
const [ error , result ] = await safe ( mail . getList ( req . params . name , req . params . domain ) ) ;
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
if ( ! result ) return next ( new HttpError ( 404 , 'List not found' ) ) ;
2018-01-26 10:22:50 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 200 , { list : result } ) ) ;
2018-01-26 10:22:50 +01:00
}
2021-08-17 15:45:57 -07:00
async function addList ( req , res , next ) {
2018-01-26 10:22:50 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
assert . strictEqual ( typeof req . body , 'object' ) ;
2018-04-03 09:34:33 -07:00
if ( typeof req . body . name !== 'string' ) return next ( new HttpError ( 400 , 'name must be a string' ) ) ;
2018-04-05 15:46:13 -07:00
if ( ! Array . isArray ( req . body . members ) ) return next ( new HttpError ( 400 , 'members must be a string' ) ) ;
2019-09-11 14:09:36 -07:00
if ( req . body . members . length === 0 ) return next ( new HttpError ( 400 , 'list must have atleast one member' ) ) ;
2018-01-26 10:22:50 +01:00
2021-08-17 15:45:57 -07:00
for ( let i = 0 ; i < req . body . members . length ; i ++ ) {
2018-04-05 15:46:13 -07:00
if ( typeof req . body . members [ i ] !== 'string' ) return next ( new HttpError ( 400 , 'member must be a string' ) ) ;
}
2020-04-17 16:55:23 -07:00
if ( typeof req . body . membersOnly !== 'boolean' ) return next ( new HttpError ( 400 , 'membersOnly must be a boolean' ) ) ;
2021-04-14 22:37:01 -07:00
if ( typeof req . body . active !== 'boolean' ) return next ( new HttpError ( 400 , 'active must be a boolean' ) ) ;
2018-04-05 15:46:13 -07:00
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . addList ( req . body . name , req . params . domain , req . body , AuditSource . fromRequest ( req ) ) ) ;
2021-08-17 15:45:57 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-26 10:22:50 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 201 , { } ) ) ;
2018-01-26 10:22:50 +01:00
}
2021-08-17 15:45:57 -07:00
async function updateList ( req , res , next ) {
2018-04-03 14:12:43 -07:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-04-05 15:46:13 -07:00
if ( ! Array . isArray ( req . body . members ) ) return next ( new HttpError ( 400 , 'members must be a string' ) ) ;
2019-09-11 14:09:36 -07:00
if ( req . body . members . length === 0 ) return next ( new HttpError ( 400 , 'list must have atleast one member' ) ) ;
2018-04-05 15:46:13 -07:00
for ( var i = 0 ; i < req . body . members . length ; i ++ ) {
if ( typeof req . body . members [ i ] !== 'string' ) return next ( new HttpError ( 400 , 'member must be a string' ) ) ;
}
2020-04-17 16:55:23 -07:00
if ( typeof req . body . membersOnly !== 'boolean' ) return next ( new HttpError ( 400 , 'membersOnly must be a boolean' ) ) ;
2021-04-14 22:37:01 -07:00
if ( typeof req . body . active !== 'boolean' ) return next ( new HttpError ( 400 , 'active must be a boolean' ) ) ;
2018-04-03 14:12:43 -07:00
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . updateList ( req . params . name , req . params . domain , req . body , AuditSource . fromRequest ( req ) ) ) ;
2021-08-17 15:45:57 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-04-03 14:12:43 -07:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 204 ) ) ;
2018-04-03 14:12:43 -07:00
}
2021-08-17 15:45:57 -07:00
async function delList ( req , res , next ) {
2018-01-26 10:22:50 +01:00
assert . strictEqual ( typeof req . params . domain , 'string' ) ;
2018-04-03 09:34:33 -07:00
assert . strictEqual ( typeof req . params . name , 'string' ) ;
2018-01-26 10:22:50 +01:00
2021-09-30 09:50:30 -07:00
const [ error ] = await safe ( mail . delList ( req . params . name , req . params . domain , AuditSource . fromRequest ( req ) ) ) ;
2021-08-17 15:45:57 -07:00
if ( error ) return next ( BoxError . toHttpError ( error ) ) ;
2018-01-26 10:22:50 +01:00
2021-08-17 15:45:57 -07:00
next ( new HttpSuccess ( 204 ) ) ;
2018-01-26 10:22:50 +01:00
}