diff --git a/docs/buzz-help.md b/docs/buzz-help.md index f74ba87c2d..ee0e04ffe2 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -113,6 +113,8 @@ if that desktop app is up and running. chat. Sharing a chat with a channel shares its whole history. - **Channels** are open (anyone can find and join them) or private (invite only). The member avatars in the header manage members, access and roles. + A private channel or chat that has, or once had, members besides you and + your own agents can't be made open or shared; create a new channel instead. Archived channels are read-only, and owners and admins can unarchive them. - **Workspaces.** Drag conversations in, or use **Move to…**. A workspace can set the folders and default agents for new chats started in it. diff --git a/src/bundled/channels/ChannelGeneralAccess.test.tsx b/src/bundled/channels/ChannelGeneralAccess.test.tsx index 4b9a0b0c55..c58ec90780 100644 --- a/src/bundled/channels/ChannelGeneralAccess.test.tsx +++ b/src/bundled/channels/ChannelGeneralAccess.test.tsx @@ -899,3 +899,93 @@ it("rechecks plugin participation policy after consent was staged", async () => await user.click(confirm); expect(h.save).not.toHaveBeenCalled(); }); + +it.each([true, false])( + "offers opening a private channel only when nobody else is a member (blocked: %s)", + async (blocked) => { + const h = harness(); + const user = userEvent.setup(); + h.load.mockResolvedValue({ ...base, visibility: "private" }); + render( + , + ); + const control = screen.getByRole("combobox", { name: "General access" }); + await waitFor(() => expect(control).toBeEnabled()); + await user.click(control); + for (const name of ["Public", "View only"]) { + const option = await screen.findByRole("option", { name }); + if (blocked) { + expect(option).toHaveAttribute("aria-disabled", "true"); + expect(option).toHaveAccessibleDescription( + "Has other members. Create a new channel instead.", + ); + } else expect(option).not.toHaveAttribute("aria-disabled", "true"); + } + await user.click(screen.getByRole("option", { name: "View only" })); + if (blocked) { + expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument(); + expect(h.load).toHaveBeenCalledTimes(1); + } else expect(await screen.findByRole("alertdialog")).toBeVisible(); + expect(h.save).not.toHaveBeenCalled(); + }, +); + +it("refuses a staged opening the opening check closes after consent opened", async () => { + const h = harness(); + h.load.mockResolvedValue({ ...base, visibility: "private" }); + const user = userEvent.setup(); + const view = render( + , + ); + await select(user, "General access", "View only"); + const confirm = await screen.findByRole("button", { name: "Change access" }); + expect(confirm).toBeEnabled(); + view.rerender( + , + ); + expect(confirm).toBeDisabled(); + expect(screen.getByRole("alertdialog")).toHaveAccessibleDescription( + expect.stringContaining("Has other members. Create a new channel instead."), + ); + await user.click(confirm); + expect(h.save).not.toHaveBeenCalled(); + await user.click(screen.getByRole("button", { name: "Cancel" })); + await waitFor(() => + expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument(), + ); +}); + +it.each([ + ["Public", "member"], + ["View only", "guest"], +] as const)( + "keeps switching an already %s channel open when opening is blocked", + async (current, joinRole) => { + const h = harness(); + h.load.mockResolvedValue({ ...base, visibility: "public", joinRole }); + const user = userEvent.setup(); + render( + , + ); + const control = screen.getByRole("combobox", { name: "General access" }); + await waitFor(() => expect(control).toHaveTextContent(current)); + await user.click(control); + for (const name of ["Public", "View only"]) + expect(await screen.findByRole("option", { name })).not.toHaveAttribute( + "aria-disabled", + "true", + ); + }, +); diff --git a/src/bundled/channels/ChannelGeneralAccess.tsx b/src/bundled/channels/ChannelGeneralAccess.tsx index e63a7ba41e..b137ff285a 100644 --- a/src/bundled/channels/ChannelGeneralAccess.tsx +++ b/src/bundled/channels/ChannelGeneralAccess.tsx @@ -35,6 +35,7 @@ import { generalAccessOptions, generalAccessPolicy, generalAccessValue, + OPENING_BLOCKED_REASON, } from "../../features/channels/general-access"; /** Resource wording and participation policy; relay authorization remains authoritative. */ @@ -53,6 +54,8 @@ export type ChannelGeneralAccessProps = { /** False only when the signed member-role snapshot verifies no Guests. */ mayHaveGuestMembers?: boolean; policy?: GeneralAccessPolicy; + /** The relay will refuse to open it: someone else is a member. */ + openingBlocked?: boolean; }; /** General access uses the same signed save/readback owner as channel details. @@ -64,6 +67,7 @@ export function ChannelGeneralAccess({ channel, mayHaveGuestMembers = true, policy, + openingBlocked = false, }: ChannelGeneralAccessProps) { const place = policy?.subject ?? (channel?.channelType === "solo" ? "chat" : "channel"); @@ -118,6 +122,7 @@ export function ChannelGeneralAccess({ summary={channel && capability.summaryAccess?.(channel)} autoJoin={channel?.autoJoin ?? false} policy={policy} + openingBlocked={openingBlocked} /> ); } @@ -130,6 +135,7 @@ function ChannelGeneralAccessEditor({ summary, autoJoin, policy, + openingBlocked, }: { capability: ChannelDetailsCapability; recovery: RelayRecovery | undefined; @@ -139,6 +145,7 @@ function ChannelGeneralAccessEditor({ summary: ChannelAccess | undefined; autoJoin: boolean; policy: GeneralAccessPolicy | undefined; + openingBlocked: boolean; }) { const attempt = useSyncExternalStore(capability.subscribe, () => capability.snapshot(channelId), @@ -211,6 +218,9 @@ function ChannelGeneralAccessEditor({ choice?.visibility !== "public" || choice.joinRole === "guest"; const access = shown ? generalAccessValue(shown) : ""; + const closed = access === "private" && openingBlocked; + // The opening check can settle after the confirmation opened. + const choiceOpensClosed = closed && choice?.visibility === "public"; const Icon = access === "public" ? GlobeIcon @@ -222,7 +232,12 @@ function ChannelGeneralAccessEditor({ const option = Object.values(generalAccessOptions).find( (option) => option.value === value, ); - if (value === access || !option || (restrictPublic && value === "public")) + if ( + value === access || + !option || + (restrictPublic && value === "public") || + (closed && value !== "private") + ) return; origin.current = section.current?.querySelector('[role="combobox"]') ?? null; @@ -252,7 +267,11 @@ function ChannelGeneralAccessEditor({ busy.current || (check ? attempt?.status !== "unconfirmed" - : !base || !choice || locked || !policyAllowsChoice) + : !base || + !choice || + locked || + !policyAllowsChoice || + choiceOpensClosed) ) return; if (check) section.current?.focus(); @@ -358,9 +377,19 @@ function ChannelGeneralAccessEditor({ ...generalAccessOptions["view-only"], leading: , }, - ].filter( - (option) => !restrictPublic || option.value !== "public", - ), + ] + .filter( + (option) => !restrictPublic || option.value !== "public", + ) + .map((option) => + closed + ? { + ...option, + disabled: true, + description: OPENING_BLOCKED_REASON, + } + : option, + ), }, { label: "", @@ -381,6 +410,7 @@ function ChannelGeneralAccessEditor({