Merge pull request #682 from sharelatex/sk-copy-linked-file-data-on-clone

Copy linkedFileData when cloning a project
This commit is contained in:
Shane Kilkelly 2018-06-22 13:22:45 +01:00 committed by GitHub
commit d76c6c2c22
2 changed files with 37 additions and 3 deletions

View file

@ -55,7 +55,10 @@ module.exports = ProjectEntityUpdateHandler = self =
logger.err { project_id, folder_id, originalProject_id, origonalFileRef }, "file trying to copy is null" logger.err { project_id, folder_id, originalProject_id, origonalFileRef }, "file trying to copy is null"
return callback() return callback()
# convert any invalid characters in original file to '_' # convert any invalid characters in original file to '_'
fileRef = new File name : SafePath.clean(origonalFileRef.name) fileProperties = name : SafePath.clean(origonalFileRef.name)
if origonalFileRef.linkedFileData?
fileProperties.linkedFileData = origonalFileRef.linkedFileData
fileRef = new File(fileProperties)
FileStoreHandler.copyFile originalProject_id, origonalFileRef._id, project._id, fileRef._id, (err, fileStoreUrl)-> FileStoreHandler.copyFile originalProject_id, origonalFileRef._id, project._id, fileRef._id, (err, fileStoreUrl)->
if err? if err?
logger.err { err, project_id, folder_id, originalProject_id, origonalFileRef }, "error coping file in s3" logger.err { err, project_id, folder_id, originalProject_id, origonalFileRef }, "error coping file in s3"

View file

@ -44,6 +44,8 @@ describe 'ProjectEntityUpdateHandler', ->
else else
@._id = file_id @._id = file_id
@rev = 0 @rev = 0
if options.linkedFileData?
@linkedFileData = options.linkedFileData
@docName = "doc-name" @docName = "doc-name"
@docLines = ['1234','abc'] @docLines = ['1234','abc']
@ -121,6 +123,35 @@ describe 'ProjectEntityUpdateHandler', ->
.calledWithMatch(project_id, projectHistoryId, userId, changesMatcher) .calledWithMatch(project_id, projectHistoryId, userId, changesMatcher)
.should.equal true .should.equal true
describe 'copyFileFromExistingProjectWithProject, with linkedFileData', ->
beforeEach ->
@oldProject_id = "123kljadas"
@oldFileRef = {
_id:"oldFileRef",
name:@fileName,
linkedFileData: @linkedFileData
}
@ProjectEntityMongoUpdateHandler._confirmFolder = sinon.stub().yields(folder_id)
@ProjectEntityMongoUpdateHandler._putElement = sinon.stub().yields(null, {path:{fileSystem: @fileSystemPath}})
@ProjectEntityUpdateHandler.copyFileFromExistingProjectWithProject @project, folder_id, @oldProject_id, @oldFileRef, userId, @callback
it 'should copy the file in FileStoreHandler', ->
@FileStoreHandler.copyFile
.calledWith(@oldProject_id, @oldFileRef._id, project_id, file_id)
.should.equal true
it 'should put file into folder by calling put element, with the linkedFileData', ->
@ProjectEntityMongoUpdateHandler._putElement
.calledWithMatch(
@project,
folder_id,
{ _id: file_id, name: @fileName, linkedFileData: @linkedFileData},
"file"
)
.should.equal true
describe 'updateDocLines', -> describe 'updateDocLines', ->
beforeEach -> beforeEach ->
@path = "/somewhere/something.tex" @path = "/somewhere/something.tex"
@ -285,7 +316,7 @@ describe 'ProjectEntityUpdateHandler', ->
beforeEach -> beforeEach ->
@path = "/path/to/file" @path = "/path/to/file"
@newFile = {_id: file_id, rev: 0, name: @fileName} @newFile = {_id: file_id, rev: 0, name: @fileName, linkedFileData: @linkedFileData}
@TpdsUpdateSender.addFile = sinon.stub().yields() @TpdsUpdateSender.addFile = sinon.stub().yields()
@ProjectEntityMongoUpdateHandler.addFile = sinon.stub().yields(null, {path: fileSystem: @path}, @project) @ProjectEntityMongoUpdateHandler.addFile = sinon.stub().yields(null, {path: fileSystem: @path}, @project)
@ProjectEntityUpdateHandler.addFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback @ProjectEntityUpdateHandler.addFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
@ -330,7 +361,7 @@ describe 'ProjectEntityUpdateHandler', ->
@newFileUrl = "new-file-url" @newFileUrl = "new-file-url"
@FileStoreHandler.uploadFileFromDisk = sinon.stub().yields(null, @newFileUrl) @FileStoreHandler.uploadFileFromDisk = sinon.stub().yields(null, @newFileUrl)
@newFile = _id: new_file_id, name: "dummy-upload-filename", rev: 0 @newFile = _id: new_file_id, name: "dummy-upload-filename", rev: 0, linkedFileData: @linkedFileData
@oldFile = _id: file_id @oldFile = _id: file_id
@path = "/path/to/file" @path = "/path/to/file"
@ProjectEntityMongoUpdateHandler._insertDeletedFileReference = sinon.stub().yields() @ProjectEntityMongoUpdateHandler._insertDeletedFileReference = sinon.stub().yields()