-
-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
P1Critical — must be done firstCritical — must be done firstphase:2-orgsPhase 2: Multi-tenancy & OrganizationsPhase 2: Multi-tenancy & Organizations
Description
Description
Migrate CASL from the current route-level authorization (role + action + route path) to document-level abilities with conditions (organizationId, userId).
Current system
- Policies register rules like
{ roles: ['user'], actions: 'manage', subject: '/api/tasks' } isAllowedmiddleware checksability.can(action, routePath)- Ownership checked separately via
isOwnermiddleware
Target system
- Each module defines abilities with conditions:
can('update', 'Task', { organizationId, userId }) isAllowedmiddleware checksability.can(action, subject('Task', document))- No more
isOwnermiddleware — ownership is a CASL condition - Abilities are built from
(user, membership)instead of just(user) - Each module exports an
xxxAbilities(user, membership, builder)function - Core collects and merges all module abilities via auto-discovery
- Platform
adminrole getscan('manage', 'all')— god mode bypassing organization checks
Naming
organizationId(notorgId)req.organization(notreq.org)req.membership(notreq.member)
⚠️ Security: mandatory test-first approach
Currently only 3 authorization tests (403) exist in the whole stack. This refactor MUST:
- BEFORE refactoring: add exhaustive auth tests for every protected route (expected 403s for unauthorized access)
- Refactor CASL
- AFTER refactoring: all old + new tests must pass
Merge order
Depends on #3218 (migration system). Must be merged BEFORE #3219 (organizations module).
Acceptance criteria
- Exhaustive auth tests added BEFORE refactor
- All existing policies migrated to document-level
-
isOwnermiddleware removed, replaced by CASL conditions - Platform admin gets
can('manage', 'all') - Auto-discovery of
modules/*/policies/*.policy.js - All existing tests pass
- No regression on authorization
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Critical — must be done firstCritical — must be done firstphase:2-orgsPhase 2: Multi-tenancy & OrganizationsPhase 2: Multi-tenancy & Organizations