mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 02:23:41 -05:00
Merge pull request #19318 from overleaf/mj-revert-check-ranges-support
[web] Check that project has ranges support when reverting GitOrigin-RevId: 761e435e9d640c08f27dd4ad2cef95934c0cc48b
This commit is contained in:
parent
778aa717d9
commit
0be042e331
2 changed files with 33 additions and 0 deletions
|
@ -14,6 +14,8 @@ const DocstoreManager = require('../Docstore/DocstoreManager')
|
|||
const logger = require('@overleaf/logger')
|
||||
const EditorRealTimeController = require('../Editor/EditorRealTimeController')
|
||||
const ChatManager = require('../Chat/ChatManager')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const ProjectGetter = require('../Project/ProjectGetter')
|
||||
|
||||
const RestoreManager = {
|
||||
async restoreFileFromV2(userId, projectId, version, pathname) {
|
||||
|
@ -48,6 +50,13 @@ const RestoreManager = {
|
|||
},
|
||||
|
||||
async revertFile(userId, projectId, version, pathname) {
|
||||
const project = await ProjectGetter.promises.getProject(projectId, {
|
||||
overleaf: true,
|
||||
})
|
||||
if (!project?.overleaf?.history?.rangesSupportEnabled) {
|
||||
throw new OError('project does not have ranges support', { projectId })
|
||||
}
|
||||
|
||||
const fsPath = await RestoreManager._writeFileVersionToDisk(
|
||||
projectId,
|
||||
version,
|
||||
|
|
|
@ -34,6 +34,7 @@ describe('RestoreManager', function () {
|
|||
'../Chat/ChatManager': (this.ChatManager = { promises: {} }),
|
||||
'../Editor/EditorRealTimeController': (this.EditorRealTimeController =
|
||||
{}),
|
||||
'../Project/ProjectGetter': (this.ProjectGetter = { promises: {} }),
|
||||
},
|
||||
})
|
||||
this.user_id = 'mock-user-id'
|
||||
|
@ -211,6 +212,10 @@ describe('RestoreManager', function () {
|
|||
|
||||
describe('revertFile', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.promises.getProject = sinon.stub()
|
||||
this.ProjectGetter.promises.getProject
|
||||
.withArgs(this.project_id)
|
||||
.resolves({ overleaf: { history: { rangesSupportEnabled: true } } })
|
||||
this.RestoreManager.promises._writeFileVersionToDisk = sinon
|
||||
.stub()
|
||||
.resolves((this.fsPath = '/tmp/path/on/disk'))
|
||||
|
@ -225,6 +230,25 @@ describe('RestoreManager', function () {
|
|||
.rejects()
|
||||
})
|
||||
|
||||
describe('reverting a project without ranges support', function () {
|
||||
beforeEach(function () {
|
||||
this.ProjectGetter.promises.getProject = sinon.stub().resolves({
|
||||
overleaf: { history: { rangesSupportEnabled: false } },
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw an error', async function () {
|
||||
await expect(
|
||||
this.RestoreManager.promises.revertFile(
|
||||
this.user_id,
|
||||
this.project_id,
|
||||
this.version,
|
||||
this.pathname
|
||||
)
|
||||
).to.eventually.be.rejectedWith('project does not have ranges support')
|
||||
})
|
||||
})
|
||||
|
||||
describe('reverting a document', function () {
|
||||
beforeEach(function () {
|
||||
this.pathname = 'foo.tex'
|
||||
|
|
Loading…
Reference in a new issue