mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Store lastUpdatedBy Value on Projects (#1727)
Store lastUpdatedBy Value on Projects GitOrigin-RevId: bdb12c55732bc726151135b28a03e722bf3fdb39
This commit is contained in:
parent
5b7974065d
commit
5b7b9fc97b
7 changed files with 84 additions and 29 deletions
|
@ -38,9 +38,9 @@ module.exports =
|
||||||
setDocument: (req, res, next = (error) ->) ->
|
setDocument: (req, res, next = (error) ->) ->
|
||||||
project_id = req.params.Project_id
|
project_id = req.params.Project_id
|
||||||
doc_id = req.params.doc_id
|
doc_id = req.params.doc_id
|
||||||
{lines, version, ranges} = req.body
|
{lines, version, ranges, lastUpdatedAt, lastUpdatedBy} = req.body
|
||||||
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
logger.log doc_id:doc_id, project_id:project_id, "receiving set document request from api (docupdater)"
|
||||||
ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, lines, version, ranges, (error) ->
|
ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, lines, version, ranges, lastUpdatedAt, lastUpdatedBy, (error) ->
|
||||||
if error?
|
if error?
|
||||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||||
return next(error)
|
return next(error)
|
||||||
|
|
|
@ -81,7 +81,7 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback null, fileRef, folder_id
|
callback null, fileRef, folder_id
|
||||||
|
|
||||||
updateDocLines: (project_id, doc_id, lines, version, ranges, callback = (error) ->)->
|
updateDocLines: (project_id, doc_id, lines, version, ranges, lastUpdatedAt, lastUpdatedBy, callback = (error) ->)->
|
||||||
ProjectGetter.getProjectWithoutDocLines project_id, (err, project)->
|
ProjectGetter.getProjectWithoutDocLines project_id, (err, project)->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
return callback(new Errors.NotFoundError("project not found")) if !project?
|
return callback(new Errors.NotFoundError("project not found")) if !project?
|
||||||
|
@ -113,7 +113,7 @@ module.exports = ProjectEntityUpdateHandler = self =
|
||||||
# path will only be present if the doc is not deleted
|
# path will only be present if the doc is not deleted
|
||||||
if modified && !isDeletedDoc
|
if modified && !isDeletedDoc
|
||||||
# Don't need to block for marking as updated
|
# Don't need to block for marking as updated
|
||||||
ProjectUpdateHandler.markAsUpdated project_id
|
ProjectUpdateHandler.markAsUpdated project_id, lastUpdatedAt, lastUpdatedBy
|
||||||
TpdsUpdateSender.addDoc {project_id:project_id, path:path.fileSystem, doc_id:doc_id, project_name:project.name, rev:rev}, callback
|
TpdsUpdateSender.addDoc {project_id:project_id, path:path.fileSystem, doc_id:doc_id, project_name:project.name, rev:rev}, callback
|
||||||
else
|
else
|
||||||
callback()
|
callback()
|
||||||
|
|
|
@ -2,12 +2,18 @@ Project = require('../../models/Project').Project
|
||||||
logger = require('logger-sharelatex')
|
logger = require('logger-sharelatex')
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
markAsUpdated : (project_id, callback)->
|
markAsUpdated : (projectId, lastUpdatedAt, lastUpdatedBy, callback = () ->)->
|
||||||
conditions = {_id:project_id}
|
lastUpdatedAt ?= new Date()
|
||||||
update = {lastUpdated:Date.now()}
|
|
||||||
Project.update conditions, update, {}, (err)->
|
conditions =
|
||||||
if callback?
|
_id: projectId
|
||||||
callback()
|
lastUpdated: { $lt: lastUpdatedAt }
|
||||||
|
|
||||||
|
update = {
|
||||||
|
lastUpdated: lastUpdatedAt or (new Date()).getTime()
|
||||||
|
lastUpdatedBy: lastUpdatedBy
|
||||||
|
}
|
||||||
|
Project.update conditions, update, {}, callback
|
||||||
|
|
||||||
markAsOpened : (project_id, callback)->
|
markAsOpened : (project_id, callback)->
|
||||||
conditions = {_id:project_id}
|
conditions = {_id:project_id}
|
||||||
|
|
|
@ -19,6 +19,7 @@ DeletedFileSchema = new Schema
|
||||||
ProjectSchema = new Schema
|
ProjectSchema = new Schema
|
||||||
name : {type:String, default:'new project'}
|
name : {type:String, default:'new project'}
|
||||||
lastUpdated : {type:Date, default: () -> new Date()}
|
lastUpdated : {type:Date, default: () -> new Date()}
|
||||||
|
lastUpdatedBy : {type:ObjectId, ref: 'User'}
|
||||||
lastOpened : {type:Date}
|
lastOpened : {type:Date}
|
||||||
active : { type: Boolean, default: true }
|
active : { type: Boolean, default: true }
|
||||||
owner_ref : {type:ObjectId, ref:'User'}
|
owner_ref : {type:ObjectId, ref:'User'}
|
||||||
|
|
|
@ -28,6 +28,8 @@ describe "DocumentController", ->
|
||||||
@version = 42
|
@version = 42
|
||||||
@ranges = {"mock": "ranges"}
|
@ranges = {"mock": "ranges"}
|
||||||
@pathname = '/a/b/c/file.tex'
|
@pathname = '/a/b/c/file.tex'
|
||||||
|
@lastUpdatedAt = (new Date()).getTime()
|
||||||
|
@lastUpdatedBy = 'fake-last-updater-id'
|
||||||
@rev = 5
|
@rev = 5
|
||||||
|
|
||||||
describe "getDocument", ->
|
describe "getDocument", ->
|
||||||
|
@ -120,12 +122,21 @@ describe "DocumentController", ->
|
||||||
lines: @doc_lines
|
lines: @doc_lines
|
||||||
version: @version
|
version: @version
|
||||||
ranges: @ranges
|
ranges: @ranges
|
||||||
|
lastUpdatedAt: @lastUpdatedAt
|
||||||
|
lastUpdatedBy: @lastUpdatedBy
|
||||||
@DocumentController.setDocument(@req, @res, @next)
|
@DocumentController.setDocument(@req, @res, @next)
|
||||||
|
|
||||||
it "should update the document in Mongo", ->
|
it "should update the document in Mongo", ->
|
||||||
@ProjectEntityUpdateHandler.updateDocLines
|
sinon.assert.calledWith(
|
||||||
.calledWith(@project_id, @doc_id, @doc_lines, @version, @ranges)
|
@ProjectEntityUpdateHandler.updateDocLines,
|
||||||
.should.equal true
|
@project_id,
|
||||||
|
@doc_id,
|
||||||
|
@doc_lines,
|
||||||
|
@version,
|
||||||
|
@ranges,
|
||||||
|
@lastUpdatedAt,
|
||||||
|
@lastUpdatedBy
|
||||||
|
)
|
||||||
|
|
||||||
it "should return a successful response", ->
|
it "should return a successful response", ->
|
||||||
@res.success.should.equal true
|
@res.success.should.equal true
|
||||||
|
|
|
@ -160,6 +160,8 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
}
|
}
|
||||||
@version = 42
|
@version = 42
|
||||||
@ranges = {"mock":"ranges"}
|
@ranges = {"mock":"ranges"}
|
||||||
|
@lastUpdatedAt = (new Date()).getTime()
|
||||||
|
@lastUpdatedBy = 'fake-last-updater-id'
|
||||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().yields(null, @project)
|
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().yields(null, @project)
|
||||||
@ProjectLocator.findElement = sinon.stub().yields(null, @doc, {fileSystem: @path})
|
@ProjectLocator.findElement = sinon.stub().yields(null, @doc, {fileSystem: @path})
|
||||||
@TpdsUpdateSender.addDoc = sinon.stub().yields()
|
@TpdsUpdateSender.addDoc = sinon.stub().yields()
|
||||||
|
@ -169,7 +171,7 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
describe "when the doc has been modified", ->
|
describe "when the doc has been modified", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, true, @rev = 5)
|
@DocstoreManager.updateDoc = sinon.stub().yields(null, true, @rev = 5)
|
||||||
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @callback
|
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @lastUpdatedAt, @lastUpdatedBy, @callback
|
||||||
|
|
||||||
it "should get the project without doc lines", ->
|
it "should get the project without doc lines", ->
|
||||||
@ProjectGetter.getProjectWithoutDocLines
|
@ProjectGetter.getProjectWithoutDocLines
|
||||||
|
@ -191,9 +193,12 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should mark the project as updated", ->
|
it "should mark the project as updated", ->
|
||||||
@ProjectUpdater.markAsUpdated
|
sinon.assert.calledWith(
|
||||||
.calledWith(project_id)
|
@ProjectUpdater.markAsUpdated,
|
||||||
.should.equal true
|
project_id,
|
||||||
|
@lastUpdatedAt,
|
||||||
|
@lastUpdatedBy
|
||||||
|
)
|
||||||
|
|
||||||
it "should send the doc the to the TPDS", ->
|
it "should send the doc the to the TPDS", ->
|
||||||
@TpdsUpdateSender.addDoc
|
@TpdsUpdateSender.addDoc
|
||||||
|
@ -212,7 +217,7 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
describe "when the doc has not been modified", ->
|
describe "when the doc has not been modified", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@DocstoreManager.updateDoc = sinon.stub().yields(null, false, @rev = 5)
|
@DocstoreManager.updateDoc = sinon.stub().yields(null, false, @rev = 5)
|
||||||
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @callback
|
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @lastUpdatedAt, @lastUpdatedBy, @callback
|
||||||
|
|
||||||
it "should not mark the project as updated", ->
|
it "should not mark the project as updated", ->
|
||||||
@ProjectUpdater.markAsUpdated.called.should.equal false
|
@ProjectUpdater.markAsUpdated.called.should.equal false
|
||||||
|
@ -229,7 +234,7 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().yields(null, @project)
|
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().yields(null, @project)
|
||||||
@ProjectLocator.findElement = sinon.stub().yields(new Errors.NotFoundError)
|
@ProjectLocator.findElement = sinon.stub().yields(new Errors.NotFoundError)
|
||||||
@DocstoreManager.updateDoc = sinon.stub().yields()
|
@DocstoreManager.updateDoc = sinon.stub().yields()
|
||||||
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @callback
|
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @lastUpdatedAt, @lastUpdatedBy, @callback
|
||||||
|
|
||||||
it "should update the doc in the docstore", ->
|
it "should update the doc in the docstore", ->
|
||||||
@DocstoreManager.updateDoc
|
@DocstoreManager.updateDoc
|
||||||
|
@ -248,7 +253,7 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
describe "when the doc is not related to the project", ->
|
describe "when the doc is not related to the project", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectLocator.findElement = sinon.stub().yields()
|
@ProjectLocator.findElement = sinon.stub().yields()
|
||||||
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @callback
|
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @lastUpdatedAt, @lastUpdatedBy, @callback
|
||||||
|
|
||||||
it "should log out the error", ->
|
it "should log out the error", ->
|
||||||
@logger.error
|
@logger.error
|
||||||
|
@ -266,7 +271,7 @@ describe 'ProjectEntityUpdateHandler', ->
|
||||||
describe "when the project is not found", ->
|
describe "when the project is not found", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().yields()
|
@ProjectGetter.getProjectWithoutDocLines = sinon.stub().yields()
|
||||||
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @callback
|
@ProjectEntityUpdateHandler.updateDocLines project_id, doc_id, @docLines, @version, @ranges, @lastUpdatedAt, @lastUpdatedBy, @callback
|
||||||
|
|
||||||
it "should return a not found error", ->
|
it "should return a not found error", ->
|
||||||
@callback.calledWith(new Errors.NotFoundError()).should.equal true
|
@callback.calledWith(new Errors.NotFoundError()).should.equal true
|
||||||
|
|
|
@ -6,6 +6,10 @@ SandboxedModule = require('sandboxed-module')
|
||||||
describe 'ProjectUpdateHandler', ->
|
describe 'ProjectUpdateHandler', ->
|
||||||
|
|
||||||
|
|
||||||
|
before ->
|
||||||
|
@fakeTime = new Date()
|
||||||
|
@clock = sinon.useFakeTimers(@fakeTime.getTime())
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectModel = class Project
|
@ProjectModel = class Project
|
||||||
@ProjectModel.update = sinon.stub().callsArg(3)
|
@ProjectModel.update = sinon.stub().callsArg(3)
|
||||||
|
@ -13,15 +17,43 @@ describe 'ProjectUpdateHandler', ->
|
||||||
'../../models/Project':{Project:@ProjectModel}
|
'../../models/Project':{Project:@ProjectModel}
|
||||||
'logger-sharelatex' : { log: sinon.stub() }
|
'logger-sharelatex' : { log: sinon.stub() }
|
||||||
|
|
||||||
|
after ->
|
||||||
|
@clock.restore()
|
||||||
|
|
||||||
describe 'marking a project as recently updated', ->
|
describe 'marking a project as recently updated', ->
|
||||||
|
beforeEach ->
|
||||||
|
@project_id = "project_id"
|
||||||
|
@lastUpdatedAt = 987654321
|
||||||
|
@lastUpdatedBy = 'fake-last-updater-id'
|
||||||
|
|
||||||
it 'should send an update to mongo', (done)->
|
it 'should send an update to mongo', (done)->
|
||||||
project_id = "project_id"
|
@handler.markAsUpdated @project_id, @lastUpdatedAt, @lastUpdatedBy, (err) =>
|
||||||
@handler.markAsUpdated project_id, (err)=>
|
sinon.assert.calledWith(
|
||||||
args = @ProjectModel.update.args[0]
|
@ProjectModel.update,
|
||||||
args[0]._id.should.equal project_id
|
{
|
||||||
date = args[1].lastUpdated+""
|
_id: @project_id,
|
||||||
now = Date.now()+""
|
lastUpdated: { $lt: @lastUpdatedAt }
|
||||||
date.substring(0,5).should.equal now.substring(0,5)
|
},
|
||||||
|
{
|
||||||
|
lastUpdated: @lastUpdatedAt,
|
||||||
|
lastUpdatedBy: @lastUpdatedBy
|
||||||
|
}
|
||||||
|
)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'should set smart fallbacks', (done)->
|
||||||
|
@handler.markAsUpdated @project_id, null, null, (err) =>
|
||||||
|
sinon.assert.calledWithMatch(
|
||||||
|
@ProjectModel.update,
|
||||||
|
{
|
||||||
|
_id: @project_id,
|
||||||
|
lastUpdated: { $lt: @fakeTime }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lastUpdated: @fakeTime
|
||||||
|
lastUpdatedBy: null
|
||||||
|
}
|
||||||
|
)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "markAsOpened", ->
|
describe "markAsOpened", ->
|
||||||
|
|
Loading…
Reference in a new issue