mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #242 from sharelatex/rename-entity-bugfix
Ensure the dirname is not affected when we rename an entity
This commit is contained in:
commit
feaa7c6d3f
2 changed files with 7 additions and 12 deletions
|
@ -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) =>
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue