fix(realtime): take a socket out of a room once its access ends

A socket was let into a trip room or a journey's book room with one access
check and then trusted: delivery went by room membership alone. So a member
removed from a trip kept receiving every broadcast of it on the socket they
had already joined, a contributor taken off a journey kept the book's
pointers and presence and could still send pointers, and a deleted account's
sockets stayed in every room.

The gateway now installs the checks its joins run, and every write that ends
access asks the sockets already in again once it is committed and its own
event went out: a member removed or leaving (REST, MCP and plugin RPC), a
trip deleted, a contributor removed, a journey deleted, a trip's journal
link replaced, narrowed or removed. Open books are asked again with every
trip change, since a book can be open through a trip's journal. A socket
that no longer passes leaves the room, and a book that loses somebody tells
the others. A deleted account's sockets are closed. An answer that cannot be
had counts as no access.
This commit is contained in:
Maurice
2026-11-27 21:29:34 +01:00
parent 512584b4f1
commit d8be9a40e7
11 changed files with 458 additions and 4 deletions
+9 -1
View File
@@ -135,7 +135,13 @@ export function build(
const permissions = {
checkPermission: vi.fn((a: string) => (opts.allow ? opts.allow(a) : true)),
} as unknown as PermissionsService;
const realtime = { broadcast: vi.fn() } as unknown as RealtimeService & { broadcast: ReturnType<typeof vi.fn> };
const realtime = {
broadcast: vi.fn(),
recheckTripAccess: vi.fn(async () => undefined),
} as unknown as RealtimeService & {
broadcast: ReturnType<typeof vi.fn>;
recheckTripAccess: ReturnType<typeof vi.fn>;
};
const guards = new PluginGuards(
db,
permissions,
@@ -429,6 +435,8 @@ describe('TripsRpc membership', () => {
expect((await f.host().dispatch(req('trips.removeMember', { tripId: 1, userId: 7 }), 42)).ok).toBe(true);
expect(f.roster.removeMember).toHaveBeenCalledWith(1, 7, 42);
expect(f.realtime.broadcast).toHaveBeenCalledWith(1, 'member:removed', { userId: 7 });
// The removed member's sockets already in the room are asked again.
expect(f.realtime.recheckTripAccess).toHaveBeenCalledWith({ tripId: 1, userId: 7 });
});
it('TRIPS-RPC-018 without member_manage nothing changes', async () => {