Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Room permissions come from the server when it says

Simon Flack4ec41af2203f
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.rooms.test.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.rooms.test.ts
index 743a5d1e3..d9065e7e7 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.rooms.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.rooms.test.ts
@@ -146,6 +146,21 @@ describe('fetchRoomDetail', () => {
});
});
+describe('what the server says the caller may do', () => {
+ it('carries the server’s own answer when it gives one', async () => {
+ fetchMock.mockImplementation(async () =>
+ jsonResponse({ ...ROOM, can_write: true, can_manage: false })
+ );
+ const room = await fetchRoomDetail(SERVER, 'room-1');
+ expect(room.serverPermissions).toEqual({ canWrite: true, canManage: false });
+ });
+
+ it('leaves it out for a server that does not say, so Console works it out', async () => {
+ const room = await fetchRoomDetail(SERVER, 'room-1');
+ expect(room.serverPermissions).toBeUndefined();
+ });
+});
+
describe('room writes', () => {
it('sends a visibility change in the server’s field names', async () => {
await updateRoom(SERVER, 'room-1', { readVisibility: 'private', writeVisibility: 'private' });
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
index 5483a75ad..31080b75c 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
@@ -3299,6 +3299,9 @@ type RoomSummaryJson = {
archived: boolean;
created_at: string;
write_visibility?: string;
+ /** What the caller may do with the room, decided by the routes' own rules; absent from an older server. */
+ can_write?: boolean;
+ can_manage?: boolean;
};
function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {
@@ -3319,6 +3322,9 @@ function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {
...(r.write_visibility !== undefined
? { writeVisibility: visibilityOf(r.write_visibility) }
: {}),
+ ...(r.can_write !== undefined && r.can_manage !== undefined
+ ? { serverPermissions: { canWrite: r.can_write, canManage: r.can_manage } }
+ : {}),
};
}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.test.ts
index f75c30932..2046a03ef 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.test.ts
@@ -44,6 +44,19 @@ describe('roomPermissionsFor', () => {
expect(roomPermissionsFor({ ownerId: 'u-2' }, ME).canWrite).toBe(true);
});
+ it('takes the server’s answer over its own working when the server gives one', () => {
+ expect(
+ roomPermissionsFor(
+ {
+ ownerId: 'u-1',
+ writeVisibility: 'public',
+ serverPermissions: { canWrite: false, canManage: false },
+ },
+ ME
+ )
+ ).toEqual({ canWrite: false, canManage: false });
+ });
+
it('gives an unknown viewer nothing', () => {
expect(
roomPermissionsFor(
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.ts
index 659864da1..c306a24f8 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-permissions.ts
@@ -10,14 +10,20 @@ import type { RoomVisibility } from '@shared/core/switch-servers/switch-servers'
export type RoomPermissions = { canWrite: boolean; canManage: boolean };
/**
- * The gateway's room rule (`authz.can`), worked out for one viewer. A room
+ * What one viewer may do with a room: the server's own answer when it gives
+ * one, otherwise the gateway's room rule (`authz.can`) worked out here. A room
* whose write access is not known — a server that predates the setting — is
* treated as public, which is what every room was before it existed.
*/
export function roomPermissionsFor(
- room: { ownerId: string | null; writeVisibility?: RoomVisibility },
+ room: {
+ ownerId: string | null;
+ writeVisibility?: RoomVisibility;
+ serverPermissions?: RoomPermissions;
+ },
viewer: { userId: string | null; isAdmin: boolean }
): RoomPermissions {
+ if (room.serverPermissions) return room.serverPermissions;
if (viewer.userId === null) return { canWrite: false, canManage: false };
const canManage = viewer.isAdmin || (room.ownerId !== null && room.ownerId === viewer.userId);
const canWrite = canManage || (room.writeVisibility ?? 'public') === 'public';
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
index 8f77832c8..91d415786 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
@@ -260,7 +260,11 @@ export class SwitchRoomsStore {
*/
roomPermissions(
workspaceId: string,
- room: { ownerId: string | null; writeVisibility?: RoomVisibility }
+ room: {
+ ownerId: string | null;
+ writeVisibility?: RoomVisibility;
+ serverPermissions?: RoomPermissions;
+ }
): RoomPermissions {
const serverId = workspacesStore.serverIdFor(workspaceId);
const user = serverId ? (switchServersStore.statusFor(serverId)?.user ?? null) : null;
diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
index ebf9d8fa6..b39cc0f08 100644
--- a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
@@ -362,6 +362,12 @@ export type RemoteRoomSummary = {
createdAt: string;
/** Who may write to the room, when the server says (see `RoomDetail`); absent from an older server. */
writeVisibility?: RoomVisibility;
+ /**
+ * What the signed-in person may do with the room, as the server decides it
+ * by the rules its routes enforce. Absent from a server that does not say,
+ * where Console works it out the same way (`roomPermissionsFor`).
+ */
+ serverPermissions?: { canWrite: boolean; canManage: boolean };
};
/**