Move collaborator HTTP end points into the Collaborators feature

This commit is contained in:
James Allen 2014-11-06 12:20:45 +00:00
parent 5c3e8e6d88
commit e596b60af0
8 changed files with 68 additions and 57 deletions

View file

@ -1,6 +1,6 @@
ProjectGetter = require "../Project/ProjectGetter"
CollaboratorsHandler = require "./CollaboratorsHandler"
EditorController = require "../Editor/EditorController"
module.exports = CollaboratorsController =
getCollaborators: (req, res, next = (error) ->) ->
@ -20,6 +20,20 @@ module.exports = CollaboratorsController =
CollaboratorsHandler.removeUserFromProject req.params.project_id, user_id, (error) ->
return next(error) if error?
res.send 204
addUserToProject: (req, res, next) ->
project_id = req.params.Project_id
{email, privileges} = req.body
EditorController.addUserToProject project_id, email, privileges, (error, user) ->
return next(error) if error?
res.json user: user
removeUserFromProject: (req, res, next) ->
project_id = req.params.Project_id
user_id = req.params.user_id
EditorController.removeUserFromProject project_id, user_id, (error)->
return next(error) if error?
res.send 204
_formatCollaborators: (project, callback = (error, collaborators) ->) ->
collaborators = []

View file

@ -0,0 +1,11 @@
CollaboratorsController = require('./CollaboratorsController')
SecurityManager = require('../../managers/SecurityManager')
AuthenticationController = require('../Authentication/AuthenticationController')
module.exports =
apply: (app) ->
app.post '/project/:project_id/leave', AuthenticationController.requireLogin(), CollaboratorsController.removeSelfFromProject
app.get '/project/:Project_id/collaborators', SecurityManager.requestCanAccessProject(allow_auth_token: true), CollaboratorsController.getCollaborators
app.post '/project/:Project_id/users', SecurityManager.requestIsOwner, CollaboratorsController.addUserToProject
app.delete '/project/:Project_id/users/:user_id', SecurityManager.requestIsOwner, CollaboratorsController.removeUserFromProject

View file

@ -76,18 +76,5 @@ module.exports = EditorHttpController =
EditorController.deleteEntity project_id, entity_id, entity_type, "editor", (error) ->
return next(error) if error?
res.send 204
addUserToProject: (req, res, next) ->
project_id = req.params.Project_id
{email, privileges} = req.body
EditorController.addUserToProject project_id, email, privileges, (error, user) ->
return next(error) if error?
res.json user: user
removeUserFromProject: (req, res, next) ->
project_id = req.params.Project_id
user_id = req.params.user_id
EditorController.removeUserFromProject project_id, user_id, (error)->
return next(error) if error?
res.send 204

View file

@ -14,6 +14,3 @@ module.exports =
app.delete '/project/:Project_id/folder/:entity_id', SecurityManager.requestCanModifyProject, EditorHttpController.deleteFolder
app.post '/project/:Project_id/doc/:doc_id/restore', SecurityManager.requestCanModifyProject, EditorHttpController.restoreDoc
app.post '/project/:Project_id/users', SecurityManager.requestIsOwner, EditorHttpController.addUserToProject
app.delete '/project/:Project_id/users/:user_id', SecurityManager.requestIsOwner, EditorHttpController.removeUserFromProject

View file

