mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 21:59:00 +02:00
Merge pull request #15001 from overleaf/em-invite-audit-logs
Project audit logs for invite operations GitOrigin-RevId: c2db4bc719f508c5bf33be2c59eddfb63fcdae25
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const logger = require('@overleaf/logger')
|
||||
const { ProjectAuditLogEntry } = require('../../models/ProjectAuditLogEntry')
|
||||
const { callbackify } = require('../../util/promises')
|
||||
|
||||
@@ -5,7 +6,8 @@ module.exports = {
|
||||
promises: {
|
||||
addEntry,
|
||||
},
|
||||
addEntry: callbackify(addEntry), // callback version of adEntry
|
||||
addEntry: callbackify(addEntry), // callback version of addEntry
|
||||
addEntryInBackground,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,12 +19,39 @@ module.exports = {
|
||||
* - userId: the user on behalf of whom the operation was performed
|
||||
* - message: a string detailing what happened
|
||||
*/
|
||||
async function addEntry(projectId, operation, initiatorId, info = {}) {
|
||||
async function addEntry(
|
||||
projectId,
|
||||
operation,
|
||||
initiatorId,
|
||||
ipAddress,
|
||||
info = {}
|
||||
) {
|
||||
const entry = {
|
||||
projectId,
|
||||
operation,
|
||||
initiatorId,
|
||||
ipAddress,
|
||||
info,
|
||||
}
|
||||
await ProjectAuditLogEntry.create(entry)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an audit log entry in the background
|
||||
*
|
||||
* This function doesn't return a promise. Instead, it catches any error and logs it.
|
||||
*/
|
||||
function addEntryInBackground(
|
||||
projectId,
|
||||
operation,
|
||||
initiatorId,
|
||||
ipAddress,
|
||||
info = {}
|
||||
) {
|
||||
addEntry(projectId, operation, initiatorId, ipAddress, info).catch(err => {
|
||||
logger.error(
|
||||
{ err, projectId, operation, initiatorId, ipAddress, info },
|
||||
'Failed to write audit log'
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user