Skip to content

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

Rooms: answers to review

Simon Flack1a911f72a27b
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 093638667..976c3aa94 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
@@ -159,7 +159,25 @@ describe('what the server says the caller may do', () => {
jsonResponse({ ...ROOM, can_write: true, can_manage: false })
);
const room = await fetchRoomDetail(SERVER, 'room-1');
- expect(room.serverPermissions).toEqual({ canWrite: true, canManage: false });
+ // A server from before detaching had its own rule: it took write access.
+ expect(room.serverPermissions).toEqual({ canWrite: true, canManage: false, canUnlink: true });
+ });
+
+ it('carries who may detach and delete when the server says', async () => {
+ fetchMock.mockImplementation(async () =>
+ jsonResponse({ ...ROOM, can_write: true, can_manage: false, can_unlink: false })
+ );
+ expect((await fetchRoomDetail(SERVER, 'room-1')).serverPermissions).toEqual({
+ canWrite: true,
+ canManage: false,
+ canUnlink: false,
+ });
+ fetchMock.mockImplementation(async () =>
+ jsonResponse([
+ { id: 'd-1', name: 'Notes', description: '', scope: 'room', can_remove: false },
+ ])
+ );
+ expect((await fetchRoomResources(SERVER, 'room-1', 'documents'))[0]!.canRemove).toBe(false);
});
it('leaves it out for a server that does not say, so Console works it out', async () => {
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 dcfb27913..d1eb3d727 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
@@ -3306,6 +3306,7 @@ type RoomSummaryJson = {
/** 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;
+ can_unlink?: boolean;
};
function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {
@@ -3327,7 +3328,14 @@ function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {
? { writeVisibility: visibilityOf(r.write_visibility) }
: {}),
...(r.can_write !== undefined && r.can_manage !== undefined
- ? { serverPermissions: { canWrite: r.can_write, canManage: r.can_manage } }
+ ? {
+ serverPermissions: {
+ canWrite: r.can_write,
+ canManage: r.can_manage,
+ // Detaching took write access until the server said otherwise.
+ canUnlink: r.can_unlink ?? r.can_write,
+ },
+ }
: {}),
};
}
@@ -5102,6 +5110,7 @@ type ResourceJson = {
packages?: string[];
scope?: 'global' | 'room';
created_by_agent_name?: string | null;
+ can_remove?: boolean;
};
function mapResource(kind: RoomResourceKind, r: ResourceJson): RoomResource {
@@ -5118,6 +5127,7 @@ function mapResource(kind: RoomResourceKind, r: ResourceJson): RoomResource {
roomScoped: r.scope === 'room',
createdByAgentName: r.created_by_agent_name ?? null,
packageIds: r.packages ?? [],
+ ...(r.can_remove !== undefined ? { canRemove: r.can_remove } : {}),
};
}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx
index febc3f15a..2520a8110 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-configuration-panel.tsx
@@ -76,7 +76,11 @@ const ChatConfiguration = observer(function ChatConfiguration({
<RolesSection
workspaceId={workspaceId}
room={detail.data}
- permissions={{ canWrite: chat.canManage, canManage: chat.canManage }}
+ permissions={{
+ canWrite: chat.canManage,
+ canManage: chat.canManage,
+ canUnlink: chat.canManage,
+ }}
/>
<RoomInfoSection room={detail.data} />
</>
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx
index d85b2bf87..9898d0aa7 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-resources-panel.tsx
@@ -65,10 +65,14 @@ export const RoomResourcesPanel = observer(function RoomResourcesPanel({
}
const room = detail.data ?? null;
// A Console chat's members may read it but only its managers change it.
- const canWrite =
+ const permissions =
opensAsConsoleChat(roomId) && chat
- ? chat.canManage
- : room !== null && switchRoomsStore.roomPermissions(workspaceId, room).canWrite;
+ ? { canWrite: chat.canManage, canManage: chat.canManage, canUnlink: chat.canManage }
+ : room !== null
+ ? switchRoomsStore.roomPermissions(workspaceId, room)
+ : { canWrite: false, canManage: false, canUnlink: false };
+ const canWrite = permissions.canWrite;
+ const canUnlink = permissions.canUnlink;
return (
<div className="h-full overflow-y-auto">
@@ -78,18 +82,21 @@ export const RoomResourcesPanel = observer(function RoomResourcesPanel({
roomId={roomId}
kind="references"
canWrite={canWrite}
+ canUnlink={canUnlink}
/>
<ResourceSection
workspaceId={workspaceId}
roomId={roomId}
kind="documents"
canWrite={canWrite}
+ canUnlink={canUnlink}
/>
<ResourceSection
workspaceId={workspaceId}
roomId={roomId}
kind="packages"
canWrite={canWrite}
+ canUnlink={canUnlink}
/>
<LinkedRoomsSection workspaceId={workspaceId} roomId={roomId} canWrite={canWrite} />
</div>
@@ -102,11 +109,15 @@ const ResourceSection = observer(function ResourceSection({
roomId,
kind,
canWrite,
+ canUnlink,
}: {
workspaceId: string;
roomId: string;
kind: RoomResourceKind;
+ /** Attaching. */
canWrite: boolean;
+ /** Detaching, which the server keeps for those taking part and admins. */
+ canUnlink: boolean;
}) {
const queryClient = useQueryClient();
const key = roomResourcesKey(workspaceId, roomId, kind);
@@ -189,7 +200,7 @@ const ResourceSection = observer(function ResourceSection({
? () => setReading(resource)
: null
}
- removeLabel={canWrite ? `Detach ${resource.name}` : null}
+ removeLabel={canUnlink ? `Detach ${resource.name}` : null}
busy={busy === resource.id}
onRemove={() => void detach(resource)}
/>
@@ -206,8 +217,14 @@ const ResourceSection = observer(function ResourceSection({
resource={resource}
via={[]}
onOpen={() => setReading(resource)}
- removeLabel={canWrite ? `Delete ${resource.name}` : null}
+ // Deleting an agent's document is for its author, the room's owner
+ // and admins: the server says per document, else detaching's rule.
+ removeLabel={
+ (resource.canRemove ?? canUnlink) ? `Delete ${resource.name}` : null
+ }
busy={busy === resource.id}
+ // It is deleted for everyone, with no undo, so it asks first.
+ confirm
onRemove={() => void detach(resource)}
/>
))}
@@ -245,6 +262,7 @@ function ResourceRow({
onOpen,
removeLabel,
busy,
+ confirm = false,
onRemove,
}: {
resource: RoomResource;
@@ -254,8 +272,11 @@ function ResourceRow({
/** The remove button's label, or null for someone who may not remove it. */
removeLabel: string | null;
busy: boolean;
+ /** Ask before removing: the first click arms it, the second removes. */
+ confirm?: boolean;
onRemove: () => void;
}) {
+ const [armed, setArmed] = useState(false);
const Icon =
resource.kind === 'packages' ? Package : resource.kind === 'documents' ? FileText : Link2;
const meta = [
@@ -292,14 +313,25 @@ function ResourceRow({
) : (
<div className="flex min-w-0 flex-1 items-center gap-3">{body}</div>
)}
- {removeLabel && (
+ {removeLabel && confirm && armed && (
+ <span className="flex shrink-0 items-center gap-1">
+ <span className="text-xs text-foreground-muted">Delete for everyone?</span>
+ <Button size="sm" variant="ghost" disabled={busy} onClick={() => setArmed(false)}>
+ No
+ </Button>
+ <Button size="sm" variant="destructive" disabled={busy} onClick={onRemove}>
+ {busy ? <Loader2 className="animate-spin" /> : 'Delete'}
+ </Button>
+ </span>
+ )}
+ {removeLabel && !(confirm && armed) && (
<Button
variant="ghost"
size="icon-xs"
aria-label={removeLabel}
title={removeLabel}
disabled={busy}
- onClick={onRemove}
+ onClick={confirm ? () => setArmed(true) : onRemove}
>
{busy ? <Loader2 className="animate-spin" /> : <X />}
</Button>
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx
index c156d6d4c..89dad10cd 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-rooms/room-settings-sections.tsx
@@ -558,7 +558,8 @@ export const ArchiveRoomSection = observer(function ArchiveRoomSection({
: 'Archiving…'
: room.archived
? 'Unarchive'
- : 'Archive'}
+ : // The room is hidden for everyone, not just you.
+ 'Archive for everyone'}
</Button>
</div>
);
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 2046a03ef..ee80a90da 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
@@ -4,10 +4,11 @@ import { roomPermissionsFor } from './room-permissions';
const ME = { userId: 'u-1', isAdmin: false };
describe('roomPermissionsFor', () => {
- it('lets the owner manage and write', () => {
+ it('lets the owner manage, write and detach', () => {
expect(roomPermissionsFor({ ownerId: 'u-1', writeVisibility: 'private' }, ME)).toEqual({
canWrite: true,
canManage: true,
+ canUnlink: true,
});
});
@@ -17,13 +18,14 @@ describe('roomPermissionsFor', () => {
{ ownerId: 'u-2', writeVisibility: 'private' },
{ userId: 'u-1', isAdmin: true }
)
- ).toEqual({ canWrite: true, canManage: true });
+ ).toEqual({ canWrite: true, canManage: true, canUnlink: true });
});
it('lets anyone write to a publicly writable room, but not manage it', () => {
expect(roomPermissionsFor({ ownerId: 'u-2', writeVisibility: 'public' }, ME)).toEqual({
canWrite: true,
canManage: false,
+ canUnlink: true,
});
});
@@ -31,6 +33,7 @@ describe('roomPermissionsFor', () => {
expect(roomPermissionsFor({ ownerId: 'u-2', writeVisibility: 'private' }, ME)).toEqual({
canWrite: false,
canManage: false,
+ canUnlink: false,
});
});
@@ -40,21 +43,23 @@ describe('roomPermissionsFor', () => {
);
});
- it('reads an unknown write access as public, as rooms were before the setting', () => {
- expect(roomPermissionsFor({ ownerId: 'u-2' }, ME).canWrite).toBe(true);
+ it('offers no writing on a room whose write access is not known, so nothing it shows is refused', () => {
+ expect(roomPermissionsFor({ ownerId: 'u-2' }, ME)).toEqual({
+ canWrite: false,
+ canManage: false,
+ canUnlink: false,
+ });
+ expect(roomPermissionsFor({ ownerId: 'u-1' }, ME).canWrite).toBe(true);
});
it('takes the server’s answer over its own working when the server gives one', () => {
+ const answer = { canWrite: true, canManage: false, canUnlink: false };
expect(
roomPermissionsFor(
- {
- ownerId: 'u-1',
- writeVisibility: 'public',
- serverPermissions: { canWrite: false, canManage: false },
- },
+ { ownerId: 'u-1', writeVisibility: 'public', serverPermissions: answer },
ME
)
- ).toEqual({ canWrite: false, canManage: false });
+ ).toEqual(answer);
});
it('gives an unknown viewer nothing', () => {
@@ -63,6 +68,6 @@ describe('roomPermissionsFor', () => {
{ ownerId: 'u-1', writeVisibility: 'public' },
{ userId: null, isAdmin: true }
)
- ).toEqual({ canWrite: false, canManage: false });
+ ).toEqual({ canWrite: false, canManage: false, canUnlink: false });
});
});
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 c306a24f8..0d1806bd3 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
@@ -5,15 +5,19 @@ import type { RoomVisibility } from '@shared/core/switch-servers/switch-servers'
* workspace admins' alone: deleting the room, changing who may see it, naming
* it after its channel. `canWrite` also covers anyone at all when the room's
* write access is public: its description and instructions, who is in it, its
- * roles, its group, archiving it.
+ * roles, its group, archiving it. `canUnlink` is detaching what is attached
+ * to it: the server now keeps that for those taking part in the room and
+ * workspace admins, whatever its write access.
*/
-export type RoomPermissions = { canWrite: boolean; canManage: boolean };
+export type RoomPermissions = { canWrite: boolean; canManage: boolean; canUnlink: boolean };
/**
* 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.
+ * one, otherwise the gateway's room rule (`authz.can`) worked out here, where
+ * detaching takes write access as it did before the server said otherwise.
+ * A room whose write access is not known offers no writing beyond its owner's
+ * and admins': showing a control the server then refuses is the worse
+ * mistake.
*/
export function roomPermissionsFor(
room: {
@@ -24,8 +28,8 @@ export function roomPermissionsFor(
viewer: { userId: string | null; isAdmin: boolean }
): RoomPermissions {
if (room.serverPermissions) return room.serverPermissions;
- if (viewer.userId === null) return { canWrite: false, canManage: false };
+ if (viewer.userId === null) return { canWrite: false, canManage: false, canUnlink: false };
const canManage = viewer.isAdmin || (room.ownerId !== null && room.ownerId === viewer.userId);
- const canWrite = canManage || (room.writeVisibility ?? 'public') === 'public';
- return { canWrite, canManage };
+ const canWrite = canManage || room.writeVisibility === 'public';
+ return { canWrite, canManage, canUnlink: canWrite };
}
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx
index 8c10b3684..5746860fc 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-resources-panel.test.tsx
@@ -11,7 +11,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
const listRoomResources = vi.hoisted(() => vi.fn());
const setRoomResourceAttached = vi.hoisted(() => vi.fn());
const listLinkedRooms = vi.hoisted(() => vi.fn());
-const permissions = vi.hoisted(() => ({ value: { canWrite: true, canManage: false } }));
+const permissions = vi.hoisted(() => ({
+ value: { canWrite: true, canManage: false, canUnlink: true },
+}));
vi.hoisted(() => {
window.electronAPI ??= {
@@ -92,7 +94,7 @@ beforeEach(() => {
listLinkedRooms.mockResolvedValue([
{ roomId: 'room-2', name: 'support', description: '', label: 'escalate to' },
]);
- permissions.value = { canWrite: true, canManage: false };
+ permissions.value = { canWrite: true, canManage: false, canUnlink: true };
});
afterEach(async () => {
@@ -149,8 +151,40 @@ describe('the Resources tab', () => {
});
});
+ it('asks before deleting a document an agent wrote, since it goes for everyone', async () => {
+ const el = await renderPanel();
+ await act(async () =>
+ el.querySelector<HTMLButtonElement>('[aria-label="Delete Standup notes"]')!.click()
+ );
+ expect(setRoomResourceAttached).not.toHaveBeenCalled();
+ expect(el.textContent).toContain('Delete for everyone?');
+ const confirm = [...el.querySelectorAll('button')].find((b) => b.textContent === 'Delete')!;
+ await act(async () => confirm.click());
+ expect(setRoomResourceAttached).toHaveBeenCalledWith(
+ expect.objectContaining({ resourceId: 'd-2', attached: false })
+ );
+ });
+
+ it('lets someone attach without detaching, as the server keeps detaching for those taking part', async () => {
+ permissions.value = { canWrite: true, canManage: false, canUnlink: false };
+ const el = await renderPanel();
+ expect(el.textContent).toContain('Attach reference');
+ expect(el.querySelector('[aria-label^="Detach"]')).toBeNull();
+ });
+
+ it('follows the server on who may delete each document', async () => {
+ listRoomResources.mockImplementation(async ({ kind }: { kind: keyof typeof RESOURCES }) =>
+ kind === 'documents'
+ ? RESOURCES.documents.map((doc) => ({ ...doc, canRemove: false }))
+ : RESOURCES[kind]
+ );
+ const el = await renderPanel();
+ expect(el.querySelector('[aria-label="Delete Standup notes"]')).toBeNull();
+ expect(el.querySelector('[aria-label="Detach Guide"]')).not.toBeNull();
+ });
+
it('only lists for someone who may not change the room', async () => {
- permissions.value = { canWrite: false, canManage: false };
+ permissions.value = { canWrite: false, canManage: false, canUnlink: false };
const el = await renderPanel();
expect(el.textContent).toContain('Repo');
expect(el.textContent).not.toContain('Attach reference');
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx
index 91ee3106b..7d2e36c00 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/room-settings-sections.test.tsx
@@ -225,7 +225,7 @@ describe('room settings for someone who may write to the room', () => {
it('archives the room', async () => {
const el = await renderPanel();
- await click(button(el, /^Archive$/)!);
+ await click(button(el, /^Archive for everyone$/)!);
expect(setRoomArchived).toHaveBeenCalledWith({
workspaceId: 'ws-1',
roomId: 'room-1',
@@ -244,7 +244,7 @@ describe('room settings for someone who may only read the room', () => {
);
expect(el.querySelector('[aria-label="Who can see and change it"]')).toBeNull();
expect(button(el, /^Add agent$/)).toBeUndefined();
- expect(button(el, /^Archive$/)).toBeUndefined();
+ expect(button(el, /^Archive for everyone$/)).toBeUndefined();
expect(el.querySelector<HTMLInputElement>('input[aria-label="Name"]')!.disabled).toBe(true);
});
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 154e382ba..bb6f1ddee 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
@@ -367,7 +367,7 @@ export type RemoteRoomSummary = {
* 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 };
+ serverPermissions?: { canWrite: boolean; canManage: boolean; canUnlink: boolean };
};
/**
@@ -1358,6 +1358,8 @@ export type RoomResource = {
createdByAgentName: string | null;
/** The packages this came in with, by id: attached through them rather than on its own. */
packageIds: string[];
+ /** Whether the viewer may delete this room-scoped document, when the server says. */
+ canRemove?: boolean;
};
/** A document read in full, through the room it is attached to. */