mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
14e014c667
commit
6d4d643fd9
4 changed files with 58 additions and 2 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue