mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #416 from sharelatex/hof-history-disabled-resync
disable history resync when project-history is not enabled
This commit is contained in:
commit
f514b68936
5 changed files with 106 additions and 56 deletions
|
@ -47,6 +47,13 @@ UnsupportedExportRecordsError = (message) ->
|
|||
return error
|
||||
UnsupportedExportRecordsError.prototype.__proto___ = Error.prototype
|
||||
|
||||
ProjectHistoryDisabledError = (message) ->
|
||||
error = new Error(message)
|
||||
error.name = "ProjectHistoryDisabledError "
|
||||
error.__proto__ = ProjectHistoryDisabledError.prototype
|
||||
return error
|
||||
ProjectHistoryDisabledError.prototype.__proto___ = Error.prototype
|
||||
|
||||
module.exports = Errors =
|
||||
NotFoundError: NotFoundError
|
||||
ServiceNotConfiguredError: ServiceNotConfiguredError
|
||||
|
@ -55,3 +62,4 @@ module.exports = Errors =
|
|||
UnsupportedFileTypeError: UnsupportedFileTypeError
|
||||
UnsupportedBrandError: UnsupportedBrandError
|
||||
UnsupportedExportRecordsError: UnsupportedExportRecordsError
|
||||
ProjectHistoryDisabledError: ProjectHistoryDisabledError
|
||||
|
|
|
@ -2,9 +2,10 @@ logger = require "logger-sharelatex"
|
|||
request = require "request"
|
||||
settings = require "settings-sharelatex"
|
||||
AuthenticationController = require "../Authentication/AuthenticationController"
|
||||
Errors = require "../Errors/Errors"
|
||||
HistoryManager = require "./HistoryManager"
|
||||
ProjectDetailsHandler = require "../Project/ProjectDetailsHandler"
|
||||
ProjectEntityUpdateHandler = require "../Project/ProjectEntityUpdateHandler"
|
||||
HistoryManager = require "./HistoryManager"
|
||||
|
||||
module.exports = HistoryController =
|
||||
selectHistoryApi: (req, res, next = (error) ->) ->
|
||||
|
@ -67,5 +68,6 @@ module.exports = HistoryController =
|
|||
resyncProjectHistory: (req, res, next = (error) ->) ->
|
||||
project_id = req.params.Project_id
|
||||
ProjectEntityUpdateHandler.resyncProjectHistory project_id, (error) ->
|
||||
return res.sendStatus(404) if error instanceof Errors.ProjectHistoryDisabledError
|
||||
return next(error) if error?
|
||||
res.sendStatus 204
|
||||
|
|
|
@ -316,8 +316,13 @@ module.exports = ProjectEntityUpdateHandler = self =
|
|||
# This doesn't directly update project structure but we need to take the lock
|
||||
# to prevent anything else being queued before the resync update
|
||||
resyncProjectHistory: wrapWithLock (project_id, callback) ->
|
||||
ProjectGetter.getProject project_id, rootFolder: true, (error, project) ->
|
||||
ProjectGetter.getProject project_id, rootFolder: true, overleaf: true, (error, project) ->
|
||||
return callback(error) if error?
|
||||
|
||||
if !project.overleaf?.history?.id?
|
||||
error = new Errors.ProjectHistoryDisabledError("project history not enabled for #{project_id}")
|
||||
return callback(error)
|
||||
|
||||
ProjectEntityHandler.getAllEntitiesFromProject project, (error, docs, files) ->
|
||||
return callback(error) if error?
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
chai = require('chai')
|
||||
chai.should()
|
||||
sinon = require("sinon")
|
||||
|
||||
Errors = require "../../../../app/js/Features/Errors/Errors"
|
||||
|
||||
modulePath = "../../../../app/js/Features/History/HistoryController"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
|
@ -14,8 +17,9 @@ describe "HistoryController", ->
|
|||
"request" : @request = sinon.stub()
|
||||
"settings-sharelatex": @settings = {}
|
||||
"logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
|
||||
"./HistoryManager": @HistoryManager = {}
|
||||
"../Authentication/AuthenticationController": @AuthenticationController
|
||||
"../Errors/Errors": Errors
|
||||
"./HistoryManager": @HistoryManager = {}
|
||||
"../Project/ProjectDetailsHandler": @ProjectDetailsHandler = {}
|
||||
"../Project/ProjectEntityUpdateHandler": @ProjectEntityUpdateHandler = {}
|
||||
@settings.apis =
|
||||
|
@ -202,22 +206,40 @@ describe "HistoryController", ->
|
|||
@res.json.calledWith(@data_with_users).should.equal false
|
||||
|
||||
describe "resyncProjectHistory", ->
|
||||
beforeEach ->
|
||||
@project_id = 'mock-project-id'
|
||||
@req = params: Project_id: @project_id
|
||||
@res = sendStatus: sinon.stub()
|
||||
@next = sinon.stub()
|
||||
describe "for a project without project-history enabled", ->
|
||||
beforeEach ->
|
||||
@project_id = 'mock-project-id'
|
||||
@req = params: Project_id: @project_id
|
||||
@res = sendStatus: sinon.stub()
|
||||
@next = sinon.stub()
|
||||
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory = sinon.stub().yields()
|
||||
@error = new Errors.ProjectHistoryDisabledError()
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory = sinon.stub().yields(@error)
|
||||
|
||||
@HistoryController.resyncProjectHistory @req, @res, @next
|
||||
@HistoryController.resyncProjectHistory @req, @res, @next
|
||||
|
||||
it "resyncs the project", ->
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
it "response with a 404", ->
|
||||
@res.sendStatus
|
||||
.calledWith(404)
|
||||
.should.equal true
|
||||
|
||||
it "responds with a 204", ->
|
||||
@res.sendStatus
|
||||
.calledWith(204)
|
||||
.should.equal true
|
||||
describe "for a project with project-history enabled", ->
|
||||
beforeEach ->
|
||||
@project_id = 'mock-project-id'
|
||||
@req = params: Project_id: @project_id
|
||||
@res = sendStatus: sinon.stub()
|
||||
@next = sinon.stub()
|
||||
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory = sinon.stub().yields()
|
||||
|
||||
@HistoryController.resyncProjectHistory @req, @res, @next
|
||||
|
||||
it "resyncs the project", ->
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "responds with a 204", ->
|
||||
@res.sendStatus
|
||||
.calledWith(204)
|
||||
.should.equal true
|
||||
|
|
|
@ -746,49 +746,62 @@ describe 'ProjectEntityUpdateHandler', ->
|
|||
.should.equal true
|
||||
|
||||
describe "resyncProjectHistory", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProject = sinon.stub().yields(null, @project)
|
||||
docs = [
|
||||
doc: _id: doc_id
|
||||
path: 'main.tex'
|
||||
]
|
||||
files = [
|
||||
file: _id: file_id
|
||||
path: 'universe.png'
|
||||
]
|
||||
@ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub().yields(null, docs, files)
|
||||
@FileStoreHandler._buildUrl = (project_id, file_id) ->
|
||||
"www.filestore.test/#{project_id}/#{file_id}"
|
||||
@DocumentUpdaterHandler.resyncProjectHistory = sinon.stub().yields()
|
||||
describe "a project without project-history enabled", ->
|
||||
beforeEach ->
|
||||
@project.ovreleaf = {}
|
||||
@ProjectGetter.getProject = sinon.stub().yields(null, @project)
|
||||
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory project_id, @callback
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory project_id, @callback
|
||||
|
||||
it 'gets the project', ->
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(project_id)
|
||||
.should.equal true
|
||||
it "should return an error", ->
|
||||
error = new Errors.ProjectHistoryDisabledError("project history not enabled for #{project_id}")
|
||||
@callback.calledWith(error).should.equal true
|
||||
|
||||
it 'gets the entities for the project', ->
|
||||
@ProjectEntityHandler.getAllEntitiesFromProject
|
||||
.calledWith(@project)
|
||||
.should.equal true
|
||||
describe "a project with project-history enabled", ->
|
||||
beforeEach ->
|
||||
@project.overleaf = history: id: 4
|
||||
@ProjectGetter.getProject = sinon.stub().yields(null, @project)
|
||||
docs = [
|
||||
doc: _id: doc_id
|
||||
path: 'main.tex'
|
||||
]
|
||||
files = [
|
||||
file: _id: file_id
|
||||
path: 'universe.png'
|
||||
]
|
||||
@ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub().yields(null, docs, files)
|
||||
@FileStoreHandler._buildUrl = (project_id, file_id) ->
|
||||
"www.filestore.test/#{project_id}/#{file_id}"
|
||||
@DocumentUpdaterHandler.resyncProjectHistory = sinon.stub().yields()
|
||||
|
||||
it 'tells the doc updater to sync the project', ->
|
||||
docs = [
|
||||
doc: doc_id
|
||||
path: 'main.tex'
|
||||
]
|
||||
files = [
|
||||
file: file_id
|
||||
path: 'universe.png'
|
||||
url: "www.filestore.test/#{project_id}/#{file_id}"
|
||||
]
|
||||
@DocumentUpdaterHandler.resyncProjectHistory
|
||||
.calledWith(project_id, docs, files)
|
||||
.should.equal true
|
||||
@ProjectEntityUpdateHandler.resyncProjectHistory project_id, @callback
|
||||
|
||||
it 'calls the callback', ->
|
||||
@callback.called.should.equal true
|
||||
it 'gets the project', ->
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(project_id)
|
||||
.should.equal true
|
||||
|
||||
it 'gets the entities for the project', ->
|
||||
@ProjectEntityHandler.getAllEntitiesFromProject
|
||||
.calledWith(@project)
|
||||
.should.equal true
|
||||
|
||||
it 'tells the doc updater to sync the project', ->
|
||||
docs = [
|
||||
doc: doc_id
|
||||
path: 'main.tex'
|
||||
]
|
||||
files = [
|
||||
file: file_id
|
||||
path: 'universe.png'
|
||||
url: "www.filestore.test/#{project_id}/#{file_id}"
|
||||
]
|
||||
@DocumentUpdaterHandler.resyncProjectHistory
|
||||
.calledWith(project_id, docs, files)
|
||||
.should.equal true
|
||||
|
||||
it 'calls the callback', ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
describe "_cleanUpEntity", ->
|
||||
beforeEach ->
|
||||
|
|
Loading…
Reference in a new issue