eventlog: add mailbox and list update events

This commit is contained in:
Girish Ramakrishnan
2020-01-24 16:55:41 -08:00
parent 45053205db
commit cda649884e
4 changed files with 26 additions and 9 deletions
+2
View File
@@ -40,8 +40,10 @@ exports = module.exports = {
ACTION_MAIL_DISABLED: 'mail.disabled',
ACTION_MAIL_MAILBOX_ADD: 'mail.box.add',
ACTION_MAIL_MAILBOX_REMOVE: 'mail.box.remove',
ACTION_MAIL_MAILBOX_UPDATE: 'mail.box.update',
ACTION_MAIL_LIST_ADD: 'mail.list.add',
ACTION_MAIL_LIST_REMOVE: 'mail.list.remove',
ACTION_MAIL_LIST_UPDATE: 'mail.list.update',
ACTION_PROVISION: 'cloudron.provision',
ACTION_RESTORE: 'cloudron.restore', // unused
+21 -7
View File
@@ -1106,18 +1106,25 @@ function addMailbox(name, domain, userId, auditSource, callback) {
});
}
function updateMailboxOwner(name, domain, userId, callback) {
function updateMailboxOwner(name, domain, userId, auditSource, callback) {
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof userId, 'string');
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof callback, 'function');
name = name.toLowerCase();
mailboxdb.updateMailboxOwner(name, domain, userId, function (error) {
getMailbox(name, domain, function (error, result) {
if (error) return callback(error);
callback(null);
mailboxdb.updateMailboxOwner(name, domain, userId, function (error) {
if (error) return callback(error);
eventlog.add(eventlog.ACTION_MAIL_MAILBOX_UPDATE, auditSource, { name, domain, oldUserId: result.userId, userId });
callback(null);
});
});
}
@@ -1227,16 +1234,17 @@ function addList(name, domain, members, auditSource, callback) {
mailboxdb.addList(name, domain, members, function (error) {
if (error) return callback(error);
eventlog.add(eventlog.ACTION_MAIL_LIST_ADD, auditSource, { name, domain });
eventlog.add(eventlog.ACTION_MAIL_LIST_ADD, auditSource, { name, domain, members });
callback();
});
}
function updateList(name, domain, members, callback) {
function updateList(name, domain, members, auditSource, callback) {
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof domain, 'string');
assert(Array.isArray(members));
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof callback, 'function');
name = name.toLowerCase();
@@ -1248,10 +1256,16 @@ function updateList(name, domain, members, callback) {
if (!validator.isEmail(members[i])) return callback(new BoxError(BoxError.BAD_FIELD, 'Invalid email: ' + members[i]));
}
mailboxdb.updateList(name, domain, members, function (error) {
getList(name, domain, function (error, result) {
if (error) return callback(error);
callback(null);
mailboxdb.updateList(name, domain, members, function (error) {
if (error) return callback(error);
eventlog.add(eventlog.ACTION_MAIL_MAILBOX_UPDATE, auditSource, { name, domain, oldMembers: result.members, members });
callback(null);
});
});
}
+2 -2
View File
@@ -239,7 +239,7 @@ function updateMailbox(req, res, next) {
if (typeof req.body.userId !== 'string') return next(new HttpError(400, 'userId must be a string'));
mail.updateMailboxOwner(req.params.name, req.params.domain, req.body.userId, function (error) {
mail.updateMailboxOwner(req.params.name, req.params.domain, req.body.userId, auditSource.fromRequest(req), function (error) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204));
@@ -353,7 +353,7 @@ function updateList(req, res, next) {
if (typeof req.body.members[i] !== 'string') return next(new HttpError(400, 'member must be a string'));
}
mail.updateList(req.params.name, req.params.domain, req.body.members, function (error) {
mail.updateList(req.params.name, req.params.domain, req.body.members, auditSource.fromRequest(req), function (error) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204));