From e252c6499664c1e3e7f45105d65e5b67c1c48e64 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 15 May 2019 13:30:47 +0100 Subject: [PATCH] Merge pull request #1763 from overleaf/bg-preserve-file-hash-on-copy-and-delete preserve file hash on copy and delete GitOrigin-RevId: 2dc000255dcfe875a30a7e7f878aaa09fea367dc --- .../Features/Project/ProjectEntityUpdateHandler.coffee | 2 ++ services/web/app/coffee/models/Project.coffee | 7 +++++-- .../Project/ProjectEntityUpdateHandlerTests.coffee | 10 ++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee index 4fd5a1637b..ba405b0b27 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee @@ -57,6 +57,8 @@ module.exports = ProjectEntityUpdateHandler = self = fileProperties = name : SafePath.clean(origonalFileRef.name) if origonalFileRef.linkedFileData? fileProperties.linkedFileData = origonalFileRef.linkedFileData + if origonalFileRef.hash? + fileProperties.hash = origonalFileRef.hash fileRef = new File(fileProperties) FileStoreHandler.copyFile originalProject_id, origonalFileRef._id, project._id, fileRef._id, (err, fileStoreUrl)-> if err? diff --git a/services/web/app/coffee/models/Project.coffee b/services/web/app/coffee/models/Project.coffee index c5a75d3cd8..fd0a078d73 100644 --- a/services/web/app/coffee/models/Project.coffee +++ b/services/web/app/coffee/models/Project.coffee @@ -13,8 +13,11 @@ DeletedDocSchema = new Schema name: String DeletedFileSchema = new Schema - name: String - deletedAt: {type: Date} + name : String + created : type:Date + linkedFileData : { type: Schema.Types.Mixed } + hash : type:String + deletedAt : {type: Date} ProjectSchema = new Schema name : {type:String, default:'new project'} diff --git a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee index 53034d3581..65c0b74d50 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee @@ -44,7 +44,8 @@ describe 'ProjectEntityUpdateHandler', -> @rev = 0 if options.linkedFileData? @linkedFileData = options.linkedFileData - + if options.hash? + @hash = options.hash @docName = "doc-name" @docLines = ['1234','abc'] @@ -121,7 +122,7 @@ describe 'ProjectEntityUpdateHandler', -> .calledWithMatch(project_id, projectHistoryId, userId, changesMatcher) .should.equal true - describe 'copyFileFromExistingProjectWithProject, with linkedFileData', -> + describe 'copyFileFromExistingProjectWithProject, with linkedFileData and hash', -> beforeEach -> @oldProject_id = "123kljadas" @@ -129,6 +130,7 @@ describe 'ProjectEntityUpdateHandler', -> _id:"oldFileRef", name:@fileName, linkedFileData: @linkedFileData + hash: "123456" } @ProjectEntityMongoUpdateHandler._confirmFolder = sinon.stub().yields(folder_id) @ProjectEntityMongoUpdateHandler._putElement = sinon.stub().yields(null, {path:{fileSystem: @fileSystemPath}}) @@ -140,12 +142,12 @@ describe 'ProjectEntityUpdateHandler', -> .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', -> + it 'should put file into folder by calling put element, with the linkedFileData and hash', -> @ProjectEntityMongoUpdateHandler._putElement .calledWithMatch( @project, folder_id, - { _id: file_id, name: @fileName, linkedFileData: @linkedFileData}, + { _id: file_id, name: @fileName, linkedFileData: @linkedFileData, hash: "123456"}, "file" ) .should.equal true