From 91424e4fb52d3985168628e9b8241c0e84ca0b0f Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 4 Dec 2026 19:27:37 +0100 Subject: [PATCH 1/2] Delete account: a Windows computer's row opens Computers for an admin there - The windows_computer blocker offers Open Computers to someone who is an admin or the owner of that organization, as their list of organizations says. It switches to the organization first, as Open its settings does. - Someone who isn't an admin there gets no button, since Computers would send them home, and the row keeps no empty actions area. Co-Authored-By: Claude Opus 5.5 --- .../components/settings/delete-account.tsx | 55 ++++++++++++++++--- app/tests/delete-account.test.tsx | 43 +++++++++++++-- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/app/src/components/settings/delete-account.tsx b/app/src/components/settings/delete-account.tsx index 1e8bd06e95..5c5bffed10 100644 --- a/app/src/components/settings/delete-account.tsx +++ b/app/src/components/settings/delete-account.tsx @@ -62,14 +62,17 @@ import { import { signInAgainAtProvider } from "@/lib/account-deletion/reauthenticate"; import { signOutMutationOptions } from "@/lib/auth/mutations"; import { currentUserQueryOptions } from "@/lib/auth/queries"; +import { isOrganizationAdmin } from "@/lib/auth/roles"; import { ClientError } from "@/lib/client"; import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries"; import { failureSaid } from "@/lib/load-failure"; import { useCurrentOrganizationId } from "@/lib/organizations/current"; import { switchOrganizationMutationOptions } from "@/lib/organizations/mutations"; +import { ownOrganizationsQueryOptions } from "@/lib/organizations/queries"; import { queryClient } from "@/query-client"; const ORGANIZATION_SETTINGS = "/settings/organization"; +const ADMIN_COMPUTERS = "/admin/computers"; const GENERAL_SETTINGS = "/settings"; /** @@ -166,6 +169,7 @@ export function DeleteAccountSection() { /** One organization that stops the account being deleted, and the one thing to do there. */ function BlockerRow({ blocker }: { blocker: AccountDeletionBlocker }) { const [leaving, setLeaving] = useState(false); + const adminThere = useAdminOf(blocker.organizationId); const organization = { id: blocker.organizationId, name: blocker.organizationName, @@ -181,12 +185,26 @@ function BlockerRow({ blocker }: { blocker: AccountDeletionBlocker }) { {/* Under the words on a phone, as on Organization's members: a button beside them squeezes them. - A blocker with nothing to do here (a Windows computer an admin settles) has no actions at all, - so its row keeps no empty line under the words. */} + A blocker with nothing to do here (a Windows computer, for somebody who isn't an admin there) + has no actions at all, so its row keeps no empty line under the words. */} {settledInItsSettings(blocker) ? ( - + + ) : blocker.reason === "windows_computer" ? ( + adminThere ? ( + + + + ) : null ) : settledByLeaving(blocker) ? ( {switching.error ? (

diff --git a/app/tests/delete-account.test.tsx b/app/tests/delete-account.test.tsx index d801c9f18f..b3d184e3fd 100644 --- a/app/tests/delete-account.test.tsx +++ b/app/tests/delete-account.test.tsx @@ -126,6 +126,8 @@ let server: { | null; /** The operation isn't served: an OpenBot older than it. */ older: boolean; + /** Dana's role in each organization, where it isn't owner. */ + roles: Record; /** Which product the deployment says it is; the personal edition doesn't serve the operation. */ edition: "team" | "personal"; /** The sign-in providers the deployment offers, and the ones the person signed in through. */ @@ -308,7 +310,7 @@ async function answer( return checked(ListOrganizationsResponse, { organizations: ORGANIZATIONS.map((one) => ({ ...one, - role: "owner", + role: server.roles[one.id] ?? "owner", active: one.id === server.active, })), canCreate: true, @@ -365,6 +367,7 @@ beforeEach(() => { deleted: false, refuse: null, older: false, + roles: {}, edition: "team", providers: [], signedInWith: [], @@ -432,6 +435,7 @@ async function open(start = "/settings") { at("/", () =>

Home

), at("/sign", () =>

Sign in

), at("/settings/organization", () =>

Organization settings

), + at("/admin/computers", () =>

Computers

), at("/settings", () => ( @@ -554,7 +558,7 @@ describe("deleting your account", () => { ); }); - test("a Windows computer OpenBot made is listed with who settles it, and offers no Leave, which wouldn't", async () => { + test("a Windows computer OpenBot made is listed with who settles it, offers no Leave, which wouldn't, and opens Computers for an admin there", async () => { server.blockers = [WINDOWS]; const app = await open(); const acme = (await app.view.findByText("Acme")).closest( @@ -569,13 +573,44 @@ describe("deleting your account", () => { expect( within(acme).queryByRole("button", { name: "Open its settings" }), ).toBeNull(); - // No empty actions area: on a phone it would wrap onto a line of its own under the words. - expect(acme.querySelector("[data-slot=item-actions]")).toBeNull(); expect( app.view .getByRole("button", { name: "Delete account" }) .hasAttribute("disabled"), ).toBe(true); + // Computers is the organization's own: it is switched to first. + await app.person.click( + await within(acme).findByRole("button", { name: "Open Computers" }), + ); + await waitFor(() => + expect(app.router.state.location.pathname).toBe("/admin/computers"), + ); + expect(server.active).toBe("org_acme"); + expect(currentOrganizationId()).toBe("org_acme"); + }); + + test("a Windows computer where the person isn't an admin offers nothing to open, which would send them home", async () => { + // Beside it, one where she is an admin, so the list of her organizations has been read. + server.blockers = [ + WINDOWS, + { ...WINDOWS, organizationId: "org_globex", organizationName: "Globex" }, + ]; + server.roles = { org_acme: "member", org_globex: "admin" }; + const app = await open(); + const row = async (name: string) => + (await app.view.findByText(name)).closest( + "[data-slot=item]", + ) as HTMLElement; + const acme = await row("Acme"); + await within(await row("Globex")).findByRole("button", { + name: "Open Computers", + }); + expect(acme.textContent).toContain( + "An admin removes or forgets it under Computers first.", + ); + expect(within(acme).queryByRole("button")).toBeNull(); + // No empty actions area: on a phone it would wrap onto a line of its own under the words. + expect(acme.querySelector("[data-slot=item-actions]")).toBeNull(); }); test("the dialog's Delete account waits for both the email address and the phrase, GitHub style", async () => { From dfdd304d9435fe5dee416c34265966eaa7f3a3ab Mon Sep 17 00:00:00 2001 From: Maxim Date: Fri, 4 Dec 2026 20:43:46 +0100 Subject: [PATCH 2/2] Delete account: Open Computers switches first and then opens Computers, so Admin's gate reads the person in that organization Computers was opened as the switch's `leave`, which runs before the app changes over, so Admin's gate read the person as they are where they were working and sent somebody who is only a member there home. The page now opens once the switch has finished. Admin's gate moves to lib/auth/admin-gate.ts, and the test's router uses it, with `people/me` answering per organization. Co-Authored-By: Claude Opus 5.5 --- .../components/settings/delete-account.tsx | 14 +++++---- app/src/lib/auth/admin-gate.ts | 24 +++++++++++++++ app/src/routes/_authed/admin/route.tsx | 27 +++-------------- app/tests/delete-account.test.tsx | 30 +++++++++++++++++-- 4 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 app/src/lib/auth/admin-gate.ts diff --git a/app/src/components/settings/delete-account.tsx b/app/src/components/settings/delete-account.tsx index 5c5bffed10..c7a1fa6215 100644 --- a/app/src/components/settings/delete-account.tsx +++ b/app/src/components/settings/delete-account.tsx @@ -246,6 +246,10 @@ function useAdminOf(organizationId: string): boolean { * A page of an organization: its settings, where its owner makes someone else an owner or deletes * it, or Computers, where its admin removes or forgets a Windows computer. Both are the one the * person works in, so another one is switched to first, as the account menu switches. + * + * The page is opened once the switch has finished, never as the switch's `leave`: that runs before + * the app changes over, so Admin's gate would read the person as they are in the organization being + * left, and send somebody who is only a member there home. */ function OpenInOrganization({ label, @@ -259,11 +263,7 @@ function OpenInOrganization({ const navigate = useNavigate(); const current = useCurrentOrganizationId(); const open = () => navigate({ to }); - const switching = useMutation( - switchOrganizationMutationOptions(queryClient, async () => { - await open(); - }), - ); + const switching = useMutation(switchOrganizationMutationOptions(queryClient)); return (