feat(rls): Phase 1 #4 — Department RLS + callsite fixes + gitignore scheduler lock#132
Merged
Merged
Conversation
…cheduler lock - Migration 20260529000000: enable RLS + FORCE on Department, composite index on (organizationId, id), SELECT/INSERT/UPDATE/DELETE policies for app_user, grants to app_user + admin_user - departments/route.ts: wrap findMany(GET) and parent findUnique+create(POST) with withOrgContext; orgId/organizationId from validated request - departments/[departmentId]/route.ts: loadDepartment() uses withAdminBypass (pre-auth lookup to discover orgId); GET findUnique, PATCH parent check + update, DELETE wrapped with withOrgContext(dept.organizationId) - agents/[agentId]/department/route.ts: dept existence check uses withAdminBypass (agent's orgId not in scope; cross-org isolation deferred to Agent table RLS migration) - .gitignore: add .claude/scheduled_tasks.lock; remove from git index RLS_ENFORCEMENT_ENABLED=false; wrapping is a no-op until flag flip.
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
20260529000000_rls_phase1_department: enables RLS + FORCE onDepartment, adds composite index on(organizationId, id), SELECT/INSERT/UPDATE/DELETE policies forapp_user, grants toapp_user+admin_userdepartments/route.ts(GET findMany, POST parent check + create) →withOrgContextdepartments/[departmentId]/route.ts→loadDepartment()useswithAdminBypass(pre-auth lookup to discover orgId); GET/PATCH/DELETE usewithOrgContext(dept.organizationId)agents/[agentId]/department/route.ts→ dept existence check useswithAdminBypass(agent's orgId not in scope; full cross-org isolation deferred to Agent table RLS migration).gitignore: adds.claude/scheduled_tasks.lock; removes file from git indexRLS_ENFORCEMENT_ENABLED=false— allwithOrgContextwrapping is a no-op until the flag is flipped after all 14 migrations land.Callsite audit
Three grep patterns confirmed exactly 9 callsites for
prisma.department.*outside generated/test code. No workers or crons accessDepartmentdirectly.Test plan
pnpm precheck— TS ✅ vitest ✅ ESLint ✅ (4119 tests, 307 files)SELECT COUNT(*) FROM "Department"asapp_userwithoutapp.current_org_id— must return 0 rowsapp.current_org_idto a valid org ID — must return only that org's departmentsGET /api/departments?orgId=<id>,POST /api/departments,PATCH/DELETE /api/departments/<id>work with flag off🤖 Generated with Claude Code