From 67b8719bf21ffcb0ab3fba7d8ec8ed49d9661a70 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 5 Nov 2020 11:07:02 +0100 Subject: [PATCH] Merge pull request #3354 from overleaf/jpa-fix-clone-invalid-root-doc [ProjectDuplicator] silently ignore an invalid rootDoc when duplicating GitOrigin-RevId: 93b4d4193fab25484525f8ab2c692e047cf0da30 --- .../src/Features/Project/ProjectDuplicator.js | 6 +++++- .../unit/src/Project/ProjectDuplicatorTests.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/services/web/app/src/Features/Project/ProjectDuplicator.js b/services/web/app/src/Features/Project/ProjectDuplicator.js index 625698c6b4..26c8478790 100644 --- a/services/web/app/src/Features/Project/ProjectDuplicator.js +++ b/services/web/app/src/Features/Project/ProjectDuplicator.js @@ -60,7 +60,11 @@ async function duplicate(owner, originalProjectId, newProjectName) { docEntries, fileEntries ) - if (rootDocPath) { + // Silently ignore the rootDoc in case it's not valid per the new limits. + if ( + rootDocPath && + ProjectEntityUpdateHandler.isPathValidForRootDoc(rootDocPath.fileSystem) + ) { await _setRootDoc(newProject._id, rootDocPath.fileSystem) } await _notifyDocumentUpdater(newProject, owner._id, { diff --git a/services/web/test/unit/src/Project/ProjectDuplicatorTests.js b/services/web/test/unit/src/Project/ProjectDuplicatorTests.js index 842564c18d..967f1c4e02 100644 --- a/services/web/test/unit/src/Project/ProjectDuplicatorTests.js +++ b/services/web/test/unit/src/Project/ProjectDuplicatorTests.js @@ -159,6 +159,7 @@ describe('ProjectDuplicator', function() { } } this.ProjectEntityUpdateHandler = { + isPathValidForRootDoc: sinon.stub().returns(true), promises: { setRootDoc: sinon.stub().resolves() } @@ -340,6 +341,22 @@ describe('ProjectDuplicator', function() { }) }) + describe('with an invalid root doc', function() { + beforeEach(async function() { + this.ProjectEntityUpdateHandler.isPathValidForRootDoc.returns(false) + this.newProject = await this.ProjectDuplicator.promises.duplicate( + this.owner, + this.project._id, + 'Copy of project' + ) + }) + + it('should not set the root doc on the copy', function() { + this.ProjectEntityUpdateHandler.promises.setRootDoc.should.not.have.been + .called + }) + }) + describe('when there is an error', function() { beforeEach(async function() { this.ProjectEntityMongoUpdateHandler.promises.createNewFolderStructure.rejects()