mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #17879 from overleaf/rh-refresh-collab
Refresh websocket on collaborator change GitOrigin-RevId: b05444d592f5952a08bad51c9f529ed9183d042f
This commit is contained in:
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 = {
|
||||
|
|
|
@ -82,8 +82,8 @@ async function setCollaboratorInfo(req, res, next) {
|
|||
)
|
||||
EditorRealTimeController.emitToRoom(
|
||||
projectId,
|
||||
'project:membership:changed',
|
||||
{ members: true }
|
||||
'project:collaboratorAccessLevel:changed',
|
||||
{ userId }
|
||||
)
|
||||
res.sendStatus(204)
|
||||
} catch (err) {
|
||||
|
|
|
@ -58,6 +58,22 @@ function useSocketListeners() {
|
|||
)
|
||||
)
|
||||
|
||||
useSocketListener(
|
||||
socket,
|
||||
'project:collaboratorAccessLevel:changed',
|
||||
useCallback(() => {
|
||||
listProjectMembers(projectId)
|
||||
.then(({ members }) => {
|
||||
if (members) {
|
||||
setProjectMembers(members)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
debugConsole.error('Error fetching members for project', err)
|
||||
})
|
||||
}, [projectId, setProjectMembers])
|
||||
)
|
||||
|
||||
useSocketListener(
|
||||
socket,
|
||||
'project:membership:changed',
|
||||
|
|
Loading…
Reference in a new issue