added a change privlage level for user to new collab handler, won't work yet but is starting point

This commit is contained in:
Henry Oswald 2014-04-07 16:54:51 +01:00
parent fa78db5c59
commit ff88849444
3 changed files with 57 additions and 7 deletions

View file

@ -0,0 +1,17 @@
User = require('../models/User').User
Settings = require('settings-sharelatex')
EmailHandler = require("../Email/EmailHandler")
projectEntityHandler = require '../Project/ProjectEntityHandler'
mimelib = require("mimelib")
module.exports =
changeUsersPrivlageLevel: (project_id, user_id, newPrivalageLevel, callback)->
@removeUserFromProject project_id, user_id, =>
User.findById user_id, (err, user)=>
@addUserToProject project_id, user_id, newPrivalageLevel, callback

View file

@ -74,10 +74,4 @@ module.exports = class ProjectHandler
if err?
logger.err err: err, "problem removing user from project collaberators"
if callback?
callback()
changeUsersPrivlageLevel: (project_id, user_id, newPrivalageLevel)->
@removeUserFromProject project_id, user_id, ()=>
User.findById user_id, (err, user)=>
if user
@addUserToProject project_id, user.email, newPrivalageLevel
callback()

View file

@ -0,0 +1,39 @@
should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/Collaborators/CollaboratorsHandler"
expect = require("chai").expect
describe "CollaboratorsHandler", ->
beforeEach ->
@user =
email:"bob@bob.com"
@UserModel =
findById:sinon.stub().callsArgWith(1, null, @user)
@settings = {}
@CollaboratorHandler = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
'../models/User': User:@UserModel
@project_id = "123l2j13lkj"
@user_id = "132kj1lk2j"
describe "changeUsersPrivlageLevel", ->
it "should call removeUserFromProject then addUserToProject", (done)->
@CollaboratorHandler.removeUserFromProject = sinon.stub().callsArgWith(2)
@CollaboratorHandler.addUserToProject = sinon.stub().callsArgWith(3)
newPrivalageLevel = "readAndWrite"
@CollaboratorHandler.changeUsersPrivlageLevel @project_id, @user_id, newPrivalageLevel, =>
@CollaboratorHandler.removeUserFromProject.calledWith(@project_id, @user_id).should.equal true
@CollaboratorHandler.addUserToProject.calledWith(@project_id, @user_id, newPrivalageLevel)
done()