Merge pull request #17879 from overleaf/rh-refresh-collab

Refresh websocket on collaborator change

GitOrigin-RevId: b05444d592f5952a08bad51c9f529ed9183d042f
This commit is contained in:
roo hutton
2024-04-17 08:05:18 +00:00
committed by Copybot
parent 407a1f640b
commit d53a3e315e
4 changed files with 59 additions and 3 deletions
@@ -44,6 +44,9 @@ module.exports = WebsocketLoadBalancer = {
) {
return true
}
} else if (message?.message === 'project:collaboratorAccessLevel:changed') {
const changedUserId = message.payload[0].userId
return userId === changedUserId
}
return false
},
@@ -181,7 +184,11 @@ module.exports = WebsocketLoadBalancer = {
},
'disconnecting client'
)
client.emit('project:access:revoked')
if (
message?.message !== 'project:collaboratorAccessLevel:changed'
) {
client.emit('project:access:revoked')
}
client.disconnect()
} else {
if (isRestrictedMessage && client.ol_context.is_restricted_user) {
@@ -69,6 +69,39 @@ describe('WebsocketLoadBalancer', function () {
).to.equal(false)
})
describe('collaborator access level changed', function () {
const messageName = 'project:collaboratorAccessLevel:changed'
const client = {
ol_context: { user_id: 'abcd' },
}
it('should return true if the user id matches', function () {
const message = {
message: messageName,
payload: [
{
userId: 'abcd',
},
],
}
expect(
this.WebsocketLoadBalancer.shouldDisconnectClient(client, message)
).to.equal(true)
})
it('should return false if the user id does not match', function () {
const message = {
message: messageName,
payload: [
{
userId: 'xyz',
},
],
}
expect(
this.WebsocketLoadBalancer.shouldDisconnectClient(client, message)
).to.equal(false)
})
})
describe('user removed from project', function () {
const messageName = 'userRemovedFromProject'
const client = {