diff --git a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee index 30e573ea42..c4992a29f8 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee @@ -456,14 +456,14 @@ module.exports = ProjectEntityHandler = return callback(error) if error? ProjectEntityHandler.getAllEntitiesFromProject project, (error, oldDocs, oldFiles) => return callback(error) if error? - projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (error, entity, path)=> + projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (error, entity, entPath)=> return callback(error) if error? - endPath = path.fileSystem.replace(entity.name, newName) + endPath = path.join(path.dirname(entPath.fileSystem), newName) conditions = {_id:project_id} update = "$set":{} - namePath = path.mongo+".name" + namePath = entPath.mongo+".name" update["$set"][namePath] = newName - tpdsUpdateSender.moveEntity({project_id:project_id, startPath:path.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev}) + tpdsUpdateSender.moveEntity({project_id:project_id, startPath:entPath.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev}) Project.findOneAndUpdate conditions, update, { "new": true}, (error, newProject) -> return callback(error) if error? ProjectEntityHandler.getAllEntitiesFromProject newProject, (error, newDocs, newFiles) => diff --git a/services/web/test/unit/coffee/Project/ProjectEntityHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityHandlerTests.coffee index a4ac6a7f02..3b6a6e8626 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityHandlerTests.coffee @@ -1121,7 +1121,7 @@ describe 'ProjectEntityHandler', -> @entity_id = "4eecaffcbffa66588e000009" @entityType = "doc" @newName = "new.tex" - @path = mongo: "mongo.path", fileSystem: "/file/system/old.tex" + @path = mongo: "mongo.path", fileSystem: "/oldnamepath/oldname" @ProjectGetter.getProject.callsArgWith(2, null, @project) @ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub() @@ -1132,7 +1132,7 @@ describe 'ProjectEntityHandler', -> .onSecondCall() .callsArgWith(1, null, @newDocs = ['new-doc'], @newFiles = ['new-file']) - @projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: @entity_id, name:"old.tex", rev:4 }, @path) + @projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: @entity_id, name:"oldname", rev:4 }, @path) @tpdsUpdateSender.moveEntity = sinon.stub() @ProjectModel.findOneAndUpdate = sinon.stub().callsArgWith(3, null, @project) @documentUpdaterHandler.updateProjectStructure = sinon.stub().yields() @@ -1151,7 +1151,7 @@ describe 'ProjectEntityHandler', -> it "should send the update to the tpds", (done)-> @ProjectEntityHandler.renameEntity project_id, @entity_id, @entityType, @newName, userId, => - @tpdsUpdateSender.moveEntity.calledWith({project_id:project_id, startPath:@path.fileSystem, endPath:"/file/system/new.tex", project_name:@project.name, rev:4}).should.equal true + @tpdsUpdateSender.moveEntity.calledWith({project_id:project_id, startPath:@path.fileSystem, endPath:"/oldnamepath/new.tex", project_name:@project.name, rev:4}).should.equal true done() describe "_insertDeletedDocReference", -> @@ -1348,8 +1348,3 @@ describe 'ProjectEntityHandler', -> @ProjectEntityHandler._countElements @project, (err, count)-> count.should.equal 23 done() - - - - -