Merge pull request #7307 from overleaf/jpa-notify-editor-restore-doc

[web] notify the editor after restoring a deleted doc

GitOrigin-RevId: 4bd316958827c83a56a82f9ff72f5ff803d32631
This commit is contained in:
Jakob Ackermann 2022-03-31 08:55:51 +01:00 committed by Copybot
parent 2677984b93
commit 64ffd66fa4
3 changed files with 11 additions and 8 deletions

View file

@ -1,7 +1,7 @@
const { callbackify } = require('util') const { callbackify } = require('util')
const Path = require('path') const Path = require('path')
const ProjectEntityHandler = require('./ProjectEntityHandler') const ProjectEntityHandler = require('./ProjectEntityHandler')
const ProjectEntityUpdateHandler = require('./ProjectEntityUpdateHandler') const EditorController = require('../Editor/EditorController')
// generate a new name based on the original, with an optional label. // generate a new name based on the original, with an optional label.
// e.g. origname-20210101-122345.tex (default) // e.g. origname-20210101-122345.tex (default)
@ -24,12 +24,14 @@ async function restoreDeletedDoc(projectId, docId, docName, userId) {
{ include_deleted: true } { include_deleted: true }
) )
const deletedDocName = generateRestoredName(docName) const deletedDocName = generateRestoredName(docName)
return await ProjectEntityUpdateHandler.promises.addDocWithRanges( // Create the doc and emit a websocket message.
return await EditorController.promises.addDocWithRanges(
projectId, projectId,
null, null,
`${deletedDocName}`, `${deletedDocName}`,
deletedDoc.lines, deletedDoc.lines,
deletedDoc.ranges, deletedDoc.ranges,
null,
userId userId
) )
} }

View file

@ -386,7 +386,7 @@ const ProjectEntityUpdateHandler = {
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
callback(null, doc, folderId) callback(null, doc, folderId || project.rootFolder[0]._id)
} }
) )
} }

View file

@ -33,7 +33,7 @@ describe('ProjectEntityRestoreHandler', function () {
}, },
} }
this.ProjectEntityUpdateHandler = { this.EditorController = {
promises: { promises: {
addDocWithRanges: sinon.stub(), addDocWithRanges: sinon.stub(),
}, },
@ -42,7 +42,7 @@ describe('ProjectEntityRestoreHandler', function () {
this.ProjectEntityRestoreHandler = SandboxedModule.require(MODULE_PATH, { this.ProjectEntityRestoreHandler = SandboxedModule.require(MODULE_PATH, {
requires: { requires: {
'./ProjectEntityHandler': this.ProjectEntityHandler, './ProjectEntityHandler': this.ProjectEntityHandler,
'./ProjectEntityUpdateHandler': this.ProjectEntityUpdateHandler, '../Editor/EditorController': this.EditorController,
}, },
}) })
}) })
@ -68,9 +68,9 @@ describe('ProjectEntityRestoreHandler', function () {
ranges: this.ranges, ranges: this.ranges,
}) })
this.ProjectEntityUpdateHandler.addDocWithRanges = sinon this.EditorController.promises.addDocWithRanges = sinon
.stub() .stub()
.yields(null, this.newDoc) .resolves(this.newDoc)
await this.ProjectEntityRestoreHandler.promises.restoreDeletedDoc( await this.ProjectEntityRestoreHandler.promises.restoreDeletedDoc(
this.project._id, this.project._id,
@ -82,13 +82,14 @@ describe('ProjectEntityRestoreHandler', function () {
const docNameMatcher = new RegExp(docName + '-\\d{4}-\\d{2}-\\d{2}-\\d+') const docNameMatcher = new RegExp(docName + '-\\d{4}-\\d{2}-\\d{2}-\\d+')
expect( expect(
this.ProjectEntityUpdateHandler.promises.addDocWithRanges this.EditorController.promises.addDocWithRanges
).to.have.been.calledWith( ).to.have.been.calledWith(
this.project._id, this.project._id,
null, null,
sinon.match(docNameMatcher), sinon.match(docNameMatcher),
this.docLines, this.docLines,
this.ranges, this.ranges,
null,
this.user._id this.user._id
) )
}) })