Public: anyone can read this; the crew can change it.

Removing an organization's last owner can retire the organization and its repositories with them, after a confirm page (destructive) #1211

Closed opened this
Closed without merging

An admin can now remove an organization's last owner together with the organization and everything it owns, after a confirm page that lists exactly what will go. The new test/org-removal.test.ts passes (5 tests).

Notes

stopped closed without shipping deploy 229fc57

opened this

An admin can now remove an organization's last owner together with the organization and everything it owns, after a confirm page that lists exactly what will go. The new test/org-removal.test.ts passes (5 tests). I could not run the existing accounts.test.ts and org-owners.test.ts here, and bun x tsc --noEmit failed because the bun type definitions aren't installed. The sandbox refuses the unix-socket listen those tests need, so the forge's check is the first run of those suites and of tsc.

What changed

  • Refusal: removing the sole owner on the accounts page still changes nothing. The refusal now offers "Add an owner first" or "Remove the organization too".
  • Confirm page: GET /settings/accounts/:username/remove-organization is admin-only. It lists each organization, its teams, and each repository with its app slug. Nothing is removed until the form on that page is posted (same-origin).
  • Removal order: each repository goes the same way an account's do today (app torn down, then the repository). Then the organization's teams and the organization row go together, then the account. The outbox records repo.deleted per repository, org.removed, and account.removed.
  • Failure partway: a failed repository deletion stops there and leaves the rest intact. Running it again finishes.
  • API:
    • DELETE /api/v1/admin/accounts/:username removes the organizations too only with {"removeOrganizations": true}. Without it, it answers 409 last_owner and names the field.
    • GET /api/v1/admin/accounts/:username/removal returns the same list the confirm page shows.
  • Tests: the new tests call the app in-process through forgeHttp(app).handle instead of serve. They cover:
    • The refusal stands and the confirm page and API list change nothing.
    • A non-admin gets 404 on the page, the form post and the API.
    • Confirming removes the repositories, teams, organization and account, and records their events.

Left out

  • A failed removal is reported with the existing generic "did not finish" flash, not a list of what was already removed. The remaining state is intact and a rerun finishes it.
  • The removed organization's name stays taken, like an account's.
  • I added no dependencies.

Try it: as an admin, create an organization with one owner and a repository, then remove that owner at /settings/accounts.

🤖 Generated with Claude Code

Closes #1069

3 earlier comments · 1 event
commented

scout only (reviewers: not for you): the check on this pull is red. Read the failing tests in the check log, fix them on this branch and push, or say in one line why the red is not yours.

commented

An admin can now remove an organization's last owner together with the organization, its teams and its repositories, after a confirm page that lists what will go.

What changed in this push: the red check came from test/check-list.test.ts. It requires every test/*.test.ts to be in GATE or EXCLUDED in scripts/gate.ts, and the new test/org-removal.test.ts was in neither. I added it to GATE, since it calls the app in-process and listens on no socket. check-list and org-removal now pass together (13 tests), and tsc --noEmit is clean.

What I couldn't check: I couldn't read the forge's check log, so the missing-list entry is the failure I reproduced, not one I confirmed from the log. accounts.test.ts and org-owners.test.ts need a unix-socket listen that this sandbox refuses. Reading them, I found no assertion the change breaks: the refusal is still last_owner, the 409 message still names the organization, and the accounts page still says "only owner of". The forge's check is the first real run of those two.

What it does:

  • Refusal: removing a sole owner on the accounts page still changes nothing. It now offers "Add an owner first" or "Remove the organization too".
  • Confirm page: GET /settings/accounts/:username/remove-organization is admin-only. It lists each organization, its teams, and each repository with its app slug. The form on that page posts same-origin and is the only thing that removes anything.
  • Removal order: each repository goes first (app torn down, then the repository), then the teams and the organization together, then the account. A failure stops there and leaves the rest intact; running it again finishes.
  • Events: the outbox records repo.deleted per repository, org.removed, and account.removed.
  • API: DELETE /api/v1/admin/accounts/:username removes the organizations too only with {"removeOrganizations": true}. Without it, it answers 409 last_owner and names the field. GET …/removal returns the same list the confirm page shows.

Left out:

  • A failed removal shows the existing generic flash, not a list of what was already removed.
  • The removed organization's name stays taken, like an account's.
  • No dependencies added.

Try it: as an admin, create an organization with one owner and a repository, then remove that owner at /settings/accounts.

🤖 Generated with Claude Code

Changes requested — before the latest push

The guards are right. A non-admin gets 404 on the page, the form and the API. The web form needs the same-origin readForm(ctx, "admin"). The DELETE body is read through body(), which caps the bytes it actually reads. Nothing is removed without the explicit field, and the confirm page escapes what it shows. A retry finishes too: isLastOwner still counts the org once the account is suspended. One acceptance item of #1069 is missing, though, and what replaces it misleads.

What doesn't work. The issue says: "A failure partway leaves what is left intact and says what was removed; running it again finishes." If destroyRepo fails partway, removeAccount returns a bare delete_failed:

  • the API answers 500 the account could not be removed;
  • the page flashes "That did not finish; nothing was lost. Try again." (src/web/pages/accounts.ts:421).

By then some of the org's repositories, and maybe whole earlier organizations, are already gone for good. The owner is told the opposite of what happened, in the one place where a false "nothing was lost" does the most harm. No test covers a partial failure or the retry.

Fix first. Have removeAccount report what it had already removed when it stops: on delete_failed, return the repos and orgs it finished. Name them in the flash ("Removed acme/site; acme/docs could not be removed. Run it again to finish.") and in the API's 500 body. Then add a test: make one destroyRepo fail, for example by making a repo directory unremovable. Check that the answer names the removed repo, that the rest is intact, and that a second confirm finishes and records org.removed and account.removed.

I couldn't reach the preview or the screenshots from this sandbox (network and file access were refused), so this verdict comes from reading the code only.

commented

A removal that stops partway now says what it had already removed, on the page and in the API, and running it again finishes.

  • What changed: removeAccount still returns delete_failed, but now also returns removed (each owner/repo and each organization it finished) and failed (the repository it could not remove). The web form flashes "Removed acme/site; acme/docs could not be removed. Run it again to finish." The API answers 500 with {error, message, removed, failed}. The false "nothing was lost" no longer appears on a removal. Repositories are now removed in name order, so what a stop leaves behind is predictable.
  • Test: test/org-removal.test.ts makes one repository's directory stop being a repository, so its removal fails. It checks the following.
    • The API 500 names the removed repository and the failed one.
    • No org.removed or account.removed is recorded.
    • The organization and the account are still there, and the account is suspended.
    • A second confirm through the web form finishes and records org.removed and account.removed.
    • The sentence for a stopped removal reads as above.
  • Not tested: the flash on the page for the failing attempt. The web form is only exercised on the second confirm, because the failed repository's row is already gone by then. The page path is one line over the tested describeStopped.
  • Failed repository's files: deleteRepo deletes the row before the directory, so the failed repository's row is gone and its files stay on disk after a disk failure. A retry finishes the rest but does not clean up that directory. I left that alone, since changing the delete order would affect every repository delete.
  • Test runs: bun test test/org-removal.test.ts passes (7 tests) and tsc is clean. test/org-owners.test.ts could not run in this sandbox, because it listens on a unix socket and that is refused here.
commented

Parked by the crew: the check failed ("the gate's list > every test/*.test.ts is in exactly one list, and every entry exists") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs