eventlog: mailbox add,remove events

This commit is contained in:
Girish Ramakrishnan
2018-11-09 18:45:44 -08:00
parent 1bb3b5e51b
commit 003789265c
3 changed files with 23 additions and 4 deletions
+7 -2
View File
@@ -44,6 +44,11 @@ var assert = require('assert'),
var mailProxy = middleware.proxy(url.parse('http://127.0.0.1:2020'));
function auditSource(req) {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || null;
return { ip: ip, username: req.user ? req.user.username : null, userId: req.user ? req.user.id : null };
}
function getDomain(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
@@ -234,7 +239,7 @@ function addMailbox(req, res, next) {
if (typeof req.body.name !== 'string') return next(new HttpError(400, 'name must be a string'));
if (typeof req.body.userId !== 'string') return next(new HttpError(400, 'userId must be a string'));
mail.addMailbox(req.body.name, req.params.domain, req.body.userId, function (error) {
mail.addMailbox(req.body.name, req.params.domain, req.body.userId, auditSource(req), function (error) {
if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message));
if (error && error.reason === MailError.ALREADY_EXISTS) return next(new HttpError(409, error.message));
if (error && error.reason === MailError.BAD_FIELD) return next(new HttpError(400, error.message));
@@ -263,7 +268,7 @@ function removeMailbox(req, res, next) {
assert.strictEqual(typeof req.params.domain, 'string');
assert.strictEqual(typeof req.params.name, 'string');
mail.removeMailbox(req.params.name, req.params.domain, function (error) {
mail.removeMailbox(req.params.name, req.params.domain, auditSource(req), function (error) {
if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message));
if (error) return next(new HttpError(500, error));