From 9ccdf073c443bd93f188dc4f86f6527d24e566d3 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Thu, 10 May 2018 11:39:23 +0100 Subject: [PATCH] accept attributes rather than projectHistoryId to ProjectCreationHandler --- .../Project/ProjectCreationHandler.coffee | 28 +++++++++++-------- .../ProjectCreationHandlerTests.coffee | 6 +++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee b/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee index 0b66b38ad6..529164a49e 100644 --- a/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectCreationHandler.coffee @@ -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? diff --git a/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee index 042dc34d09..6d86545622 100644 --- a/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee @@ -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()