Merge pull request #4690 from overleaf/tm-upgraded-history-allow-downgrade

Projects migrated to full project history should send history to both systems if allowDowngrade is set

GitOrigin-RevId: 52c46345eb8606e363ae85727d29e87f35cea37d
This commit is contained in:
Eric Mc Sween 2021-08-18 08:38:23 -04:00 committed by Copybot
parent b2e6eaf936
commit 84559790f2
2 changed files with 66 additions and 3 deletions

View file

@ -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,

View file

@ -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)