Merge pull request #2267 from overleaf/em-audit-log-admin

Show project audit logs in admin panel

GitOrigin-RevId: f0dae4621ed8d62c8d0424f5f8f5612dc16c3eb5
This commit is contained in:
Eric Mc Sween 2019-10-23 08:24:01 -04:00 committed by sharelatex
parent dad0b56813
commit f6e4be616c
7 changed files with 75 additions and 8 deletions

View file

@ -13,7 +13,6 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let EditorController
const logger = require('logger-sharelatex') const logger = require('logger-sharelatex')
const Metrics = require('metrics-sharelatex') const Metrics = require('metrics-sharelatex')
const sanitize = require('sanitizer') const sanitize = require('sanitizer')
@ -26,8 +25,9 @@ const EditorRealTimeController = require('./EditorRealTimeController')
const async = require('async') const async = require('async')
const PublicAccessLevels = require('../Authorization/PublicAccessLevels') const PublicAccessLevels = require('../Authorization/PublicAccessLevels')
const _ = require('underscore') const _ = require('underscore')
const { promisifyAll } = require('../../util/promises')
module.exports = EditorController = { const EditorController = {
addDoc(project_id, folder_id, docName, docLines, source, user_id, callback) { addDoc(project_id, folder_id, docName, docLines, source, user_id, callback) {
if (callback == null) { if (callback == null) {
callback = function(error, doc) {} callback = function(error, doc) {}
@ -725,3 +725,6 @@ module.exports = EditorController = {
return callback() return callback()
} }
} }
EditorController.promises = promisifyAll(EditorController)
module.exports = EditorController

View file

@ -14,13 +14,13 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let HistoryManager
const request = require('request') const request = require('request')
const settings = require('settings-sharelatex') const settings = require('settings-sharelatex')
const async = require('async') const async = require('async')
const UserGetter = require('../User/UserGetter') const UserGetter = require('../User/UserGetter')
const { promisifyAll } = require('../../util/promises')
module.exports = HistoryManager = { const HistoryManager = {
initializeProject(callback) { initializeProject(callback) {
if (callback == null) { if (callback == null) {
callback = function(error, history_id) {} callback = function(error, history_id) {}
@ -219,3 +219,6 @@ function __guard__(value, transform) {
? transform(value) ? transform(value)
: undefined : undefined
} }
HistoryManager.promises = promisifyAll(HistoryManager, { without: '_userView' })
module.exports = HistoryManager

View file

@ -13,15 +13,15 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let ProjectHistoryHandler
const { Project } = require('../../models/Project') const { Project } = require('../../models/Project')
const ProjectDetailsHandler = require('./ProjectDetailsHandler') const ProjectDetailsHandler = require('./ProjectDetailsHandler')
const logger = require('logger-sharelatex') const logger = require('logger-sharelatex')
const settings = require('settings-sharelatex') const settings = require('settings-sharelatex')
const HistoryManager = require('../History/HistoryManager') const HistoryManager = require('../History/HistoryManager')
const ProjectEntityUpdateHandler = require('./ProjectEntityUpdateHandler') const ProjectEntityUpdateHandler = require('./ProjectEntityUpdateHandler')
const { promisifyAll } = require('../../util/promises')
module.exports = ProjectHistoryHandler = { const ProjectHistoryHandler = {
setHistoryId(project_id, history_id, callback) { setHistoryId(project_id, history_id, callback) {
// reject invalid history ids // reject invalid history ids
if (callback == null) { if (callback == null) {
@ -171,3 +171,6 @@ function __guard__(value, transform) {
? transform(value) ? transform(value)
: undefined : undefined
} }
ProjectHistoryHandler.promises = promisifyAll(ProjectHistoryHandler)
module.exports = ProjectHistoryHandler

View file

@ -1,10 +1,11 @@
const { Project } = require('../../models/Project') const { Project } = require('../../models/Project')
const logger = require('logger-sharelatex') const logger = require('logger-sharelatex')
const settings = require('settings-sharelatex') const settings = require('settings-sharelatex')
const { promisifyAll } = require('../../util/promises')
const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex'] const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex']
module.exports = { const ProjectOptionsHandler = {
setCompiler(projectId, compiler, callback) { setCompiler(projectId, compiler, callback) {
logger.log({ projectId, compiler }, 'setting the compiler') logger.log({ projectId, compiler }, 'setting the compiler')
if (!compiler) { if (!compiler) {
@ -72,3 +73,6 @@ module.exports = {
Project.update(conditions, update, {}, callback) Project.update(conditions, update, {}, callback)
} }
} }
ProjectOptionsHandler.promises = promisifyAll(ProjectOptionsHandler)
module.exports = ProjectOptionsHandler

View file

@ -0,0 +1,18 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
const DocSnapshotSchema = new Schema(
{
project_id: Schema.Types.ObjectId,
doc_id: Schema.Types.ObjectId,
version: Number,
lines: [String],
pathname: String,
ranges: Schema.Types.Mixed,
ts: Date
},
{ collection: 'docSnapshots' }
)
exports.DocSnapshot = mongoose.model('DocSnapshot', DocSnapshotSchema)

View file

@ -0,0 +1,24 @@
const mongoose = require('mongoose')
const { Schema } = mongoose
const ProjectHistoryFailureSchema = new Schema(
{
project_id: Schema.Types.ObjectId,
ts: Date,
queueSize: Number,
error: String,
stack: String,
attempts: Number,
history: Schema.Types.Mixed,
resyncStartedAt: Date,
resyncAttempts: Number,
requestCount: Number
},
{ collection: 'projectHistoryFailures' }
)
exports.ProjectHistoryFailure = mongoose.model(
'ProjectHistoryFailure',
ProjectHistoryFailureSchema
)

View file

@ -1,8 +1,10 @@
const { promisify } = require('util') const { promisify } = require('util')
const pLimit = require('p-limit')
module.exports = { module.exports = {
promisifyAll, promisifyAll,
expressify expressify,
promiseMapWithLimit
} }
/** /**
@ -43,3 +45,13 @@ function expressify(fn) {
fn(req, res, next).catch(next) fn(req, res, next).catch(next)
} }
} }
/**
* Map values in `array` with the async function `fn`
*
* Limit the number of unresolved promises to `concurrency`.
*/
function promiseMapWithLimit(concurrency, array, fn) {
const limit = pLimit(concurrency)
return Promise.all(array.map(x => limit(() => fn(x))))
}