separate overleaf.id from overleaf.history.id

This commit is contained in:
Hayden Faulds 2017-10-27 15:24:18 +01:00
parent 20ea9918c9
commit 19bc145ff4
3 changed files with 13 additions and 10 deletions

View file

@ -15,28 +15,28 @@ _ = require "underscore"
module.exports = ProjectCreationHandler =
createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)->
createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
metrics.inc("project-creation")
if arguments.length == 3
callback = overleafId
overleafId = null
callback = projectHistoryId
projectHistoryId = null
ProjectDetailsHandler.validateProjectName projectName, (error) ->
return callback(error) if error?
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
if overleafId?
ProjectCreationHandler._createBlankProject owner_id, projectName, overleafId, callback
if projectHistoryId?
ProjectCreationHandler._createBlankProject owner_id, projectName, projectHistoryId, callback
else
HistoryController.initializeProject (error, history) ->
return callback(error) if error?
ProjectCreationHandler._createBlankProject owner_id, projectName, history.overleaf_id, callback
_createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)->
_createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
rootFolder = new Folder {'name':'rootFolder'}
project = new Project
owner_ref : new ObjectId(owner_id)
name : projectName
project.overleaf.id = overleafId
project.overleaf.history.id = projectHistoryId
if Settings.currentImageName?
project.imageName = Settings.currentImageName
project.rootFolder[0] = rootFolder

View file

@ -38,6 +38,8 @@ ProjectSchema = new Schema
imported_at_ver_id : { type: Number }
token : { type: String }
read_token : { type: String }
history :
id : { type: Number }
ProjectSchema.statics.getProject = (project_or_id, fields, callback)->
if project_or_id._id?

View file

@ -22,7 +22,8 @@ describe 'ProjectCreationHandler', ->
@._id = project_id
@owner_ref = options.owner_ref
@name = options.name
@overleaf = {}
@overleaf =
history: {}
save: sinon.stub().callsArg(0)
rootFolder:[{
_id: rootFolderId
@ -86,13 +87,13 @@ describe 'ProjectCreationHandler', ->
it "should set the overleaf id if overleaf id not provided", (done)->
@handler.createBlankProject ownerId, projectName, (err, project)=>
project.overleaf.id.should.equal @overleaf_id
project.overleaf.history.id.should.equal @overleaf_id
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.history.id.should.equal overleaf_id
done()
it "should set the language from the user", (done)->