From 67d784a74ad56bf4476ad6873d6cf1267740484a Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 26 Feb 2018 12:55:05 +0000 Subject: [PATCH] increment project version on every structure change --- .../Features/Project/ProjectEntityMongoUpdateHandler.coffee | 2 +- services/web/app/coffee/models/Project.coffee | 1 + .../Project/ProjectEntityMongoUpdateHandlerTests.coffee | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee index 64bf12f232..da4421e4ec 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee @@ -255,7 +255,7 @@ module.exports = ProjectEntityMongoUpdateHandler = self = update["$push"][mongopath] = element # we need to increment the project version number for any structure change update["$inc"]["version"] = 1 # increment project version number - logger.log project_id: project._id, element_id: element._id, fileType: type, folder_id: folder_id, mongopath:mongopath, update: update, "adding element to project" + logger.log project_id: project._id, element_id: element._id, fileType: type, folder_id: folder_id, mongopath:mongopath, "adding element to project" Project.findOneAndUpdate conditions, update, {"new": true}, (err, newProject)-> if err? logger.err err: err, project_id: project._id, 'error saving in putElement project' diff --git a/services/web/app/coffee/models/Project.coffee b/services/web/app/coffee/models/Project.coffee index 252388b169..89f8b94097 100644 --- a/services/web/app/coffee/models/Project.coffee +++ b/services/web/app/coffee/models/Project.coffee @@ -22,6 +22,7 @@ ProjectSchema = new Schema readOnly_refs : [ type:ObjectId, ref:'User' ] rootDoc_id : {type: ObjectId} rootFolder : [FolderSchema] + version : {type: Number} publicAccesLevel : {type: String, default: 'private'} compiler : {type:String, default:'pdflatex'} spellCheckLanguage : {type:String, default:'en'} diff --git a/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee index d2a5a334b4..be5b177786 100644 --- a/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee @@ -117,7 +117,7 @@ describe 'ProjectEntityMongoUpdateHandler', -> .calledWith( { _id: project_id }, { - '$inc': { 'file.png.rev': 1 } + '$inc': { 'file.png.rev': 1, 'version': 1 } '$set': { 'file.png.created': new Date() } } {} @@ -324,7 +324,7 @@ describe 'ProjectEntityMongoUpdateHandler', -> @ProjectModel.findOneAndUpdate .calledWith( { _id: project_id }, - { $set: { "mongo.path.name": @newName } }, + { $set: { "mongo.path.name": @newName }, $inc: {"version": 1} }, { new: true } ).should.equal true @@ -384,7 +384,7 @@ describe 'ProjectEntityMongoUpdateHandler', -> it 'should pull', -> @ProjectModel.findOneAndUpdate - .calledWith({ _id: @id }, { '$pull': { 'folders[0]': null } }, {'new': true}) + .calledWith({ _id: @id }, { '$pull': { 'folders[0]': null }, '$inc': {'version': 1} }, {'new': true}) .should.equal true it 'should call the callback', ->