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 = module.exports = ProjectCreationHandler =
createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)-> createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
metrics.inc("project-creation") metrics.inc("project-creation")
if arguments.length == 3 if arguments.length == 3
callback = overleafId callback = projectHistoryId
overleafId = null projectHistoryId = 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"
if overleafId? if projectHistoryId?
ProjectCreationHandler._createBlankProject owner_id, projectName, overleafId, callback ProjectCreationHandler._createBlankProject owner_id, projectName, projectHistoryId, callback
else else
HistoryController.initializeProject (error, history) -> HistoryController.initializeProject (error, history) ->
return callback(error) if error? return callback(error) if error?
ProjectCreationHandler._createBlankProject owner_id, projectName, history.overleaf_id, callback 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'} rootFolder = new Folder {'name':'rootFolder'}
project = new Project project = new Project
owner_ref : new ObjectId(owner_id) owner_ref : new ObjectId(owner_id)
name : projectName name : projectName
project.overleaf.id = overleafId project.overleaf.history.id = projectHistoryId
if Settings.currentImageName? if Settings.currentImageName?
project.imageName = Settings.currentImageName project.imageName = Settings.currentImageName
project.rootFolder[0] = rootFolder project.rootFolder[0] = rootFolder

View file

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

View file

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