Эх сурвалжийг харах

Merge pull request #1763 from overleaf/bg-preserve-file-hash-on-copy-and-delete

preserve file hash on copy and delete

GitOrigin-RevId: 2dc000255dcfe875a30a7e7f878aaa09fea367dc
Brian Gough 7 жил өмнө
parent
commit
e252c64996

+ 2 - 0
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?

+ 5 - 2
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'}

+ 6 - 4
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