mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
accept attributes rather than projectHistoryId to ProjectCreationHandler
This commit is contained in:
parent
78aefc2871
commit
9ccdf073c4
2 changed files with 21 additions and 13 deletions
|
@ -16,38 +16,42 @@ AnalyticsManger = require("../Analytics/AnalyticsManager")
|
|||
|
||||
module.exports = ProjectCreationHandler =
|
||||
|
||||
createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
|
||||
createBlankProject : (owner_id, projectName, attributes, callback = (error, project) ->)->
|
||||
metrics.inc("project-creation")
|
||||
if arguments.length == 3
|
||||
callback = projectHistoryId
|
||||
projectHistoryId = null
|
||||
callback = attributes
|
||||
attributes = null
|
||||
|
||||
ProjectDetailsHandler.validateProjectName projectName, (error) ->
|
||||
return callback(error) if error?
|
||||
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
||||
if projectHistoryId?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, projectHistoryId, (error, project) ->
|
||||
if attributes?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, attributes, (error, project) ->
|
||||
return callback(error) if error?
|
||||
AnalyticsManger.recordEvent(
|
||||
owner_id, 'project-imported', { projectId: project._id, projectHistoryId: projectHistoryId }
|
||||
owner_id, 'project-imported', { projectId: project._id, attributes: attributes }
|
||||
)
|
||||
callback(error, project)
|
||||
else
|
||||
HistoryManager.initializeProject (error, history) ->
|
||||
return callback(error) if error?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, history?.overleaf_id, (error, project) ->
|
||||
attributes = overleaf: history: id: history?.overleaf_id
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, attributes, (error, project) ->
|
||||
return callback(error) if error?
|
||||
AnalyticsManger.recordEvent(
|
||||
owner_id, 'project-created', { projectId: project._id }
|
||||
)
|
||||
callback(error, project)
|
||||
|
||||
_createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
|
||||
_createBlankProject : (owner_id, projectName, attributes, callback = (error, project) ->)->
|
||||
rootFolder = new Folder {'name':'rootFolder'}
|
||||
project = new Project
|
||||
owner_ref : new ObjectId(owner_id)
|
||||
name : projectName
|
||||
project.overleaf.history.id = projectHistoryId
|
||||
|
||||
attributes.owner_ref = new ObjectId(owner_id)
|
||||
attributes.name = projectName
|
||||
project = new Project attributes
|
||||
|
||||
Object.assign(project, attributes)
|
||||
|
||||
if Settings.apis?.project_history?.displayHistoryForNewProjects
|
||||
project.overleaf.history.display = true
|
||||
if Settings.currentImageName?
|
||||
|
|
|
@ -98,7 +98,11 @@ describe 'ProjectCreationHandler', ->
|
|||
|
||||
it "should set the overleaf id if overleaf id provided", (done)->
|
||||
overleaf_id = 2345
|
||||
@handler.createBlankProject ownerId, projectName, overleaf_id, (err, project)->
|
||||
attributes =
|
||||
overleaf:
|
||||
history:
|
||||
id: overleaf_id
|
||||
@handler.createBlankProject ownerId, projectName, attributes, (err, project)->
|
||||
project.overleaf.history.id.should.equal overleaf_id
|
||||
done()
|
||||
|
||||
|
|
Loading…
Reference in a new issue