feat(teams): backend foundation — orgs/teams/RBAC APIs + schema#6
Merged
Conversation
Phase 1 (schema) + Phase 2 (backend APIs) of the teams/orgs plan. Migration backend/migrations/0001_teams_orgs.sql (additive, no RLS yet): - organizations, organization_members, teams, team_members - permissions (29), roles (5 system) + role_permissions (107 mappings) - role_assignments, invitations, resource_locks, audit_log - nullable org_id/team_id on projects/workflows/tabular_reviews/chats/subfolders - app_provision_personal_org() + backfill of personal orgs for existing users Applied + verified on the staging Supabase project. Backend: - lib/tenancy.ts — membership + permission resolution, loadOrgContext + requirePerm middleware, audit + personal-org helpers - lib/email.ts — Resend wrapper (no-ops without RESEND_API_KEY; returns accept_url for manual sharing until SMTP is wired) - routes: organizations, teams, members, roles, invitations (+ accept), locks - wired into index.ts (nested routers use mergeParams for :orgId) Non-breaking: existing routes untouched; new tables/columns are additive and the service-role backend is unaffected. RLS, the user_id->uuid migration, frontend, and resource scoping are tracked as later phases. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phases 1 (schema) + 2 (backend APIs) of
docs/TEAMS_AND_ORGS_PLAN.md, plus most of Phase 3 (invitations).Schema (
backend/migrations/0001_teams_orgs.sql, additive, applied+verified on staging):orgs/teams/members, permissions(29)/roles(5)/role_permissions(107), role_assignments, invitations, resource_locks, audit_log; nullable org_id/team_id on resource tables; personal-org provisioning + backfill. No RLS yet (deferred to the coordinated hardening phase).
Backend APIs:
/organizations(list+auto-provision personal, create, get, update, delete)/organizations/:orgId/teams|members|roles|invitations/invitations/accept/locks/:type/:id(acquire/heartbeat/release/status)loadOrgContext+requirePerm; audit logging; Resend email wrapper (returns accept_url until SMTP wired).Safety: non-breaking — existing routes untouched, new tables/columns additive, service-role backend unaffected.
tscgreen.Deploys to staging on merge for API testing. Prod untouched.
🤖 Generated with Claude Code