Merge pull request #1719 from sharelatex/ja-restore-doc-snapshots

Show and restore doc snapshots from admin panel

GitOrigin-RevId: 22339644d48a8698df97f7d5fc1eecfaf27c6fab
This commit is contained in:
Brian Gough 2019-04-24 14:12:22 +01:00 committed by sharelatex
parent 967973f354
commit e1ec01eb0f
5 changed files with 21 additions and 15 deletions

View file

@ -13,10 +13,13 @@ _ = require('underscore')
module.exports = EditorController =
addDoc: (project_id, folder_id, docName, docLines, source, user_id, callback = (error, doc)->)->
EditorController.addDocWithRanges(project_id, folder_id, docName, docLines, {}, source, user_id, callback)
addDocWithRanges: (project_id, folder_id, docName, docLines, docRanges, source, user_id, callback = (error, doc)->)->
docName = docName.trim()
logger.log {project_id, folder_id, docName, source}, "sending new doc to project"
Metrics.inc "editor.add-doc"
ProjectEntityUpdateHandler.addDoc project_id, folder_id, docName, docLines, user_id, (err, doc, folder_id)=>
ProjectEntityUpdateHandler.addDocWithRanges project_id, folder_id, docName, docLines, docRanges, user_id, (err, doc, folder_id)=>
if err?
logger.err err:err, project_id:project_id, docName:docName, "error adding doc without lock"
return callback(err)

View file

@ -141,18 +141,21 @@ module.exports = ProjectEntityUpdateHandler = self =
return callback(err) if err?
callback(null, result, project)
addDoc: wrapWithLock
addDoc: (project_id, folder_id, docName, docLines, userId, callback) ->
self.addDocWithRanges(project_id, folder_id, docName, docLines, {}, userId, callback)
addDocWithRanges: wrapWithLock
beforeLock: (next) ->
(project_id, folder_id, docName, docLines, userId, callback = (error, doc, folder_id) ->) ->
(project_id, folder_id, docName, docLines, ranges, userId, callback = (error, doc, folder_id) ->) ->
if not SafePath.isCleanFilename docName
return callback new Errors.InvalidNameError("invalid element name")
# Put doc in docstore first, so that if it errors, we don't have a doc_id in the project
# which hasn't been created in docstore.
doc = new Doc name: docName
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, {}, (err, modified, rev) ->
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, ranges, (err, modified, rev) ->
return callback(err) if err?
next(project_id, folder_id, doc, docName, docLines, userId, callback)
withLock: (project_id, folder_id, doc, docName, docLines, userId, callback = (error, doc, folder_id) ->) ->
next(project_id, folder_id, doc, docName, docLines, ranges, userId, callback)
withLock: (project_id, folder_id, doc, docName, docLines, ranges, userId, callback = (error, doc, folder_id) ->) ->
ProjectEntityUpdateHandler._addDocAndSendToTpds project_id, folder_id, doc, (err, result, project) ->
return callback(err) if err?
docPath = result?.path?.fileSystem
@ -261,7 +264,7 @@ module.exports = ProjectEntityUpdateHandler = self =
return callback(err) if err?
callback null, existingDoc, !existingDoc?
else
self.addDoc.withoutLock project_id, folder_id, docName, docLines, userId, (err, doc) ->
self.addDocWithRanges.withoutLock project_id, folder_id, docName, docLines, {}, userId, (err, doc) ->
return callback(err) if err?
callback null, doc, !existingDoc?

View file

@ -1,6 +1,6 @@
Settings = require "settings-sharelatex"
mongojs = require "mongojs"
db = mongojs(Settings.mongo.url, ["projects", "users", "userstubs", "tokens"])
db = mongojs(Settings.mongo.url, ["projects", "users", "userstubs", "tokens", "docSnapshots"])
module.exports =
db: db
ObjectId: mongojs.ObjectId

View file

@ -51,12 +51,12 @@ describe "EditorController", ->
describe 'addDoc', ->
beforeEach ->
@ProjectEntityUpdateHandler.addDoc = sinon.stub().yields(null, @doc, @folder_id)
@ProjectEntityUpdateHandler.addDocWithRanges = sinon.stub().yields(null, @doc, @folder_id)
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, @callback
it 'should add the doc using the project entity handler', ->
@ProjectEntityUpdateHandler.addDoc
.calledWith(@project_id, @folder_id, @docName, @docLines)
@ProjectEntityUpdateHandler.addDocWithRanges
.calledWith(@project_id, @folder_id, @docName, @docLines, {})
.should.equal true
it 'should send the update out to the users in the project', ->

View file

@ -477,7 +477,7 @@ describe 'ProjectEntityUpdateHandler', ->
@folder = _id: folder_id, docs: []
@newDoc = _id: doc_id
@ProjectLocator.findElement = sinon.stub().yields(null, @folder)
@ProjectEntityUpdateHandler.addDoc = withoutLock: sinon.stub().yields(null, @newDoc)
@ProjectEntityUpdateHandler.addDocWithRanges = withoutLock: sinon.stub().yields(null, @newDoc)
@ProjectEntityUpdateHandler.upsertDoc project_id, folder_id, @docName, @docLines, @source, userId, @callback
@ -487,8 +487,8 @@ describe 'ProjectEntityUpdateHandler', ->
.should.equal true
it 'adds the doc', ->
@ProjectEntityUpdateHandler.addDoc.withoutLock
.calledWith(project_id, folder_id, @docName, @docLines, userId)
@ProjectEntityUpdateHandler.addDocWithRanges.withoutLock
.calledWith(project_id, folder_id, @docName, @docLines, {}, userId)
.should.equal true
it 'returns the doc', ->
@ -499,7 +499,7 @@ describe 'ProjectEntityUpdateHandler', ->
@folder = _id: folder_id, docs: []
@newDoc = _id: doc_id
@ProjectLocator.findElement = sinon.stub().yields(null, @folder)
@ProjectEntityUpdateHandler.addDoc = withoutLock: sinon.stub().yields(null, @newDoc)
@ProjectEntityUpdateHandler.addDocWithRanges = withoutLock: sinon.stub().yields(null, @newDoc)
@ProjectEntityUpdateHandler.upsertDoc project_id, folder_id, "*" + @docName, @docLines, @source, userId, @callback