From 78c5741d06f596df3a983300fc094515a5f0b8ed Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 8 Oct 2015 16:42:23 +0100 Subject: [PATCH] Add contact when adding collaborator --- .../Collaborators/CollaboratorsController.coffee | 6 ++++++ .../Collaborators/CollaboratorsControllerTests.coffee | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee index 8c53c278cb..6999b16bc5 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee @@ -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) -> diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee index 3a6e032456..def122044a 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee @@ -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