Merge pull request #28567 from overleaf/bg-fix-project-locator-root-folder

respect elementType when matching rootFolder in findElement

GitOrigin-RevId: f4e20ee6441fc16915297b2ac24737ed63398027
This commit is contained in:
Brian Gough
2025-09-19 08:57:32 +01:00
committed by Copybot
parent d75f4b3a7b
commit 9d28e4ab91
2 changed files with 28 additions and 1 deletions
@@ -95,7 +95,10 @@ function findElement(options, _callback) {
const path = { fileSystem: '', mongo: 'rootFolder.0' }
const startSearch = project => {
if (elementId + '' === project.rootFolder[0]._id + '') {
if (
elementId + '' === project.rootFolder[0]._id + '' &&
elementType === 'folders'
) {
callback(null, project.rootFolder[0], path, null)
} else {
search(project.rootFolder[0], path)
@@ -112,6 +112,30 @@ describe('ProjectLocator', function () {
foundElement._id.should.equal(rootFolder._id)
})
it('should not return root folder when searching for docs', async function () {
await expect(
this.locator.promises.findElement({
project_id: project._id,
element_id: rootFolder._id,
type: 'docs',
})
)
.to.eventually.be.rejectedWith(Errors.NotFoundError)
.and.eventually.have.property('message', 'entity not found')
})
it('should not return root folder when searching for files', async function () {
await expect(
this.locator.promises.findElement({
project_id: project._id,
element_id: rootFolder._id,
type: 'files',
})
)
.to.eventually.be.rejectedWith(Errors.NotFoundError)
.and.eventually.have.property('message', 'entity not found')
})
it('when at root', async function () {
const {
element: foundElement,