Merge pull request #9617 from overleaf/msm-audit-log-collections

Move project/user audit logs to their own collections

GitOrigin-RevId: f6f89b3e2815c0fe5691a79eceb35b77b3c370d8
This commit is contained in:
Miguel Serrano
2022-09-29 11:47:50 +02:00
committed by Copybot
parent 9c7aa36e7e
commit 694cb665da
19 changed files with 298 additions and 156 deletions

View File

@@ -1,7 +1,4 @@
const OError = require('@overleaf/o-error')
const { Project } = require('../../models/Project')
const MAX_AUDIT_LOG_ENTRIES = 200
const { ProjectAuditLogEntry } = require('../../models/ProjectAuditLogEntry')
module.exports = {
promises: {
@@ -19,22 +16,11 @@ module.exports = {
* - message: a string detailing what happened
*/
async function addEntry(projectId, operation, initiatorId, info = {}) {
const timestamp = new Date()
const entry = {
projectId,
operation,
initiatorId,
timestamp,
info,
}
const result = await Project.updateOne(
{ _id: projectId },
{
$push: {
auditLog: { $each: [entry], $slice: -MAX_AUDIT_LOG_ENTRIES },
},
}
).exec()
if (result.nModified === 0) {
throw new OError('project not found', { projectId })
}
await ProjectAuditLogEntry.create(entry)
}