diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 2825d8c12c..7a8d2c3960 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -1,6 +1,7 @@ logger = require("logger-sharelatex") projectDeleter = require("./ProjectDeleter") - +projectDuplicator = require("./ProjectDuplicator") +metrics = require('../../infrastructure/Metrics') @@ -13,4 +14,17 @@ module.exports = if err? res.send 500 else - res.send 200 \ No newline at end of file + res.send 200 + + cloneProject: (req, res)-> + metrics.inc "cloned-project" + project_id = req.params.Project_id + projectName = req.body.projectName + logger.log project_id:project_id, projectName:projectName, "cloning project" + if !req.session.user? + return res.send redir:"/register" + projectDuplicator.duplicate req.session.user, project_id, projectName, (err, project)-> + if err? + logger.error err:err, project_id: project_id, user_id: req.session.user._id, "error cloning project" + return next(err) + res.send(project_id:project._id) \ No newline at end of file diff --git a/services/web/app/coffee/controllers/ProjectController.coffee b/services/web/app/coffee/controllers/ProjectController.coffee index 5b8b75e0db..310caa5804 100755 --- a/services/web/app/coffee/controllers/ProjectController.coffee +++ b/services/web/app/coffee/controllers/ProjectController.coffee @@ -181,26 +181,6 @@ module.exports = class ProjectController @emit "end" if @endEmitted next() - cloneProject: (req, res)-> - metrics.inc "cloned-project" - project_id = req.params.Project_id - projectName = req.body.projectName - logger.log project_id:project_id, projectName:projectName, "cloning project" - if !req.session.user? - return res.send redir:"/register" - projectDuplicator.duplicate req.session.user, project_id, projectName, (err, project)-> - if err? - logger.error err:err, project_id: project_id, user_id: req.session.user._id, "error cloning project" - return next(err) - res.send(project_id:project._id) - - deleteProject: (req, res)-> - project_id = req.params.Project_id - logger.log project_id:project_id, "deleting project" - projectDeleter.deleteProject project_id, (err)-> - if err? - res.send 500 - else - res.send 200 + diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index ff8f24a304..af846bf268 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -111,7 +111,7 @@ module.exports = class Router app.del "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles app.del '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject - app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, Project.cloneProject + app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, ProjectController.cloneProject app.post '/Project/:Project_id/snapshot', SecurityManager.requestCanModifyProject, versioningController.takeSnapshot app.get '/Project/:Project_id/version', SecurityManager.requestCanAccessProject, versioningController.listVersions diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee index 752d95ff6d..09ca362829 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -10,19 +10,31 @@ describe "ProjectController", -> beforeEach -> + @project_id = "123213jlkj9kdlsaj" + @settings = {} @ProjectDeleter = deleteProject: sinon.stub().callsArgWith(1) + @ProjectDuplicator = + duplicate: sinon.stub().callsArgWith(3, null, {_id:@project_id}) @ProjectController = SandboxedModule.require modulePath, requires: "settings-sharelatex":@settings "logger-sharelatex": log:-> "./ProjectDeleter": @ProjectDeleter + "./ProjectDuplicator": @ProjectDuplicator - @project_id = "123213jlkj9kdlsaj" + @user = + _id:"!£123213kjljkl" + first_name: "bjkdsjfk" + @projectName = "£12321jkj9ujkljds" @req = params: Project_id: @project_id + session: + user: @user + body: + projectName: @projectName @res = {} describe "deleteProject", -> @@ -35,3 +47,12 @@ describe "ProjectController", -> done() @ProjectController.deleteProject @req, @res + + describe "cloneProject", -> + + it "should call the project duplicator", (done)-> + @res.send = (json)=> + @ProjectDuplicator.duplicate.calledWith(@user, @project_id, @projectName).should.equal true + json.project_id.should.equal @project_id + done() + @ProjectController.cloneProject @req, @res