mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add methods to bulk accept changes.
This commit is contained in:
parent
fe5711ef07
commit
d530ee9501
4 changed files with 49 additions and 7 deletions
|
@ -49,6 +49,7 @@ app.delete '/project/:project_id/doc/:doc_id', HttpController.flushAndDele
|
|||
app.delete '/project/:project_id', HttpController.deleteProject
|
||||
app.post '/project/:project_id/flush', HttpController.flushProject
|
||||
app.post '/project/:project_id/doc/:doc_id/change/:change_id/accept', HttpController.acceptChange
|
||||
app.post '/project/:project_id/doc/:doc_id/change/accept', HttpController.bulkAcceptChanges
|
||||
app.del '/project/:project_id/doc/:doc_id/comment/:comment_id', HttpController.deleteComment
|
||||
|
||||
app.get '/total', (req, res)->
|
||||
|
|
|
@ -140,6 +140,22 @@ module.exports = DocumentManager =
|
|||
return callback(error) if error?
|
||||
callback()
|
||||
|
||||
bulkAcceptChanges: (project_id, doc_id, change_ids, _callback = (error) ->) ->
|
||||
timer = new Metrics.Timer("docManager.bulkAcceptChanges")
|
||||
callback = (args...) ->
|
||||
timer.done()
|
||||
_callback(args...)
|
||||
|
||||
DocumentManager.getDoc project_id, doc_id, (error, lines, version, ranges) ->
|
||||
return callback(error) if error?
|
||||
if !lines? or !version?
|
||||
return callback(new Errors.NotFoundError("document not found: #{doc_id}"))
|
||||
RangesManager.bulkAcceptChanges change_ids, ranges, (error, new_ranges) ->
|
||||
return callback(error) if error?
|
||||
RedisManager.updateDocument doc_id, lines, version, [], new_ranges, (error) ->
|
||||
return callback(error) if error?
|
||||
callback()
|
||||
|
||||
deleteComment: (project_id, doc_id, comment_id, _callback = (error) ->) ->
|
||||
timer = new Metrics.Timer("docManager.deleteComment")
|
||||
callback = (args...) ->
|
||||
|
@ -180,6 +196,10 @@ module.exports = DocumentManager =
|
|||
UpdateManager = require "./UpdateManager"
|
||||
UpdateManager.lockUpdatesAndDo DocumentManager.acceptChange, project_id, doc_id, change_id, callback
|
||||
|
||||
bulkAcceptChangesWithLock: (project_id, doc_id, change_ids, callback = (error) ->) ->
|
||||
UpdateManager = require "./UpdateManager"
|
||||
UpdateManager.lockUpdatesAndDo DocumentManager.bulkAcceptChanges, project_id, doc_id, change_ids, callback
|
||||
|
||||
deleteCommentWithLock: (project_id, doc_id, thread_id, callback = (error) ->) ->
|
||||
UpdateManager = require "./UpdateManager"
|
||||
UpdateManager.lockUpdatesAndDo DocumentManager.deleteComment, project_id, doc_id, thread_id, callback
|
||||
|
|
|
@ -106,6 +106,18 @@ module.exports = HttpController =
|
|||
logger.log {project_id, doc_id, change_id}, "accepted change via http"
|
||||
res.send 204 # No Content
|
||||
|
||||
bulkAcceptChanges: (req, res, next = (error) ->) ->
|
||||
{project_id, doc_id} = req.params
|
||||
{change_ids} = req.body
|
||||
change_ids ?= []
|
||||
logger.log {project_id, doc_id}, "accepting #{ change_ids.length } changes via http"
|
||||
timer = new Metrics.Timer("http.bulkAcceptChanges")
|
||||
DocumentManager.bulkAcceptChangesWithLock project_id, doc_id, change_ids, (error) ->
|
||||
timer.done()
|
||||
return next(error) if error?
|
||||
logger.log {project_id, doc_id}, "accepted #{ change_ids.length } changes via http"
|
||||
res.send 204 # No Content
|
||||
|
||||
deleteComment: (req, res, next = (error) ->) ->
|
||||
{project_id, doc_id, comment_id} = req.params
|
||||
logger.log {project_id, doc_id, comment_id}, "deleting comment via http"
|
||||
|
|
|
@ -41,6 +41,15 @@ module.exports = RangesManager =
|
|||
response = RangesManager._getRanges(rangesTracker)
|
||||
callback null, response
|
||||
|
||||
bulkAcceptChanges: (change_ids, ranges, callback = (error, ranges) ->) ->
|
||||
{changes, comments} = ranges
|
||||
logger.log {change_id}, "accepting #{ change_ids.length } changes in ranges"
|
||||
rangesTracker = new RangesTracker(changes, comments)
|
||||
for change_id in change_ids
|
||||
rangesTracker.removeChangeId(change_id)
|
||||
response = RangesManager._getRanges(rangesTracker)
|
||||
callback null, response
|
||||
|
||||
deleteComment: (comment_id, ranges, callback = (error, ranges) ->) ->
|
||||
{changes, comments} = ranges
|
||||
logger.log {comment_id}, "deleting comment in ranges"
|
||||
|
|
Loading…
Reference in a new issue