Add a role
Goal
Create a public.roles row whose slug you can reference from record_permissions in type design schemas, min_role/required_roles on apps, and role:<slug> notification recipients.
Prerequisites
- A
system_adminlogin — role create/update/remove requires it (.framework/functions/roles.ts).
Steps
- Pick the slug. Lowercase snake_case (
support_agent). It is matched verbatim as a key inside every type'srecord_permissionsand is effectively immutable — the admin UI disables slug editing after creation. Uniqueness is enforced at both the API layer (duplicate-slug check before insert) and the database (UNIQUE(slug),.framework/migrations/009_roles_slug_unique.sql). - Decide the permissions payload.
roles.permissionsis a JSON document on the role row (permissions jsonbon the table,.framework/migrations/001_core_schema.sql). Seeded roles carry'["*"]'— a wildcard grant. Per-type grants are expressed on the type side (design_schema.record_permissionskeys are role slugs), which is whatadmin-dataevaluates per request — see Permission model. - Create the role. Admin UI → Configs → Roles → New (
configs/roles/new), orPOST /api/roleswith{ slug, name, permissions, is_system }—slugandnameare required (.framework/functions/roles.ts). Thesystem_adminslug itself is protected: only a system admin may create it (.framework/functions/roles.ts). - Reference the role. Add its slug to each type's
design_schema.record_permissions, toapps.min_role/apps.required_roles, and tosend_notificationstage recipients asrole:<slug>(resolved viapeople.role_id → roles.slug— see Automation). - Assign it to people. A person's
role_idjoins toroles; the permission engine resolvespeople.role:role_id(slug)and evaluatesrecord_permissionsagainst that slug (.framework/functions/_shared/permissions.ts).
Verify
GET /api/roles?action=listreturns the row;slugis unique and active.- Create or update a type whose
record_permissionsincludes the new slug, then perform anadmin-datacall as a person holding the role — the action is permitted. system_adminusers see all roles regardless ofis_activefilters.
Common mistakes
system-adminvssystem_admin. All seeded slugs are snake_case:system_admin,member,member_admin,engineering,engineering_admin,product,docs,qa,devops,management,sales,csm,tam,support,support_admin(.framework/migrations/003_core_system_data.sql,.framework/migrations/073_seed_member_roles.sql). Using hyphens inrecord_permissionsgrants nothing.- Expecting
roles.permissionsto gateadmin-data. Record-level grants live on the type'srecord_permissions; the role row'spermissionsJSON is not consulted per-request for record CRUD. - Renaming a slug later. Every type's
record_permissionsand every app'smin_role/required_rolesreference the slug verbatim — a rename orphans the grants. Create a new role and migrate people instead. - Creating
system_adminvia API as a non-admin — explicitly blocked. - Deactivating a role with live assignees — the slug stops resolving to a grant for those people; check
people.role_idusage first.
Reference
- roles entity page · roles function reference
- Permission model · Add a type
- Database reference for the
rolescolumns