feat(rls): Phase 1 #10 — ApprovalPolicy RLS + callsite fixes#138
Merged
Conversation
Migration 20260604000000: TENANT_DIRECT RLS on ApprovalPolicy. Pre-auth lookups (loadPolicy, decisions pre-auth) use withAdminBypass — same pattern as loadDepartment/loadGoal from migrations #4/#5. CRUD routes use withOrgContext with org ID from loadPolicy result. checkPolicies gains optional organizationId param; requestApproval wraps the policy findUnique in withOrgContext. processTimeouts unchanged — cross-org cron relies on DATABASE_URL BYPASSRLS.
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.
Summary
20260604000000_rls_phase1_approvalpolicy: TENANT_DIRECT RLS onApprovalPolicy(SELECT/INSERT/UPDATE/DELETE policies + compositeorganizationId, idindex)loadPolicyin[policyId]/route.ts, pre-authfindUniquein[policyId]/decisions/route.ts): usewithAdminBypass— fetch org ID to perform the auth check itself; same pattern asloadDepartment/loadGoalfrom migrations chore(deps): bump actions/deploy-pages from 4.0.5 to 5.0.0 #4/chore(deps): bump pnpm/action-setup from f40ffcd9367d9f12939873eb1018b921a783ffaa to b906affcce14559ad1aafd4ab0e942779e9f58b1 #5policies/route.tsGET/POST,[policyId]/route.tsGET/PATCH/DELETE): usewithOrgContextwith org ID already in scope from query param / body /loadPolicyresultcheckPoliciesinapproval-engine.ts: gains optionalorganizationId?: string | nullparam; fail-open catch still handles missing org; no production callers yet so signature change is saferequestApprovalinapproval-engine.ts: wrapsapprovalPolicy.findUniqueinwithOrgContext;organizationIdwas already in its signatureprocessTimeoutsinapproval-engine.ts: NO CHANGE — cross-org cron that processes expired decisions across all tenants; relies onDATABASE_URLhavingBYPASSRLS(Phase 0b); comment added to document intentAdmin-path classification
policies/route.tsGET/POSTwithOrgContextrequireOrgMemberauth, org ID in scope[policyId]/route.tsloadPolicywithAdminBypass[policyId]/route.tsGET/PATCH/DELETEwithOrgContextloadPolicy, auth passed[policyId]/decisions/route.tspre-authwithAdminBypassapproval-enginecheckPolicieswithOrgContextapproval-enginerequestApprovalwithOrgContextapproval-engineprocessTimeoutsTest plan
pnpm precheck— 4/4 pass ✅POST /api/policies, list viaGET /api/policies?orgId=…, confirm no 42501; trigger governance-timeout cron, confirmprocessTimeoutsstill resolves expired decisions across all orgsRLS state after this PR
Phase 1: 10/14 live — OrganizationMember, Invitation, CompanyMission, Department, Goal, AgentPermissionGrant, HeartbeatConfig, HeartbeatContext, HeartbeatRun, ApprovalPolicy
🤖 Generated with Claude Code