Merge pull request #22652 from overleaf/ar-handle-filestore-404-when-copying-in-saas

[web] Do not do filestore copy in SAAS

GitOrigin-RevId: 83456ca57f706246a86b997a038968aecfbae4c5
This commit is contained in:
Andrew Rumble
2024-12-24 09:04:48 +00:00
committed by Copybot
parent 20c6989074
commit e64e69f539
6 changed files with 142 additions and 22 deletions
@@ -20,6 +20,7 @@ const SafePath = require('./SafePath')
const TpdsProjectFlusher = require('../ThirdPartyDataStore/TpdsProjectFlusher')
const _ = require('lodash')
const TagsHandler = require('../Tags/TagsHandler')
const Features = require('../../infrastructure/Features')
module.exports = {
duplicate: callbackify(duplicate),
@@ -233,12 +234,16 @@ async function _copyFiles(sourceEntries, sourceProject, targetProject) {
)
}
}
if (createdBlob && Features.hasFeature('saas')) {
return { createdBlob, file, path, url: null }
}
const url = await FileStoreHandler.promises.copyFile(
sourceProject._id,
sourceFile._id,
targetProject._id,
file._id
)
return { createdBlob, file, path, url }
}
)
@@ -8,6 +8,7 @@ import _ from 'lodash'
import ProjectGetter from '../../../../../app/src/Features/Project/ProjectGetter.js'
import User from '../../../../../test/acceptance/src/helpers/User.js'
import MockDocUpdaterApiClass from '../../../../../test/acceptance/src/mocks/MockDocUpdaterApi.js'
import Features from '../../../../../app/src/infrastructure/Features.js'
const { ObjectId } = mongodb
@@ -256,7 +257,11 @@ describe('ProjectStructureChanges', function () {
expect(updates[2].type).to.equal('add-file')
expect(updates[2].userId).to.equal(owner._id)
expect(updates[2].pathname).to.equal('/frog.jpg')
expect(updates[2].url).to.be.a('string')
if (Features.hasFeature('saas')) {
expect(updates[2].url).to.be.null
} else {
expect(updates[2].url).to.be.a('string')
}
expect(version).to.equal(1)
})
})
@@ -120,7 +120,7 @@ describe('ProjectDuplicator', function () {
createdBlob: true,
path: this.file2Path,
file: this.newFile2,
url: this.filestoreUrl,
url: null,
},
]
@@ -304,7 +304,7 @@ describe('ProjectDuplicator', function () {
})
it('should copy files to the filestore', function () {
for (const file of [this.file0, this.file1, this.file2]) {
for (const file of [this.file0, this.file1]) {
this.FileStoreHandler.promises.copyFile.should.have.been.calledWith(
this.project._id,
file._id,
@@ -314,6 +314,15 @@ describe('ProjectDuplicator', function () {
}
})
it('should not copy files that have been sent to history-v1 to the filestore', function () {
this.FileStoreHandler.promises.copyFile.should.not.have.been.calledWith(
this.project._id,
this.file2._id,
this.newProject._id,
this.newFileId
)
})
it('should create a blank project', function () {
this.ProjectCreationHandler.promises.createBlankProject.should.have.been.calledWith(
this.owner._id,