Files
overleaf-cep/services/web/app/src/Features/Project/ProjectAuditLogHandler.mjs
Antoine Clausse 71f0b28a84 [web] Convert some Features files to ES modules (part 3) (#28494)
* Rename files to mjs

* Rename test files to mjs

* Update CODEOWNERS

* Update files to ESM

* Update test files to ESM

* Update RestoreManager.test.mjs

* Remove unused `AdminAuthorizationHelper` mock and stub

* Remove unnecessary return

GitOrigin-RevId: 2b9ef126de1d8964afbc6e5641cca36712655866
2025-09-17 08:05:02 +00:00

58 lines
1.2 KiB
JavaScript

import logger from '@overleaf/logger'
import { ProjectAuditLogEntry } from '../../models/ProjectAuditLogEntry.js'
import { callbackify } from '@overleaf/promise-utils'
export default {
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'
)
})
}