From 0be042e33143ab6a7313f19972c82a9ce0ffed90 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween <5454374+emcsween@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:39:09 -0400 Subject: [PATCH] Merge pull request #19318 from overleaf/mj-revert-check-ranges-support [web] Check that project has ranges support when reverting GitOrigin-RevId: 761e435e9d640c08f27dd4ad2cef95934c0cc48b --- .../src/Features/History/RestoreManager.js | 9 +++++++ .../unit/src/History/RestoreManagerTests.js | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/services/web/app/src/Features/History/RestoreManager.js b/services/web/app/src/Features/History/RestoreManager.js index e73406db26..95a0a1c9f3 100644 --- a/services/web/app/src/Features/History/RestoreManager.js +++ b/services/web/app/src/Features/History/RestoreManager.js @@ -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, diff --git a/services/web/test/unit/src/History/RestoreManagerTests.js b/services/web/test/unit/src/History/RestoreManagerTests.js index 430329ff3f..96d3156ac3 100644 --- a/services/web/test/unit/src/History/RestoreManagerTests.js +++ b/services/web/test/unit/src/History/RestoreManagerTests.js @@ -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'