Organization User Site
This junction links a membership (Organization User) to one or more Sites, enabling fine-grained, site-scoped access control.At a Glance
- Stores direct site assignments for a membership
- Effective access = assigned sites + all descendants
- Root site assignment grants access to entire organization
- Unique per (organizationUserId, siteId); cascades on delete
How Access Is Calculated
- Direct assignments are stored here (
assignedSiteIds). - Effective access includes the descendants of assigned sites (computed via a recursive CTE).
- Assigning the root site gives access to the entire organization (root + all children).
Constraints & Integrity
- Unique pair:
(organizationUserId, siteId)to prevent duplicates. - Cascades on delete/update to keep relations clean.
- Soft-deleted sites are filtered out by queries that list assignments.
Typical Operations
- On invitation: assign initial sites to the invited user.
- Update a member’s site list (replace entire set).
- Bulk operations for multiple users: replace, add, or remove sites.
Read Patterns
- User listings return
assignedSitesfor each member for easy display. - Access checks reference the calculated
accessibleSiteIds(descendants included). - Root site often appears as “Organization” in UI lists for clarity.
Security
- Only Managers and Owners can modify site assignments.
- All checks are further scoped to the acting user’s own accessible sites.
Tips & Edge Cases
- Users without any assignments will have no effective site access but may still appear in admin lists.
- Prefer
replacefor idempotent updates in bulk operations; useadd/removefor incremental changes.
Related Concepts
- Organization User — membership and role
- Site — hierarchical locations inside an organization

