From fd49601716f179b4340764e215eb0a361a377228 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 7 Apr 2016 14:37:53 +0100 Subject: [PATCH] preserve existing history when user upgrades --- .../track-changes/app/coffee/MongoManager.coffee | 13 +++++++++++++ .../track-changes/app/coffee/UpdateTrimmer.coffee | 4 +++- .../coffee/UpdateTrimmer/UpdateTrimmerTests.coffee | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/services/track-changes/app/coffee/MongoManager.coffee b/services/track-changes/app/coffee/MongoManager.coffee index 383facbf2e..4376e3adb1 100644 --- a/services/track-changes/app/coffee/MongoManager.coffee +++ b/services/track-changes/app/coffee/MongoManager.coffee @@ -64,6 +64,19 @@ module.exports = MongoManager = upsert: true }, callback + upgradeHistory: (project_id, callback = (error) ->) -> + # preserve the project's existing history + db.docHistory.update { + project_id: ObjectId(project_id) + temporary: true + expiresAt: {$exists: true} + }, { + $set: {temporary: false} + $unset: {expiresAt: ""} + }, { + multi: true + }, callback + ensureIndices: () -> # For finding all updates that go into a diff for a doc db.docHistory.ensureIndex { doc_id: 1, v: 1 }, { background: true } diff --git a/services/track-changes/app/coffee/UpdateTrimmer.coffee b/services/track-changes/app/coffee/UpdateTrimmer.coffee index 83a08e36fa..c7464eb6c3 100644 --- a/services/track-changes/app/coffee/UpdateTrimmer.coffee +++ b/services/track-changes/app/coffee/UpdateTrimmer.coffee @@ -15,7 +15,9 @@ module.exports = UpdateTrimmer = if details?.features?.versioning MongoManager.setProjectMetaData project_id, preserveHistory: true, (error) -> return callback(error) if error? - callback null, false + MongoManager.upgradeHistory project_id, (error) -> + return callback(error) if error? + callback null, false else callback null, true diff --git a/services/track-changes/test/unit/coffee/UpdateTrimmer/UpdateTrimmerTests.coffee b/services/track-changes/test/unit/coffee/UpdateTrimmer/UpdateTrimmerTests.coffee index afcfe53513..a25c3f4ce2 100644 --- a/services/track-changes/test/unit/coffee/UpdateTrimmer/UpdateTrimmerTests.coffee +++ b/services/track-changes/test/unit/coffee/UpdateTrimmer/UpdateTrimmerTests.coffee @@ -29,6 +29,7 @@ describe "UpdateTrimmer", -> features: {} @MongoManager.getProjectMetaData = sinon.stub().callsArgWith(1, null, @metadata) @MongoManager.setProjectMetaData = sinon.stub().callsArgWith(2) + @MongoManager.upgradeHistory = sinon.stub().callsArgWith(1) @WebApiManager.getProjectDetails = sinon.stub().callsArgWith(1, null, @details) describe "with preserveHistory set in the project meta data", -> @@ -73,6 +74,11 @@ describe "UpdateTrimmer", -> .calledWith(@project_id, {preserveHistory: true}) .should.equal true + it "should upgrade any existing history", -> + @MongoManager.upgradeHistory + .calledWith(@project_id) + .should.equal true + it "should return false", -> @callback.calledWith(null, false).should.equal true @@ -98,6 +104,11 @@ describe "UpdateTrimmer", -> .calledWith(@project_id, {preserveHistory: true}) .should.equal true + it "should upgrade any existing history", -> + @MongoManager.upgradeHistory + .calledWith(@project_id) + .should.equal true + it "should return false", -> @callback.calledWith(null, false).should.equal true