diff --git a/services/web/app/src/Features/Documents/DocumentController.js b/services/web/app/src/Features/Documents/DocumentController.js index 1d89b2f1f7..f7eed9ac60 100644 --- a/services/web/app/src/Features/Documents/DocumentController.js +++ b/services/web/app/src/Features/Documents/DocumentController.js @@ -69,12 +69,21 @@ module.exports = { return res.send(lines.join('\n')) } else { const projectHistoryId = _.get(project, 'overleaf.history.id') - const projectHistoryType = _.get( + const projectHistoryDisplay = _.get( project, 'overleaf.history.display' ) - ? 'project-history' - : undefined // for backwards compatibility, don't send anything if the project is still on track-changes + const sendToBothHistorySystems = _.get( + project, + 'overleaf.history.allowDowngrade' + ) + // if project has been switched but has 'allowDowngrade' set + // then leave projectHistoryType undefined to (temporarily) + // continue sending updates to both SL and full project history + const projectHistoryType = + projectHistoryDisplay && !sendToBothHistorySystems + ? 'project-history' + : undefined // for backwards compatibility, don't send anything if the project is still on track-changes return res.json({ lines, version, diff --git a/services/web/test/unit/src/Documents/DocumentControllerTests.js b/services/web/test/unit/src/Documents/DocumentControllerTests.js index 4eedcf7006..a2bf7082f9 100644 --- a/services/web/test/unit/src/Documents/DocumentControllerTests.js +++ b/services/web/test/unit/src/Documents/DocumentControllerTests.js @@ -191,6 +191,60 @@ describe('DocumentController', function () { }) }) + describe('when project exists that was migrated with downgrades allowed', function () { + beforeEach(function () { + this.doc = { _id: this.doc_id } + this.projectHistoryId = 1234 + this.projectHistoryDisplay = true + this.projectHistoryType = undefined + this.project = { + _id: this.project_id, + overleaf: { + history: { + id: this.projectHistoryId, + display: this.projectHistoryDisplay, + allowDowngrade: true, + }, + }, + } + this.ProjectGetter.getProject = sinon + .stub() + .callsArgWith(2, null, this.project) + this.ProjectLocator.findElement = sinon + .stub() + .callsArgWith(1, null, this.doc, { fileSystem: this.pathname }) + this.ProjectEntityHandler.getDoc = sinon + .stub() + .callsArgWith( + 2, + null, + this.doc_lines, + this.rev, + this.version, + this.ranges + ) + return this.DocumentController.getDocument( + this.req, + this.res, + this.next + ) + }) + + it('should return the history id in the JSON but not history type, sending history to both services', function () { + this.res.type.should.equal('application/json') + return this.res.body.should.equal( + JSON.stringify({ + lines: this.doc_lines, + version: this.version, + ranges: this.ranges, + pathname: this.pathname, + projectHistoryId: this.projectHistoryId, + projectHistoryType: this.projectHistoryType, + }) + ) + }) + }) + describe('when the project does not exist', function () { beforeEach(function () { this.ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)