Skip to content

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

Show a room's add-user, resource and linked-room controls only to people who can write to it

Abel Dantas8a76c7cdad1b
diff --git a/gateway/src/pages/rooms/RoomDetailPage.tsx b/gateway/src/pages/rooms/RoomDetailPage.tsx
index e7a50ed2a..5ac673527 100644
--- a/gateway/src/pages/rooms/RoomDetailPage.tsx
+++ b/gateway/src/pages/rooms/RoomDetailPage.tsx
@@ -140,9 +140,9 @@ export default function RoomDetailPage() {
<Divider />
<ParticipantsSection room={room} canWrite={canWrite} onChanged={refetch} />
<Divider />
- <RoomResourcesSection roomId={room.id} />
+ <RoomResourcesSection roomId={room.id} canWrite={canWrite} />
<Divider />
- <RoomLinkedRoomsSection roomId={room.id} />
+ <RoomLinkedRoomsSection roomId={room.id} canWrite={canWrite} />
<Divider />
<RoomGraphView roomId={room.id} />
{room.bridge_id && (
@@ -925,25 +925,29 @@ function ParticipantsSection({
</Typography>
)}
</Stack>
- <Button
- size="small"
- variant="outlined"
- startIcon={<AddIcon />}
- onClick={() => setAddUserOpen(true)}
- sx={{ alignSelf: "flex-start" }}
- >
- Add user
- </Button>
- <SearchablePickerDialog
- open={addUserOpen}
- title="Add users"
- searchPlaceholder="Search users…"
- submitLabel="Add"
- options={addableUserOptions}
- loading={bridgeUsersLoading}
- onClose={() => setAddUserOpen(false)}
- onSubmit={handleAddUsers}
- />
+ {canWrite && (
+ <>
+ <Button
+ size="small"
+ variant="outlined"
+ startIcon={<AddIcon />}
+ onClick={() => setAddUserOpen(true)}
+ sx={{ alignSelf: "flex-start" }}
+ >
+ Add user
+ </Button>
+ <SearchablePickerDialog
+ open={addUserOpen}
+ title="Add users"
+ searchPlaceholder="Search users…"
+ submitLabel="Add"
+ options={addableUserOptions}
+ loading={bridgeUsersLoading}
+ onClose={() => setAddUserOpen(false)}
+ onSubmit={handleAddUsers}
+ />
+ </>
+ )}
</Box>
)}
</Stack>
diff --git a/gateway/src/pages/rooms/RoomLinkedRoomsSection.tsx b/gateway/src/pages/rooms/RoomLinkedRoomsSection.tsx
index a7475bf86..a0d34af3c 100644
--- a/gateway/src/pages/rooms/RoomLinkedRoomsSection.tsx
+++ b/gateway/src/pages/rooms/RoomLinkedRoomsSection.tsx
@@ -25,9 +25,10 @@ import { useLinkedRooms, useRooms } from "../../data/hooks";
interface Props {
roomId: string;
+ canWrite: boolean;
}
-export default function RoomLinkedRoomsSection({ roomId }: Props) {
+export default function RoomLinkedRoomsSection({ roomId, canWrite }: Props) {
const { data: linked, loading, refetch } = useLinkedRooms(roomId);
const [dialogOpen, setDialogOpen] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -92,39 +93,45 @@ export default function RoomLinkedRoomsSection({ roomId }: Props) {
</Typography>
)}
</Stack>
- <IconButton
- size="small"
- disabled={busy}
- onClick={(e) => {
- e.stopPropagation();
- handleDetach(link.target_room_id);
- }}
- >
- <DeleteOutline fontSize="small" />
- </IconButton>
+ {canWrite && (
+ <IconButton
+ size="small"
+ disabled={busy}
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDetach(link.target_room_id);
+ }}
+ >
+ <DeleteOutline fontSize="small" />
+ </IconButton>
+ )}
</Stack>
))}
</Stack>
)}
- <Button
- size="small"
- variant="outlined"
- startIcon={<AddIcon />}
- onClick={() => setDialogOpen(true)}
- sx={{ alignSelf: "flex-start" }}
- >
- Add linked room
- </Button>
- <AddLinkedRoomDialog
- open={dialogOpen}
- sourceRoomId={roomId}
- existingTargetIds={existingTargetIds}
- onClose={() => setDialogOpen(false)}
- onCreated={() => {
- setDialogOpen(false);
- refetch();
- }}
- />
+ {canWrite && (
+ <>
+ <Button
+ size="small"
+ variant="outlined"
+ startIcon={<AddIcon />}
+ onClick={() => setDialogOpen(true)}
+ sx={{ alignSelf: "flex-start" }}
+ >
+ Add linked room
+ </Button>
+ <AddLinkedRoomDialog
+ open={dialogOpen}
+ sourceRoomId={roomId}
+ existingTargetIds={existingTargetIds}
+ onClose={() => setDialogOpen(false)}
+ onCreated={() => {
+ setDialogOpen(false);
+ refetch();
+ }}
+ />
+ </>
+ )}
</Stack>
);
}
diff --git a/gateway/src/pages/rooms/RoomResourcesSection.tsx b/gateway/src/pages/rooms/RoomResourcesSection.tsx
index 3a1d8fc1c..a50b295f0 100644
--- a/gateway/src/pages/rooms/RoomResourcesSection.tsx
+++ b/gateway/src/pages/rooms/RoomResourcesSection.tsx
@@ -33,9 +33,10 @@ import {
interface Props {
roomId: string;
+ canWrite: boolean;
}
-export default function RoomResourcesSection({ roomId }: Props) {
+export default function RoomResourcesSection({ roomId, canWrite }: Props) {
const { data: roomPackages, refetch: refetchPackages } = useRoomPackages(roomId);
const attachedPackageIds = useMemo(
() => new Set((roomPackages ?? []).map((p) => p.id)),
@@ -54,16 +55,19 @@ export default function RoomResourcesSection({ roomId }: Props) {
</Typography>
<RoomReferences
roomId={roomId}
+ canWrite={canWrite}
attachedPackageIds={attachedPackageIds}
packageDescriptions={packageDescriptions}
/>
<RoomDocuments
roomId={roomId}
+ canWrite={canWrite}
attachedPackageIds={attachedPackageIds}
packageDescriptions={packageDescriptions}
/>
<RoomPackages
roomId={roomId}
+ canWrite={canWrite}
packages={roomPackages ?? []}
refetch={refetchPackages}
/>
@@ -103,10 +107,12 @@ function PackageChips({
function RoomReferences({
roomId,
+ canWrite,
attachedPackageIds,
packageDescriptions,
}: {
roomId: string;
+ canWrite: boolean;
attachedPackageIds: Set<string>;
packageDescriptions: Record<string, string>;
}) {
@@ -213,46 +219,54 @@ function RoomReferences({
attachedPackageIds={attachedPackageIds}
packageDescriptions={packageDescriptions}
/>
- <IconButton
- size="small"
- onClick={() => handleDetach(ref.id)}
- disabled={busy}
- >
- <DeleteOutline fontSize="small" />
- </IconButton>
+ {canWrite && (
+ <IconButton
+ size="small"
+ onClick={() => handleDetach(ref.id)}
+ disabled={busy}
+ >
+ <DeleteOutline fontSize="small" />
+ </IconButton>
+ )}
</Stack>
))}
</Stack>
)}
- <Button
- size="small"
- variant="outlined"
- startIcon={<AddIcon />}
- onClick={() => setPickerOpen(true)}
- sx={{ alignSelf: "flex-start" }}
- >
- Attach reference
- </Button>
- <SearchablePickerDialog
- open={pickerOpen}
- title="Attach references"
- searchPlaceholder="Search references…"
- submitLabel="Attach"
- options={options}
- loading={allLoading}
- onClose={() => setPickerOpen(false)}
- onSubmit={handleAttach}
- />
+ {canWrite && (
+ <>
+ <Button
+ size="small"
+ variant="outlined"
+ startIcon={<AddIcon />}
+ onClick={() => setPickerOpen(true)}
+ sx={{ alignSelf: "flex-start" }}
+ >
+ Attach reference
+ </Button>
+ <SearchablePickerDialog
+ open={pickerOpen}
+ title="Attach references"
+ searchPlaceholder="Search references…"
+ submitLabel="Attach"
+ options={options}
+ loading={allLoading}
+ onClose={() => setPickerOpen(false)}
+ onSubmit={handleAttach}
+ />
+ </>
+ )}
</Stack>
);
}
function RoomDocuments({
roomId,
+ canWrite,
attachedPackageIds,
packageDescriptions,
}: {
roomId: string;
+ canWrite: boolean;
attachedPackageIds: Set<string>;
packageDescriptions: Record<string, string>;
}) {
@@ -353,13 +367,15 @@ function RoomDocuments({
attachedPackageIds={attachedPackageIds}
packageDescriptions={packageDescriptions}
/>
- <IconButton
- size="small"
- onClick={() => handleDetach(doc.id)}
- disabled={busy}
- >
- <DeleteOutline fontSize="small" />
- </IconButton>
+ {canWrite && (
+ <IconButton
+ size="small"
+ onClick={() => handleDetach(doc.id)}
+ disabled={busy}
+ >
+ <DeleteOutline fontSize="small" />
+ </IconButton>
+ )}
</Stack>
))}
</Stack>
@@ -400,51 +416,59 @@ function RoomDocuments({
variant="outlined"
/>
)}
- <IconButton
- size="small"
- onClick={(e) => {
- e.stopPropagation();
- handleDetach(doc.id);
- }}
- disabled={busy}
- >
- <DeleteOutline fontSize="small" />
- </IconButton>
+ {canWrite && (
+ <IconButton
+ size="small"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDetach(doc.id);
+ }}
+ disabled={busy}
+ >
+ <DeleteOutline fontSize="small" />
+ </IconButton>
+ )}
</Stack>
))}
</Stack>
)}
</Stack>
)}
- <Button
- size="small"
- variant="outlined"
- startIcon={<AddIcon />}
- onClick={() => setPickerOpen(true)}
- sx={{ alignSelf: "flex-start" }}
- >
- Attach document
- </Button>
- <SearchablePickerDialog
- open={pickerOpen}
- title="Attach documents"
- searchPlaceholder="Search documents…"
- submitLabel="Attach"
- options={options}
- loading={allLoading}
- onClose={() => setPickerOpen(false)}
- onSubmit={handleAttach}
- />
+ {canWrite && (
+ <>
+ <Button
+ size="small"
+ variant="outlined"
+ startIcon={<AddIcon />}
+ onClick={() => setPickerOpen(true)}
+ sx={{ alignSelf: "flex-start" }}
+ >
+ Attach document
+ </Button>
+ <SearchablePickerDialog
+ open={pickerOpen}
+ title="Attach documents"
+ searchPlaceholder="Search documents…"
+ submitLabel="Attach"
+ options={options}
+ loading={allLoading}
+ onClose={() => setPickerOpen(false)}
+ onSubmit={handleAttach}
+ />
+ </>
+ )}
</Stack>
);
}
function RoomPackages({
roomId,
+ canWrite,
packages,
refetch,
}: {
roomId: string;
+ canWrite: boolean;
packages: Array<{ id: string; name: string; description: string }>;
refetch: () => void;
}) {
@@ -526,39 +550,45 @@ function RoomPackages({
<Typography variant="body2" sx={{ flexGrow: 1 }}>
{p.name || p.description}
</Typography>
- <IconButton
- size="small"
- onClick={(e) => {
- e.stopPropagation();
- handleDetach(p.id);
- }}
- disabled={busy}
- >
- <DeleteOutline fontSize="small" />
- </IconButton>
+ {canWrite && (
+ <IconButton
+ size="small"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDetach(p.id);
+ }}
+ disabled={busy}
+ >
+ <DeleteOutline fontSize="small" />
+ </IconButton>
+ )}
</Stack>
))}
</Stack>
)}
- <Button
- size="small"
- variant="outlined"
- startIcon={<AddIcon />}
- onClick={() => setPickerOpen(true)}
- sx={{ alignSelf: "flex-start" }}
- >
- Attach package
- </Button>
- <SearchablePickerDialog
- open={pickerOpen}
- title="Attach packages"
- searchPlaceholder="Search packages…"
- submitLabel="Attach"
- options={options}
- loading={allLoading}
- onClose={() => setPickerOpen(false)}
- onSubmit={handleAttach}
- />
+ {canWrite && (
+ <>
+ <Button
+ size="small"
+ variant="outlined"
+ startIcon={<AddIcon />}
+ onClick={() => setPickerOpen(true)}
+ sx={{ alignSelf: "flex-start" }}
+ >
+ Attach package
+ </Button>
+ <SearchablePickerDialog
+ open={pickerOpen}
+ title="Attach packages"
+ searchPlaceholder="Search packages…"
+ submitLabel="Attach"
+ options={options}
+ loading={allLoading}
+ onClose={() => setPickerOpen(false)}
+ onSubmit={handleAttach}
+ />
+ </>
+ )}
</Stack>
);
}
diff --git a/gateway/src/pages/rooms/roomWriteControls.test.tsx b/gateway/src/pages/rooms/roomWriteControls.test.tsx
new file mode 100644
index 000000000..e190bc556
--- /dev/null
+++ b/gateway/src/pages/rooms/roomWriteControls.test.tsx
@@ -0,0 +1,87 @@
+import { cleanup, render, screen } from "@testing-library/react";
+import { MemoryRouter } from "react-router";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import RoomLinkedRoomsSection from "./RoomLinkedRoomsSection";
+import RoomResourcesSection from "./RoomResourcesSection";
+
+// The room's linked rooms and resources change only for someone with write
+// access to the room, so their controls show only to them.
+
+const result = <T,>(data: T) => ({
+ data,
+ loading: false,
+ error: null,
+ refetch: vi.fn(),
+});
+
+vi.mock("../../data/hooks", () => ({
+ useLinkedRooms: () =>
+ result([
+ {
+ target_room_id: "r2",
+ target_room_name: "other",
+ target_room_description: "",
+ label: "see also",
+ },
+ ]),
+ useRooms: () => result([]),
+ useRoomReferences: () =>
+ result([
+ {
+ id: "ref1",
+ name: "spec",
+ description: "",
+ type: "url",
+ type_display_name: "URL",
+ packages: [],
+ },
+ ]),
+ useReferences: () => result([]),
+ useRoomDocuments: () =>
+ result([
+ { id: "doc1", name: "notes", description: "", scope: "global", packages: [] },
+ ]),
+ useDocuments: () => result([]),
+ useRoomPackages: () => result([{ id: "pkg1", name: "kit", description: "" }]),
+ usePackages: () => result([]),
+}));
+
+afterEach(cleanup);
+
+function renderSections(canWrite: boolean) {
+ render(
+ <MemoryRouter>
+ <RoomResourcesSection roomId="r1" canWrite={canWrite} />
+ <RoomLinkedRoomsSection roomId="r1" canWrite={canWrite} />
+ </MemoryRouter>,
+ );
+}
+
+const ADD_BUTTONS = [
+ "Attach reference",
+ "Attach document",
+ "Attach package",
+ "Add linked room",
+];
+
+describe("room resources and linked rooms", () => {
+ it("offer no attach, detach or link controls without write access", () => {
+ renderSections(false);
+
+ expect(screen.getByText("spec")).toBeTruthy();
+ expect(screen.getByText("other")).toBeTruthy();
+ for (const name of ADD_BUTTONS) {
+ expect(screen.queryByRole("button", { name })).toBeNull();
+ }
+ expect(screen.queryByTestId("DeleteOutlineIcon")).toBeNull();
+ });
+
+ it("offer them with write access", () => {
+ renderSections(true);
+
+ for (const name of ADD_BUTTONS) {
+ expect(screen.getByRole("button", { name })).toBeTruthy();
+ }
+ expect(screen.getAllByTestId("DeleteOutlineIcon")).toHaveLength(4);
+ });
+});