diff --git a/src/eventlog.js b/src/eventlog.js index c2e49fa43..4f69a7bfa 100644 --- a/src/eventlog.js +++ b/src/eventlog.js @@ -2,6 +2,7 @@ exports = module.exports = { add, + upsert, get, getAllPaged, getByCreationTime, @@ -91,9 +92,24 @@ function add(action, source, data, callback) { callback = callback || NOOP_CALLBACK; - // we do only daily upserts for login actions, so they don't spam the db - var api = action === exports.ACTION_USER_LOGIN ? eventlogdb.upsert : eventlogdb.add; - api(uuid.v4(), action, source, data, function (error, id) { + eventlogdb.add(uuid.v4(), action, source, data, function (error, id) { + if (error) return callback(error); + + callback(null, { id: id }); + + notifications.onEvent(id, action, source, data, NOOP_CALLBACK); + }); +} + +function upsert(action, source, data, callback) { + assert.strictEqual(typeof action, 'string'); + assert.strictEqual(typeof source, 'object'); + assert.strictEqual(typeof data, 'object'); + assert(!callback || typeof callback === 'function'); + + callback = callback || NOOP_CALLBACK; + + eventlogdb.upsert(uuid.v4(), action, source, data, function (error, id) { if (error) return callback(error); callback(null, { id: id }); diff --git a/src/ldap.js b/src/ldap.js index 10b66c6fd..0eb18b68f 100644 --- a/src/ldap.js +++ b/src/ldap.js @@ -492,7 +492,7 @@ function authorizeUserForApp(req, res, next) { // we return no such object, to avoid leakage of a users existence if (!hasAccess) return next(new ldap.NoSuchObjectError(req.dn.toString())); - eventlog.add(eventlog.ACTION_USER_LOGIN, { authType: 'ldap', appId: req.app.id }, { userId: req.user.id, user: users.removePrivateFields(req.user) }); + eventlog.upsert(eventlog.ACTION_USER_LOGIN, { authType: 'ldap', appId: req.app.id }, { userId: req.user.id, user: users.removePrivateFields(req.user) }); res.end(); }); @@ -546,7 +546,7 @@ function authenticateUserMailbox(req, res, next) { if (error && error.reason === BoxError.INVALID_CREDENTIALS) return next(new ldap.InvalidCredentialsError(req.dn.toString())); if (error) return next(new ldap.OperationsError(error.message)); - eventlog.add(eventlog.ACTION_USER_LOGIN, { authType: 'ldap', mailboxId: email }, { userId: result.id, user: users.removePrivateFields(result) }); + eventlog.upsert(eventlog.ACTION_USER_LOGIN, { authType: 'ldap', mailboxId: email }, { userId: result.id, user: users.removePrivateFields(result) }); res.end(); }); }); @@ -686,7 +686,7 @@ function authenticateMailAddon(req, res, next) { if (error && error.reason === BoxError.INVALID_CREDENTIALS) return next(new ldap.InvalidCredentialsError(req.dn.toString())); if (error) return next(new ldap.OperationsError(error.message)); - eventlog.add(eventlog.ACTION_USER_LOGIN, { authType: 'ldap', mailboxId: email }, { userId: result.id, user: users.removePrivateFields(result) }); + eventlog.upsert(eventlog.ACTION_USER_LOGIN, { authType: 'ldap', mailboxId: email }, { userId: result.id, user: users.removePrivateFields(result) }); res.end(); }); });