mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
moved clone project from old proj controller to new one with test
This commit is contained in:
parent
5b757ac7ab
commit
6f84f4214f
4 changed files with 40 additions and 25 deletions
|
@ -1,6 +1,7 @@
|
|||
logger = require("logger-sharelatex")
|
||||
projectDeleter = require("./ProjectDeleter")
|
||||
|
||||
projectDuplicator = require("./ProjectDuplicator")
|
||||
metrics = require('../../infrastructure/Metrics')
|
||||
|
||||
|
||||
|
||||
|
@ -14,3 +15,16 @@ module.exports =
|
|||
res.send 500
|
||||
else
|
||||
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)
|
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue