mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
[web] project-downloaded audit logs (#30075)
Adds new `project-downloaded` and makes it available to managed group admin. GitOrigin-RevId: 5ae406182f87590acf300f8095a6c7e6c25366c0
This commit is contained in:
@@ -1,81 +1,73 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
import Metrics from '@overleaf/metrics'
|
||||
import ProjectGetter from '../Project/ProjectGetter.mjs'
|
||||
import ProjectZipStreamManager from './ProjectZipStreamManager.mjs'
|
||||
import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.mjs'
|
||||
import { prepareZipAttachment } from '../../infrastructure/Response.mjs'
|
||||
|
||||
let ProjectDownloadsController
|
||||
import SessionManager from '../Authentication/SessionManager.mjs'
|
||||
import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.mjs'
|
||||
|
||||
// Keep in sync with the logic for PDF files in CompileController
|
||||
function getSafeProjectName(project) {
|
||||
return project.name.replace(/[^\p{L}\p{Nd}]/gu, '_')
|
||||
}
|
||||
|
||||
export default ProjectDownloadsController = {
|
||||
export default {
|
||||
downloadProject(req, res, next) {
|
||||
const userId = SessionManager.getSessionUser(req.session)
|
||||
const projectId = req.params.Project_id
|
||||
Metrics.inc('zip-downloads')
|
||||
return DocumentUpdaterHandler.flushProjectToMongo(
|
||||
projectId,
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return ProjectGetter.getProject(
|
||||
projectId,
|
||||
{ name: true },
|
||||
function (error, project) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
return ProjectZipStreamManager.createZipStreamForProject(
|
||||
projectId,
|
||||
function (error, stream) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
prepareZipAttachment(res, `${getSafeProjectName(project)}.zip`)
|
||||
return stream.pipe(res)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
DocumentUpdaterHandler.flushProjectToMongo(projectId, function (error) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
)
|
||||
ProjectGetter.getProject(
|
||||
projectId,
|
||||
{ name: true },
|
||||
function (error, project) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
ProjectAuditLogHandler.addEntryInBackground(
|
||||
projectId,
|
||||
'project-downloaded',
|
||||
userId,
|
||||
req.ip
|
||||
)
|
||||
ProjectZipStreamManager.createZipStreamForProject(
|
||||
projectId,
|
||||
function (error, stream) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
prepareZipAttachment(res, `${getSafeProjectName(project)}.zip`)
|
||||
stream.pipe(res)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
},
|
||||
|
||||
downloadMultipleProjects(req, res, next) {
|
||||
const projectIds = req.query.project_ids.split(',')
|
||||
Metrics.inc('zip-downloads-multiple')
|
||||
return DocumentUpdaterHandler.flushMultipleProjectsToMongo(
|
||||
DocumentUpdaterHandler.flushMultipleProjectsToMongo(
|
||||
projectIds,
|
||||
function (error) {
|
||||
if (error != null) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
return ProjectZipStreamManager.createZipStreamForMultipleProjects(
|
||||
ProjectZipStreamManager.createZipStreamForMultipleProjects(
|
||||
projectIds,
|
||||
function (error, stream) {
|
||||
if (error != null) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
prepareZipAttachment(
|
||||
res,
|
||||
`Overleaf Projects (${projectIds.length} items).zip`
|
||||
)
|
||||
return stream.pipe(res)
|
||||
stream.pipe(res)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ const MANAGED_GROUP_PROJECT_EVENTS = [
|
||||
'project-restored',
|
||||
'project-cloned',
|
||||
'transfer-ownership',
|
||||
'project-downloaded',
|
||||
]
|
||||
|
||||
async function findManagedSubscriptions(entry) {
|
||||
|
||||
Reference in New Issue
Block a user