Skip to content

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

New room: offer the group only to a workspace admin

Simon Flack9f1667a14375
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx
index 68c79ec98..437b60590 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx
@@ -49,6 +49,7 @@ import {
} from './room-create-request';
import { RoomNameInput } from './room-name-input';
import { switchServersStore } from './switch-servers-store';
+import { administersWorkspaceById } from './workspace-admin';
type CreateRoomModalArgs = {
/** Create on this server instead of the active one — for callers that are not
@@ -180,7 +181,10 @@ export const CreateRoomModal = observer(function CreateRoomModal({
};
// A choice the chosen app does not offer (a private channel on Teams, say)
// falls back to a new public channel rather than being sent and refused.
- const roomOptions = optionsForBridge(options, selectedBridge);
+ const administers = workspaceId !== null && administersWorkspaceById(workspaceId);
+ // Only an admin files a room in a group; for anyone else it is made with none.
+ const bridgeOptions = optionsForBridge(options, selectedBridge);
+ const roomOptions = administers ? bridgeOptions : { ...bridgeOptions, groupId: null };
const agentIds = shownPicked.filter((each) => each.kind === 'agent').map((each) => each.id);
const memberUserIds = shownPicked.filter((each) => each.kind === 'person').map((each) => each.id);
@@ -379,6 +383,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
</Field>
<CreateRoomOptions
workspaceId={workspaceId}
+ administersWorkspace={administers}
value={roomOptions}
onChange={(next) => {
setOptions(next);
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts
index edf3a5e56..37ae97f1b 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-modal.test.ts
@@ -8,6 +8,7 @@ const flags = vi.hoisted(() => ({ group_chats: true }));
vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({ useFeatureFlags: () => flags }));
vi.mock('@renderer/lib/ipc', () => ({ events: { on: vi.fn() }, rpc: {} }));
vi.mock('@renderer/features/chats/stores/chats', () => ({ chatsStore: {} }));
+vi.mock('./workspace-admin', () => ({ administersWorkspaceById: () => true }));
vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
workspacesStore: {
workspaces: [{ id: 'ws', tenantId: null }],
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx
index 6334b45d8..bdab788cf 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/create-room-options.tsx
@@ -125,17 +125,24 @@ export function CreateRoomOptions({
workspaceId,
value,
onChange,
+ administersWorkspace,
}: {
workspaceId: string | null;
value: RoomCreateOptions;
onChange: (next: RoomCreateOptions) => void;
+ /**
+ * Whether the viewer administers the workspace. Only they put a room in a
+ * group, since a group can decide who may address an agent; for anyone
+ * else the room is made with none and the group is not offered.
+ */
+ administersWorkspace: boolean;
}) {
const [open, setOpen] = useState(false);
const groups = useQuery({
// The key every view reads the groups under, so they go stale and refresh together.
queryKey: ['remote-room-groups', workspaceId],
queryFn: () => rpc.workspaces.listRoomGroups(workspaceId as string),
- enabled: workspaceId !== null,
+ enabled: workspaceId !== null && administersWorkspace,
});
// The group is named once the list has it; until then (or if it could not be
// read) the room is still filed under it, so say so rather than "none".
@@ -151,37 +158,43 @@ export function CreateRoomOptions({
<DisclosureRow
open={open}
title="More options"
- summary={`Group: ${groupName ?? 'none'} · ${ACCESS_LABELS[access]}`}
+ summary={
+ administersWorkspace
+ ? `Group: ${groupName ?? 'none'} · ${ACCESS_LABELS[access]}`
+ : ACCESS_LABELS[access]
+ }
onToggle={() => setOpen(!open)}
/>
{open && (
<>
- <Field>
- <FieldLabel>Group</FieldLabel>
- <Select
- value={value.groupId ?? NO_GROUP}
- onValueChange={(next) =>
- onChange({ ...value, groupId: next === NO_GROUP ? null : (next as string) })
- }
- >
- <SelectTrigger className="w-full" aria-label="Group">
- <SelectValue>{groupName ?? 'No group'}</SelectValue>
- </SelectTrigger>
- <SelectContent>
- <SelectItem value={NO_GROUP}>No group</SelectItem>
- {(groups.data ?? []).map((group) => (
- <SelectItem key={group.id} value={group.id}>
- {group.name}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- {groups.isError && (
- <span className="text-xs text-destructive">
- {failureText(groups.error, 'Could not list the groups.')}
- </span>
- )}
- </Field>
+ {administersWorkspace && (
+ <Field>
+ <FieldLabel>Group</FieldLabel>
+ <Select
+ value={value.groupId ?? NO_GROUP}
+ onValueChange={(next) =>
+ onChange({ ...value, groupId: next === NO_GROUP ? null : (next as string) })
+ }
+ >
+ <SelectTrigger className="w-full" aria-label="Group">
+ <SelectValue>{groupName ?? 'No group'}</SelectValue>
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value={NO_GROUP}>No group</SelectItem>
+ {(groups.data ?? []).map((group) => (
+ <SelectItem key={group.id} value={group.id}>
+ {group.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ {groups.isError && (
+ <span className="text-xs text-destructive">
+ {failureText(groups.error, 'Could not list the groups.')}
+ </span>
+ )}
+ </Field>
+ )}
<Field>
<FieldLabel>Who can see and change it</FieldLabel>
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx
index 90ae810da..10adb0a51 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx
@@ -54,6 +54,9 @@ vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
idOnServerInScope: (serverId: string | null) => (serverId ? 'ws' : null),
},
}));
+vi.mock('@renderer/features/switch-servers/workspace-admin', () => ({
+ administersWorkspaceById: () => true,
+}));
vi.mock('@renderer/features/chats/stores/chats', () => ({ chatsStore: { add: vi.fn() } }));
vi.mock('@renderer/features/sidebar/sidebar-room-grouping', () => ({ openRoomView: vi.fn() }));
vi.mock('@renderer/features/sidebar/sidebar-tree-data', () => ({
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-options.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-options.test.tsx
index f4572132c..26339ec78 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-options.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-options.test.tsx
@@ -50,7 +50,7 @@ afterEach(async () => {
latest = DEFAULT_ROOM_OPTIONS;
});
-function Harness({ bridge }: { bridge: RemoteBridge }) {
+function Harness({ bridge, admin }: { bridge: RemoteBridge; admin: boolean }) {
const [value, setValue] = useState<RoomCreateOptions>(DEFAULT_ROOM_OPTIONS);
const onChange = (next: RoomCreateOptions) => {
latest = next;
@@ -59,12 +59,17 @@ function Harness({ bridge }: { bridge: RemoteBridge }) {
return (
<>
<RoomChannelField bridge={bridge} value={value} onChange={onChange} />
- <CreateRoomOptions workspaceId="ws-1" value={value} onChange={onChange} />
+ <CreateRoomOptions
+ workspaceId="ws-1"
+ value={value}
+ onChange={onChange}
+ administersWorkspace={admin}
+ />
</>
);
}
-async function render(bridge: RemoteBridge = BRIDGE): Promise<HTMLDivElement> {
+async function render(bridge: RemoteBridge = BRIDGE, admin = true): Promise<HTMLDivElement> {
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);
@@ -72,7 +77,7 @@ async function render(bridge: RemoteBridge = BRIDGE): Promise<HTMLDivElement> {
await act(async () =>
root!.render(
<QueryClientProvider client={client}>
- <Harness bridge={bridge} />
+ <Harness bridge={bridge} admin={admin} />
</QueryClientProvider>
)
);
@@ -131,4 +136,12 @@ describe('creating a room on a messaging app', () => {
expect(el.querySelector('[aria-label="Group"]')).not.toBeNull();
expect(el.querySelector('[aria-label="Who can see and change it"]')).not.toBeNull();
});
+
+ it('offers the group only to a workspace admin, who alone puts rooms in groups', async () => {
+ const el = await render(BRIDGE, false);
+ expect(el.textContent).not.toContain('Group:');
+ await click(el.querySelector<HTMLButtonElement>('button[aria-expanded]')!);
+ expect(el.querySelector('[aria-label="Group"]')).toBeNull();
+ expect(el.querySelector('[aria-label="Who can see and change it"]')).not.toBeNull();
+ });
});