Refresh members and invites in client when status changes

This commit is contained in:
Shane Kilkelly 2016-08-05 14:01:08 +01:00
parent 8f7603c324
commit eafd61a90e
6 changed files with 42 additions and 8 deletions

View file

@ -37,6 +37,7 @@ module.exports = CollaboratorsController =
user_id = req.params.user_id
CollaboratorsController._removeUserIdFromProject project_id, user_id, (error) ->
return next(error) if error?
EditorRealTimeController.emitToRoom project_id, 'project:membership:changed', {members: true}
res.sendStatus 204
removeSelfFromProject: (req, res, next = (error) ->) ->

View file

@ -5,6 +5,7 @@ CollaboratorsHandler = require('./CollaboratorsHandler')
CollaboratorsInviteHandler = require('./CollaboratorsInviteHandler')
logger = require('logger-sharelatex')
EmailHelper = require "../Helpers/EmailHelper"
EditorRealTimeController = require("../Editor/EditorRealTimeController")
module.exports = CollaboratorsInviteController =
@ -38,6 +39,7 @@ module.exports = CollaboratorsInviteController =
logger.err {projectId, email, sendingUserId}, "error creating project invite"
return next(err)
logger.log {projectId, email, sendingUserId}, "invite created"
EditorRealTimeController.emitToRoom projectId, 'project:membership:changed', {invites: true}
return res.json {invite: invite}
revokeInvite: (req, res, next) ->
@ -48,6 +50,7 @@ module.exports = CollaboratorsInviteController =
if err?
logger.err {projectId, inviteId}, "error revoking invite"
return next(err)
EditorRealTimeController.emitToRoom projectId, 'project:membership:changed', {invites: true}
res.sendStatus(201)
resendInvite: (req, res, next) ->
@ -113,4 +116,5 @@ module.exports = CollaboratorsInviteController =
if err?
logger.err {projectId, inviteId}, "error accepting invite by token"
return next(err)
EditorRealTimeController.emitToRoom projectId, 'project:membership:changed', {invites: true, members: true}
res.redirect "/project/#{projectId}"

View file

@ -1,13 +1,24 @@
define [
"base"
], (App) ->
App.controller "ShareController", ["$scope", "$modal", "event_tracking", ($scope, $modal, event_tracking) ->
$scope.openShareProjectModal = () ->
event_tracking.sendCountlyOnce "ide-open-share-modal-once"
App.controller "ShareController", ["$scope", "$modal", "ide", "projectInvites", "projectMembers", "event_tracking",
($scope, $modal, ide, projectInvites, projectMembers, event_tracking) ->
$scope.openShareProjectModal = () ->
event_tracking.sendCountlyOnce "ide-open-share-modal-once"
$modal.open(
templateUrl: "shareProjectModalTemplate"
controller: "ShareProjectModalController"
scope: $scope
)
$modal.open(
templateUrl: "shareProjectModalTemplate"
controller: "ShareProjectModalController"
scope: $scope
)
ide.socket.on 'project:membership:changed', (data) =>
if data.members
projectMembers.getMembers().success (responseData) =>
if responseData.members
$scope.project.members = responseData.members
if data.invites
projectInvites.getInvites().success (responseData) =>
if responseData.invites
$scope.project.invites = responseData.invites
]

View file

@ -23,6 +23,8 @@ define [
allowedNoOfMembers = $scope.project.features.collaborators
$scope.canAddCollaborators = noOfMembers < allowedNoOfMembers or allowedNoOfMembers == INFINITE_COLLABORATORS
window._m = projectMembers
$scope.autocompleteContacts = []
do loadAutocompleteUsers = () ->
$http.get "/user/contacts"

View file

@ -128,6 +128,9 @@ describe "CollaboratorsController", ->
it "should send the back a success response", ->
@res.sendStatus.calledWith(204).should.equal true
it 'should have called emitToRoom', ->
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'project:membership:changed').should.equal true
describe "removeSelfFromProject", ->
beforeEach ->
@req.session =

View file

@ -22,6 +22,7 @@ describe "CollaboratorsInviteController", ->
"./CollaboratorsHandler": @CollaboratorsHandler = {}
"./CollaboratorsInviteHandler": @CollaboratorsInviteHandler = {}
'logger-sharelatex': @logger = {err: sinon.stub(), error: sinon.stub(), log: sinon.stub()}
"../Editor/EditorRealTimeController": @EditorRealTimeController = {emitToRoom: sinon.stub()}
@res = new MockResponse()
@req = new MockRequest()
@ -112,6 +113,10 @@ describe "CollaboratorsInviteController", ->
@CollaboratorsInviteHandler.inviteToProject.callCount.should.equal 1
@CollaboratorsInviteHandler.inviteToProject.calledWith(@project_id,@current_user_id,@targetEmail,@privileges).should.equal true
it 'should have called emitToRoom', ->
@EditorRealTimeController.emitToRoom.callCount.should.equal 1
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'project:membership:changed').should.equal true
describe 'when the user is not allowed to add more collaborators', ->
beforeEach ->
@ -499,6 +504,10 @@ describe "CollaboratorsInviteController", ->
it 'should have called revokeInvite', ->
@CollaboratorsInviteHandler.revokeInvite.callCount.should.equal 1
it 'should have called emitToRoom', ->
@EditorRealTimeController.emitToRoom.callCount.should.equal 1
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'project:membership:changed').should.equal true
describe 'when revokeInvite produces an error', ->
beforeEach ->
@ -544,6 +553,10 @@ describe "CollaboratorsInviteController", ->
it 'should have called acceptInvite', ->
@CollaboratorsInviteHandler.acceptInvite.callCount.should.equal 1
it 'should have called emitToRoom', ->
@EditorRealTimeController.emitToRoom.callCount.should.equal 1
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'project:membership:changed').should.equal true
describe 'when revokeInvite produces an error', ->
beforeEach ->