Merge pull request #13325 from overleaf/jpa-real-time-check

[real-time] add check for project admin

GitOrigin-RevId: 1677b78cf7f263fc98ca539e26e21553d0ea55bd
This commit is contained in:
Jakob Ackermann 2023-06-05 11:18:00 +01:00 committed by Copybot
parent 14e014c667
commit 6d4d643fd9
4 changed files with 58 additions and 2 deletions

View file

@ -179,9 +179,32 @@ module.exports = WebsocketLoadBalancer = {
client.emit('project:access:revoked') client.emit('project:access:revoked')
client.disconnect() client.disconnect()
} else { } else {
if ( if (isRestrictedMessage && client.ol_context.is_restricted_user) {
!(isRestrictedMessage && client.ol_context.is_restricted_user) // hide restricted message
logger.debug(
{
message,
clientId: client.id,
userId: client.ol_context.user_id,
projectId: client.ol_context.project_id,
},
'hiding restricted message from client'
)
} else if (
message.message === 'project:tokens:changed' &&
client.ol_context.owner_id !== client.ol_context.user_id
) { ) {
// hide owner only message
logger.debug(
{
message,
clientId: client.id,
userId: client.ol_context.user_id,
projectId: client.ol_context.project_id,
},
'hiding owner only message from client'
)
} else {
client.emit(message.message, ...message.payload) client.emit(message.message, ...message.payload)
} }
} }

View file

@ -66,6 +66,7 @@ describe('joinProject', function () {
it('should return the project', function () { it('should return the project', function () {
return this.project.should.deep.equal({ return this.project.should.deep.equal({
name: 'Test Project', name: 'Test Project',
owner: { _id: this.user_id },
}) })
}) })

View file

@ -234,6 +234,7 @@ describe('receiveEditorEvent', function () {
'userRemovedFromProject', 'userRemovedFromProject',
'project:publicAccessLevel:changed', 'project:publicAccessLevel:changed',
'project:access:revoked', 'project:access:revoked',
'project:tokens:changed',
] ]
for (const eventName of eventNames) { for (const eventName of eventNames) {
@ -273,6 +274,32 @@ describe('receiveEditorEvent', function () {
} }
}) })
describe('event: project:tokens:changed', function () {
beforeEach(function (done) {
rclient.publish(
'editor-events',
JSON.stringify({
room_id: this.project_id,
message: 'project:tokens:changed',
payload: [{ tokens: 'TOKENS' }],
})
)
setTimeout(done, 200)
})
it('should send the event to the owner', function () {
expect(this.owner_updates).to.deep.equal([
{ 'project:tokens:changed': { tokens: 'TOKENS' } },
])
})
it('should not send the event to the other clients', function () {
expect(this.user_a_updates).to.deep.equal([])
expect(this.user_b_updates).to.deep.equal([])
expect(this.user_c_updates).to.deep.equal([])
})
})
describe('event: project:publicAccessLevel:changed, set to private', function () { describe('event: project:publicAccessLevel:changed, set to private', function () {
beforeEach(function (done) { beforeEach(function (done) {
/** /**

View file

@ -33,6 +33,11 @@ module.exports = MockWebServer = {
MockWebServer.privileges[projectId][userId] || MockWebServer.privileges[projectId][userId] ||
MockWebServer.privileges[projectId]['anonymous-user'] MockWebServer.privileges[projectId]['anonymous-user']
const userMetadata = MockWebServer.userMetadata[projectId]?.[userId] const userMetadata = MockWebServer.userMetadata[projectId]?.[userId]
if (privilegeLevel === 'owner') {
project.owner = { _id: userId }
} else {
project.owner = { _id: '404404404404404404404404' }
}
return callback(null, project, privilegeLevel, userMetadata) return callback(null, project, privilegeLevel, userMetadata)
}, },