mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-24 02:30:56 +00:00
Add contact when adding collaborator
This commit is contained in:
parent
d11d536994
commit
78c5741d06
2 changed files with 15 additions and 0 deletions
|
@ -5,6 +5,7 @@ ProjectEditorHandler = require "../Project/ProjectEditorHandler"
|
|||
EditorRealTimeController = require "../Editor/EditorRealTimeController"
|
||||
UserGetter = require "../User/UserGetter"
|
||||
LimitationsManager = require "../Subscription/LimitationsManager"
|
||||
ContactManager = require "../Contacts/ContactManager"
|
||||
mimelib = require("mimelib")
|
||||
|
||||
module.exports = CollaboratorsController =
|
||||
|
@ -36,8 +37,13 @@ module.exports = CollaboratorsController =
|
|||
UserGetter.getUser user_id, (error, raw_user) ->
|
||||
return next(error) if error?
|
||||
user = ProjectEditorHandler.buildUserModelView(raw_user, privileges)
|
||||
|
||||
# These things can all be done in the background
|
||||
adding_user_id = req.session?.user?._id
|
||||
CollaboratorsEmailHandler.notifyUserOfProjectShare project_id, user.email
|
||||
EditorRealTimeController.emitToRoom(project_id, 'userAddedToProject', user, privileges)
|
||||
ContactManager.addContact adding_user_id, user_id
|
||||
|
||||
return res.json { user: user }
|
||||
|
||||
removeUserFromProject: (req, res, next) ->
|
||||
|
|
|
@ -19,6 +19,7 @@ describe "CollaboratorsController", ->
|
|||
"../Editor/EditorRealTimeController": @EditorRealTimeController = {}
|
||||
'../Subscription/LimitationsManager' : @LimitationsManager = {}
|
||||
'../Project/ProjectEditorHandler' : @ProjectEditorHandler = {}
|
||||
"../Contacts/ContactManager": @ContactManager = {}
|
||||
@res = new MockResponse()
|
||||
@req = new MockRequest()
|
||||
|
||||
|
@ -61,6 +62,8 @@ describe "CollaboratorsController", ->
|
|||
@req.body =
|
||||
email: @email = "Joe@example.com"
|
||||
privileges: @privileges = "readOnly"
|
||||
@req.session =
|
||||
user: _id: @adding_user_id = "adding-user-id"
|
||||
@res.json = sinon.stub()
|
||||
@user_id = "mock-user-id"
|
||||
@raw_user = {
|
||||
|
@ -75,6 +78,7 @@ describe "CollaboratorsController", ->
|
|||
@UserGetter.getUser = sinon.stub().callsArgWith(1, null, @user)
|
||||
@CollaboratorsEmailHandler.notifyUserOfProjectShare = sinon.stub()
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
@ContactManager.addContact = sinon.stub()
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "when the project can accept more collaborators", ->
|
||||
|
@ -95,6 +99,11 @@ describe "CollaboratorsController", ->
|
|||
@CollaboratorsEmailHandler.notifyUserOfProjectShare
|
||||
.calledWith(@project_id, @email.toLowerCase())
|
||||
.should.equal true
|
||||
|
||||
it "should add the user as a contact for the adding user", ->
|
||||
@ContactManager.addContact
|
||||
.calledWith(@adding_user_id, @user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should send the user as the response body", ->
|
||||
@res.json
|
||||
|
|
Loading…
Reference in a new issue