@ -20,7 +20,7 @@ TemplatesController = require('./Features/Templates/TemplatesController')
TemplatesMiddlewear = require('./Features/Templates/TemplatesMiddlewear')
AuthenticationController = require('./Features/Authentication/AuthenticationController')
TagsController = require("./Features/Tags/TagsController")
CollaboratorsController = require('./Features/Collaborators/CollaboratorsController')
CollaboratorsRouter = require('./Features/Collaborators/CollaboratorsRouter')
UserInfoController = require('./Features/User/UserInfoController')
UserController = require("./Features/User/UserController")
UserPagesController = require('./Features/User/UserPagesController')
@ -63,6 +63,7 @@ module.exports = class Router
app.post '/register', UserController.register
EditorRouter.apply(app)
CollaboratorsRouter.apply(app)
SubscriptionRouter.apply(app)
UploadsRouter.apply(app)
PasswordResetRouter.apply(app)
@ -113,7 +114,6 @@ module.exports = class Router
app.get "/project/:Project_id/sync/code", SecurityManager.requestCanAccessProject, CompileController.proxySync
app.get "/project/:Project_id/sync/pdf", SecurityManager.requestCanAccessProject, CompileController.proxySync
app.del '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject
app.post '/Project/:Project_id/restore', SecurityManager.requestIsOwner, ProjectController.restoreProject
app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, ProjectController.cloneProject
@ -124,9 +124,6 @@ module.exports = class Router
app.get "/project/:Project_id/doc/:doc_id/diff", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
app.post "/project/:Project_id/doc/:doc_id/version/:version_id/restore", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
app.post '/project/:project_id/leave', AuthenticationController.requireLogin(), CollaboratorsController.removeSelfFromProject
app.get '/project/:Project_id/collaborators', SecurityManager.requestCanAccessProject(allow_auth_token: true), CollaboratorsController.getCollaborators
app.get '/project/:Project_id/connected_users', SecurityManager.requestCanAccessProject, ConnectedUsersController.getConnectedUsers
app.get '/Project/:Project_id/download/zip', SecurityManager.requestCanAccessProject, ProjectDownloadsController.downloadProject

View file

@ -16,6 +16,7 @@ describe "CollaboratorsController", ->
@CollaboratorsController = SandboxedModule.require modulePath, requires:
"../Project/ProjectGetter": @ProjectGetter = {}
"./CollaboratorsHandler": @CollaboratorsHandler
"../Editor/EditorController": @EditorController = {}
@res = new MockResponse()
@req = new MockRequest()
@ -65,6 +66,43 @@ describe "CollaboratorsController", ->
it "should return a success code", ->
@res.statusCode.should.equal 204
describe "addUserToProject", ->
beforeEach ->
@req.params =
Project_id: @project_id = "project-id-123"
@req.body =
email: @email = "joe@example.com"
privileges: @privileges = "readAndWrite"
@res.json = sinon.stub()
@EditorController.addUserToProject = sinon.stub().callsArgWith(3, null, @user = {"mock": "user"})
@CollaboratorsController.addUserToProject @req, @res
it "should add the user to the project", ->
@EditorController.addUserToProject
.calledWith(@project_id, @email, @privileges)
.should.equal true
it "should send the back the added user", ->
@res.json.calledWith(user: @user).should.equal true
describe "removeUserFromProject", ->
beforeEach ->
@req.params =
Project_id: @project_id = "project-id-123"
user_id: @user_id = "user-id-123"
@res.send = sinon.stub()
@EditorController.removeUserFromProject = sinon.stub().callsArg(2)
@CollaboratorsController.removeUserFromProject @req, @res
it "should from the user from the project", ->
@EditorController.removeUserFromProject
.calledWith(@project_id, @user_id)
.should.equal true
it "should send the back a success response", ->
@res.send.calledWith(204).should.equal true
describe "_formatCollaborators", ->
beforeEach ->

View file

@ -26,6 +26,7 @@ describe "CollaboratorsHandler", ->
err:->
'../../models/User': User:@UserModel
"../../models/Project": Project:@ProjectModel
"../Email/EmailHandler": {}
@project_id = "123l2j13lkj"
@user_id = "132kj1lk2j"

View file

@ -157,37 +157,3 @@ describe "EditorHttpController", ->
it "should send back a success response", ->
@res.send.calledWith(204).should.equal true
describe "addUserToProject", ->
beforeEach ->
@req.params =
Project_id: @project_id
@req.body =
email: @email = "joe@example.com"
privileges: @privileges = "readAndWrite"
@EditorController.addUserToProject = sinon.stub().callsArgWith(3, null, @user = {"mock": "user"})
@EditorHttpController.addUserToProject @req, @res
it "should add the user to the project", ->
@EditorController.addUserToProject
.calledWith(@project_id, @email, @privileges)
.should.equal true
it "should send the back the added user", ->
@res.json.calledWith(user: @user).should.equal true
describe "removeUserFromProject", ->
beforeEach ->
@req.params =
Project_id: @project_id
user_id: @user_id = "user-id-123"
@EditorController.removeUserFromProject = sinon.stub().callsArg(2)
@EditorHttpController.removeUserFromProject @req, @res
it "should from the user from the project", ->
@EditorController.removeUserFromProject
.calledWith(@project_id, @user_id)
.should.equal true
it "should send the back a success response", ->
@res.send.calledWith(204).should.equal true