Skip to content

Admin: link a tenant to its IdP org, and delete an organisation - #6

Merged
cliftonc merged 2 commits into
mainfrom
admin-link-idp-org
Nov 2, 2026
Merged

cliftonc merged 2 commits into
mainfrom
admin-link-idp-org

Conversation

@cliftonc

@cliftonc cliftonc commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Problem: under IdP-managed tenancy, a tenant someone made in the app has no external_org_id. So the org's first sign-in creates a second tenant (psychiatry-uk-2 in Unwind). The kit can't match by slug, because any user may create a tenant and could take a client's slug first. That second tenant has no owner, so nobody could delete it.

Global admins now have two new controls:

  • Identity provider org panel on Admin → organisation, shown under managed tenancy or when the tenant is already linked. PUT /api/admin/tenants/:id/external-org { externalOrgId | null } links or unlinks the tenant.
    • Returns 409 external_org_taken (naming the tenant that holds it) when another tenant is linked to that org.
    • Logged as tenant.idp_linked / tenant.idp_unlinked.
    • The next sign-in adopts the tenant's manual admin and member rows. Owners are left as they are.
  • Delete organisation (danger zone). DELETE /api/admin/tenants/:id { confirm: slug } reuses the owner's deleteTenant: the cascade, then tenant.purge. The deletion is logged, since the tenant's activity log goes with it.

The admin tenant DTOs gain externalOrgId, and the detail gains idpManaged. CONCEPTS §2 documents linking.

Tests: link, conflict, unlink and activity; admin-only; delete with slug confirmation; a linked hand-made tenant is the one the org signs in to. pnpm gate passes, apart from kit-manifest locally, which only fails because of untracked docs/unwind/ files.

🤖 Generated with Claude Code

cliftonc and others added 2 commits November 2, 2026 16:12
A tenant made in the app is never matched to an issuer org by slug, so the
org's first sign-in made a second tenant. A global admin now sets or clears
tenants.external_org_id (409 external_org_taken when another tenant holds
it), and can delete an organisation, including an ownerless one managed
tenancy created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cliftonc
cliftonc merged commit 3819d66 into main Nov 2, 2026
15 checks passed
@cliftonc
cliftonc deleted the admin-link-idp-org branch November 2, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant