Skip to content

Commit 9191ad8

Browse files
committed
fix(realtime): allow the write role to persist a block retry policy
`update-retry` was added to the protocol but not to the write-role allowlist, so the editor applied the change optimistically while the server dropped it and the policy never reached the database. Adds a test asserting the write role holds every per-block operation the protocol declares, so the next block setting cannot repeat this silently.
1 parent 466dac0 commit 9191ad8

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

apps/realtime/src/middleware/permissions.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* - Edge cases and invalid inputs
88
*/
99

10-
import { ALL_SOCKET_OPERATIONS } from '@sim/realtime-protocol/constants'
10+
import { ALL_SOCKET_OPERATIONS, BLOCK_OPERATIONS } from '@sim/realtime-protocol/constants'
1111
import {
1212
expectPermissionAllowed,
1313
expectPermissionDenied,
@@ -232,6 +232,17 @@ describe('checkRolePermission', () => {
232232
expect(adminOnly.length).toBeGreaterThan(0)
233233
})
234234

235+
it('grants write every per-block operation the protocol declares', () => {
236+
// A block operation that reaches this gate is an ordinary editor edit, so the
237+
// write role must hold all of them. Without this, adding a block setting to
238+
// the protocol and forgetting the ACL entry fails silently at runtime: the
239+
// editor applies the change optimistically and the server drops the write.
240+
const denied = Object.values(BLOCK_OPERATIONS).filter(
241+
(operation) => !checkRolePermission('write', operation).allowed
242+
)
243+
expect(denied).toEqual([])
244+
})
245+
235246
it('grants read nothing, so it is trivially a subset of write', () => {
236247
const readAllowed = ALL_SOCKET_OPERATIONS.filter(
237248
(operation) => checkRolePermission('read', operation).allowed

apps/realtime/src/middleware/permissions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const WRITE_OPERATIONS: string[] = [
3030
BLOCK_OPERATIONS.UPDATE_PARENT,
3131
BLOCK_OPERATIONS.UPDATE_ADVANCED_MODE,
3232
BLOCK_OPERATIONS.UPDATE_ERROR_ENABLED,
33+
BLOCK_OPERATIONS.UPDATE_RETRY,
3334
BLOCK_OPERATIONS.UPDATE_CANONICAL_MODE,
3435
BLOCK_OPERATIONS.REPLACE_CANONICAL_MODES,
3536
BLOCK_OPERATIONS.TOGGLE_HANDLES,

0 commit comments

Comments
 (0)