mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 10:10:08 +02:00
Move util/promises from web into a shared library GitOrigin-RevId: fe1980dc57b9dc8ce86fa1fad6a8a817e9505b3d
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const logger = require('@overleaf/logger')
|
|
const { ProjectAuditLogEntry } = require('../../models/ProjectAuditLogEntry')
|
|
const { callbackify } = require('@overleaf/promise-utils')
|
|
|
|
module.exports = {
|
|
promises: {
|
|
addEntry,
|
|
},
|
|
addEntry: callbackify(addEntry), // callback version of addEntry
|
|
addEntryInBackground,
|
|
}
|
|
|
|
/**
|
|
* Add an audit log entry
|
|
*
|
|
* The entry should include at least the following fields:
|
|
*
|
|
* - operation: a string identifying the type of operation
|
|
* - userId: the user on behalf of whom the operation was performed
|
|
* - message: a string detailing what happened
|
|
*/
|
|
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'
|
|
)
|
|
})
|
|
}
|