mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
moved rename entity to proj entity handler
This commit is contained in:
parent
f28bd33168
commit
5378890e57
5 changed files with 46 additions and 22 deletions
|
@ -246,7 +246,7 @@ module.exports = EditorController =
|
|||
newName = sanitize.escape(newName)
|
||||
Metrics.inc "editor.rename-entity"
|
||||
logger.log entity_id:entity_id, entity_id:entity_id, entity_id:entity_id, "reciving new name for entity for project"
|
||||
ProjectHandler.renameEntity project_id, entity_id, entityType, newName, =>
|
||||
ProjectEntityHandler.renameEntity project_id, entity_id, entityType, newName, =>
|
||||
if newName.length > 0
|
||||
EditorRealTimeController.emitToRoom project_id, 'reciveEntityRename', entity_id, newName
|
||||
callback?()
|
||||
|
|
|
@ -283,6 +283,27 @@ module.exports = ProjectEntityHandler =
|
|||
return callback(error) if error?
|
||||
callback null
|
||||
|
||||
|
||||
renameEntity: (project_id, entity_id, entityType, newName, callback)->
|
||||
logger.log(entity_id: entity_id, project_id: project_id, ('renaming '+entityType))
|
||||
if !entityType?
|
||||
logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id
|
||||
return callback("No entityType set")
|
||||
entityType = entityType.toLowerCase()
|
||||
Project.findById project_id, (err, project)=>
|
||||
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path, folder)=>
|
||||
if err?
|
||||
return callback err
|
||||
conditons = {_id:project_id}
|
||||
update = "$set":{}
|
||||
namePath = path.mongo+".name"
|
||||
update["$set"][namePath] = newName
|
||||
endPath = path.fileSystem.replace(entity.name, newName)
|
||||
tpdsUpdateSender.moveEntity({project_id:project_id, startPath:path.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev})
|
||||
Project.update conditons, update, {}, (err)->
|
||||
if callback?
|
||||
callback err
|
||||
|
||||
_cleanUpEntity: (project, entity, entityType, sl_req_id, callback = (error) ->) ->
|
||||
{callback, sl_req_id} = slReqIdHelper.getCallbackAndReqId(callback, sl_req_id)
|
||||
|
||||
|
|
|
@ -19,25 +19,7 @@ tagsHandler = require('../Features/Tags/TagsHandler')
|
|||
|
||||
module.exports = class ProjectHandler
|
||||
|
||||
renameEntity: (project_id, entity_id, entityType, newName, callback)->
|
||||
logger.log(entity_id: entity_id, project_id: project_id, ('renaming '+entityType))
|
||||
if !entityType?
|
||||
logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id
|
||||
return callback("No entityType set")
|
||||
entityType = entityType.toLowerCase()
|
||||
Project.findById project_id, (err, project)=>
|
||||
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path, folder)=>
|
||||
if err?
|
||||
return callback err
|
||||
conditons = {_id:project_id}
|
||||
update = "$set":{}
|
||||
namePath = path.mongo+".name"
|
||||
update["$set"][namePath] = newName
|
||||
endPath = path.fileSystem.replace(entity.name, newName)
|
||||
tpdsUpdateSender.moveEntity({project_id:project_id, startPath:path.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev})
|
||||
Project.update conditons, update, {}, (err)->
|
||||
if callback?
|
||||
callback err
|
||||
|
||||
|
||||
renameProject: (project_id, window_id, newName, callback)->
|
||||
logger.log project_id: project_id, "renaming project"
|
||||
|
|
|
@ -629,12 +629,12 @@ describe "EditorController", ->
|
|||
@entity_id = "entity_id_here"
|
||||
@entityType = "doc"
|
||||
@newName = "bobsfile.tex"
|
||||
@ProjectHandler::renameEntity = sinon.stub().callsArgWith(4, @err)
|
||||
@ProjectEntityHandler.renameEntity = sinon.stub().callsArgWith(4, @err)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
|
||||
it "should call the project handler", (done)->
|
||||
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, =>
|
||||
@ProjectHandler::renameEntity.calledWith(@project_id, @entity_id, @entityType, @newName).should.equal true
|
||||
@ProjectEntityHandler.renameEntity.calledWith(@project_id, @entity_id, @entityType, @newName).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
|
|
|
@ -682,3 +682,24 @@ describe 'project entity handler', ->
|
|||
|
||||
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
||||
|
||||
|
||||
describe "renameEntity", ->
|
||||
beforeEach ->
|
||||
@entity_id = "4eecaffcbffa66588e000009"
|
||||
@entityType = "doc"
|
||||
@newName = "new.tex"
|
||||
@path = mongo: "mongo.path", fileSystem: "/file/system/old.tex"
|
||||
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: @entity_id, name:"old.tex", rev:4 }, @path)
|
||||
@ProjectModel.update = sinon.stub().callsArgWith(3)
|
||||
@tpdsUpdateSender.moveEntity = sinon.stub()
|
||||
|
||||
it "should update the name in mongo", (done)->
|
||||
|
||||
@ProjectEntityHandler.renameEntity @project_id, @entity_id, @entityType, @newName, =>
|
||||
@ProjectModel.update.calledWith({_id : @project_id}, {"$set":{"mongo.path.name":@newName}}).should.equal true
|
||||
done()
|
||||
|
||||
it "should send the update to the tpds", (done)->
|
||||
@ProjectEntityHandler.renameEntity @project_id, @entity_id, @entityType, @newName, =>
|
||||
@tpdsUpdateSender.moveEntity.calledWith({project_id:@project_id, startPath:@path.fileSystem, endPath:"/file/system/new.tex", project_name:@project.name, rev:4}).should.equal true
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue