Scoped Access
Scoped access lets admins assign specific forms to editors and viewers, restricting their dashboard to only the forms they need.
Overview
Users with global roleseditor or viewer don’t automatically see all forms. Instead, an admin explicitly grants them access to individual forms through the Manage Access dialog on the admin settings page (/settings/admins).
How It Works
Two Access Systems
Terra has two independent systems for form-level access:| System | Table | Purpose | Managed By |
|---|---|---|---|
| Scoped Access | user_form_access | Admin-assigned form grants | Super admins via Settings |
| Team Members | program_members | Per-form team invitations | Form owners via Form Settings |
Role Resolution
When determining a user’s effective role for a form, the system:- Queries
user_form_accessbyuser_profile_id(admin grants) - Queries
program_membersbyuser_idandemail(team invitations) - Merges results — higher role wins (
owner > editor > viewer) - Applies global role overrides (global
viewercaps to read-only)
Global Role Overrides
Global roles set a ceiling on form-level permissions:| Global Role | Effect |
|---|---|
super_admin / admin | Full access to all forms (bypass scoped access) |
editor | Can edit assigned forms only |
viewer | Read-only on assigned forms, even if form role is editor |
user | Standard form-level permissions apply |
Database Schema
user_form_access
The dedicated table for admin-managed grants, introduced in migration093.
- References
user_profiles(id)— a stable UUID PK — instead ofauth.users, avoiding FK issues with WorkOS user IDs - Uses
TEXTforroleinstead of an enum, avoidingprogram_roletype compatibility issues across deployments granted_bystores the admin’s user ID for audit purposes
Server Actions
getUserScopedAccess
Returns the list of available forms and the user’s current assignments.updateUserScopedAccess
Replaces all form assignments for a user. Uses delete-then-insert for clean state:- Looks up
user_profiles.idbyuser_id - Deletes all existing
user_form_accessrows for that profile - Inserts new rows for each selected form
UI
The Manage Access dialog is available on/settings/admins for users with editor or viewer roles. Admins can:
- See all available forms grouped by workspace
- Toggle individual forms on/off
- Save assignments with a single click
super_admin and admin users can manage scoped access for others.