[web] Add audit log entries for project-history-version-restore and project-history-version-download

GitOrigin-RevId: 8cfe1fee733aa886cd6518d352abd95bd9da6f77
This commit is contained in:
Simon Gardner
2026-01-14 09:12:02 +00:00
committed by Copybot
parent 3f7555e5a0
commit bb7b8ee227
3 changed files with 62 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import RestoreManager from './RestoreManager.mjs'
import { prepareZipAttachment } from '../../infrastructure/Response.mjs'
import Features from '../../infrastructure/Features.mjs'
import { z, zz, validateReq } from '../../infrastructure/Validation.mjs'
import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.mjs'
// Number of seconds after which the browser should send a request to revalidate
// blobs
@@ -192,6 +193,19 @@ async function restoreFileFromV2(req, res, next) {
pathname
)
ProjectAuditLogHandler.addEntryIfManagedInBackground(
projectId,
'project-history-version-restored',
userId,
req.ip,
{
version,
scope: 'file',
pathname,
restoredEntityId: entity._id,
}
)
res.json({
type: entity.type,
id: entity._id,
@@ -211,6 +225,19 @@ async function revertFile(req, res, next) {
{}
)
ProjectAuditLogHandler.addEntryIfManagedInBackground(
projectId,
'project-history-version-restored',
userId,
req.ip,
{
version,
scope: 'file',
pathname,
restoredEntityId: entity._id,
}
)
res.json({
type: entity.type,
id: entity._id,
@@ -228,6 +255,18 @@ async function revertProject(req, res, next) {
version
)
ProjectAuditLogHandler.addEntryIfManagedInBackground(
projectId,
'project-history-version-restored',
userId,
req.ip,
{
version,
scope: 'project',
restoredEntities: reverted,
}
)
res.json(reverted)
}
@@ -346,6 +385,7 @@ async function deleteLabel(req, res, next) {
async function downloadZipOfVersion(req, res, next) {
const { project_id: projectId, version } = req.params
const userId = SessionManager.getLoggedInUserId(req.session)
const project = await ProjectDetailsHandler.promises.getDetails(projectId)
const v1Id =
@@ -366,6 +406,17 @@ async function downloadZipOfVersion(req, res, next) {
req,
res
)
ProjectAuditLogHandler.addEntryIfManagedInBackground(
projectId,
'project-history-version-downloaded',
userId,
req.ip,
{
version,
projectName: project.name,
}
)
}
async function _pipeHistoryZipToResponse(v1ProjectId, version, name, req, res) {

View File

@@ -15,6 +15,8 @@ const MANAGED_GROUP_PROJECT_EVENTS = [
'project-untrashed',
'project-restored',
'project-cloned',
'project-history-version-restored',
'project-history-version-downloaded',
'transfer-ownership',
'project-downloaded',
]

View File

@@ -103,6 +103,15 @@ describe('HistoryController', function () {
})
)
vi.doMock(
'../../../../app/src/Features/Project/ProjectAuditLogHandler.mjs',
() => ({
default: (ctx.ProjectAuditLogHandler = {
addEntryIfManagedInBackground: sinon.stub(),
}),
})
)
vi.doMock('../../../../app/src/Features/User/UserGetter.mjs', () => ({
default: (ctx.UserGetter = {}),
}))