mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 05:05:27 -05:00
allow overleafId to be passed in to avoid history initialization
This commit is contained in:
parent
670b183c8e
commit
20ea9918c9
2 changed files with 37 additions and 23 deletions
|
@ -15,27 +15,36 @@ _ = require "underscore"
|
||||||
|
|
||||||
module.exports = ProjectCreationHandler =
|
module.exports = ProjectCreationHandler =
|
||||||
|
|
||||||
createBlankProject : (owner_id, projectName, callback = (error, project) ->)->
|
createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)->
|
||||||
metrics.inc("project-creation")
|
metrics.inc("project-creation")
|
||||||
|
if arguments.length == 3
|
||||||
|
callback = overleafId
|
||||||
|
overleafId = null
|
||||||
|
|
||||||
ProjectDetailsHandler.validateProjectName projectName, (error) ->
|
ProjectDetailsHandler.validateProjectName projectName, (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
||||||
HistoryController.initializeProject (error, history) ->
|
if overleafId?
|
||||||
return callback(error) if error?
|
ProjectCreationHandler._createBlankProject owner_id, projectName, overleafId, callback
|
||||||
rootFolder = new Folder {'name':'rootFolder'}
|
else
|
||||||
project = new Project
|
HistoryController.initializeProject (error, history) ->
|
||||||
owner_ref : new ObjectId(owner_id)
|
return callback(error) if error?
|
||||||
name : projectName
|
ProjectCreationHandler._createBlankProject owner_id, projectName, history.overleaf_id, callback
|
||||||
if history?.overleaf_id?
|
|
||||||
project.overleaf.id = history.overleaf_id
|
_createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)->
|
||||||
if Settings.currentImageName?
|
rootFolder = new Folder {'name':'rootFolder'}
|
||||||
project.imageName = Settings.currentImageName
|
project = new Project
|
||||||
project.rootFolder[0] = rootFolder
|
owner_ref : new ObjectId(owner_id)
|
||||||
User.findById owner_id, "ace.spellCheckLanguage", (err, user)->
|
name : projectName
|
||||||
project.spellCheckLanguage = user.ace.spellCheckLanguage
|
project.overleaf.id = overleafId
|
||||||
project.save (err)->
|
if Settings.currentImageName?
|
||||||
return callback(err) if err?
|
project.imageName = Settings.currentImageName
|
||||||
callback err, project
|
project.rootFolder[0] = rootFolder
|
||||||
|
User.findById owner_id, "ace.spellCheckLanguage", (err, user)->
|
||||||
|
project.spellCheckLanguage = user.ace.spellCheckLanguage
|
||||||
|
project.save (err)->
|
||||||
|
return callback(err) if err?
|
||||||
|
callback err, project
|
||||||
|
|
||||||
createBasicProject : (owner_id, projectName, callback = (error, project) ->)->
|
createBasicProject : (owner_id, projectName, callback = (error, project) ->)->
|
||||||
self = @
|
self = @
|
||||||
|
|
|
@ -64,10 +64,11 @@ describe 'ProjectCreationHandler', ->
|
||||||
|
|
||||||
describe 'Creating a Blank project', ->
|
describe 'Creating a Blank project', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@overleaf_id = 1234
|
||||||
|
@HistoryController.initializeProject = sinon.stub().callsArgWith(0, null, { @overleaf_id })
|
||||||
@ProjectModel::save = sinon.stub().callsArg(0)
|
@ProjectModel::save = sinon.stub().callsArg(0)
|
||||||
|
|
||||||
describe "successfully", ->
|
describe "successfully", ->
|
||||||
|
|
||||||
it "should save the project", (done)->
|
it "should save the project", (done)->
|
||||||
@handler.createBlankProject ownerId, projectName, =>
|
@handler.createBlankProject ownerId, projectName, =>
|
||||||
@ProjectModel::save.called.should.equal true
|
@ProjectModel::save.called.should.equal true
|
||||||
|
@ -79,14 +80,18 @@ describe 'ProjectCreationHandler', ->
|
||||||
(project.owner_ref + "").should.equal ownerId
|
(project.owner_ref + "").should.equal ownerId
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should initialize the project history", (done)->
|
it "should initialize the project overleaf if history id not provided", (done)->
|
||||||
@handler.createBlankProject ownerId, projectName, done
|
@handler.createBlankProject ownerId, projectName, done
|
||||||
@HistoryController.initializeProject.calledWith().should.equal true
|
@HistoryController.initializeProject.calledWith().should.equal true
|
||||||
|
|
||||||
it "should set the overleaf id", (done)->
|
it "should set the overleaf id if overleaf id not provided", (done)->
|
||||||
overleaf_id = 1234
|
@handler.createBlankProject ownerId, projectName, (err, project)=>
|
||||||
@HistoryController.initializeProject = sinon.stub().callsArgWith(0, null, { overleaf_id })
|
project.overleaf.id.should.equal @overleaf_id
|
||||||
@handler.createBlankProject ownerId, projectName, (err, project)->
|
done()
|
||||||
|
|
||||||
|
it "should set the overleaf id if overleaf id provided", (done)->
|
||||||
|
overleaf_id = 2345
|
||||||
|
@handler.createBlankProject ownerId, projectName, overleaf_id, (err, project)->
|
||||||
project.overleaf.id.should.equal overleaf_id
|
project.overleaf.id.should.equal overleaf_id
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue