Two different resources, answering two different questions. Agents keep collapsing them into one. Read this before reasoning about who can see a tab, who can create a row, or who can read one.
The one question that prevents nearly every confusion below: for the request at hand, which resource does the system consult — the type resource (type-<type>) or the row’s own resource? Answer it first, then read the detail sections.
| Request | Resource consulted | Gate |
|---|---|---|
Type appears in the type selector (be-types) |
type resource | read |
POST /api/insert, POST /api/upload (a row that does not exist yet) |
type resource | create |
/api/validate-field, /api/validate-form (pre-row validation) |
type resource | type-level |
/api/item, /api/id, /api/value, /api/value-id |
the row’s own resource | read |
/api/update, /api/actions, /api/file |
the row’s own resource | update (file: read / delete per operation) |
/api/delete |
the row’s own resource | delete |
List of an ordinary author type (/api/list, /api/column) |
neither — authenticated caller, rows filtered to the readable set | — |
| List of a built-in type or a rollup | type resource | read (built-ins then filter rows to the readable set; rollups have no row resources) |
/api/types, /api/info, /api/css-variables |
no resource — app-level | :api-roles membership |
Base types (:users, :roles, :permissions, :resources, :settings, the joiners) have no row resources — every check on them degenerates to their type resource, and :tokens is the one built-in whose updates gate on its type resource (be-update’s carve-out); its rows do carry resources rows, which decide reads and deletes like any non-base row. Everything else — including the non-base built-ins :secrets, :saved-views, :usage, and :styling — gives each row its own resource, and that row resource is what existing-row requests consult.
:type-roles existsAccess to an existing row flows from that row’s own resource. A row that does not exist yet has no resource, so there is nothing to check. :type-roles is the stand-in for that case: the roles on the type resource (type-<type>, type-resource-name), consulted by be-insert through valid-user-permissions on "create". That is the question the key was added to answer.
An omitted declaration compiles to ("admin"). "admin" is always appended, whatever the model declares. A string entry such as "page-editors" is created with full CRUD; the (role-name perm…) form narrows that. Built-in types have their own defaults (:users gets "logged-in" and "user-creator", and so on) — those are not what an author type gets. Full vocabulary: docs/model-reference.md → Type roles.
The caller decides, not the type. insert-normal attaches exactly the roles argument it was passed, plus the creator’s exclusive role (<user>:exclusive). update-roles force-adds "admin" and the current actor’s exclusive role (not necessarily the original creator’s). Nothing in that path reads :type-roles.
roles and the row is private to its creator and admin.:type-roles and public may be attached by a non-holder (selectable-roles offers both on the Edit form), and the two force-added roles (admin, the current actor’s exclusive) are never user-selected adds. Retained roles — an unheld role already on the row’s resource — may be kept or removed freely (the D12 strip doctrine: removal is never restricted).:type-roles does not touch roles already on rows.The built-in UI pre-checks the type’s roles on the Add form — it reads the type-roles array of the /api/list response and fills the checkboxes — and the user may uncheck any of them before submit. That pre-check is a convenience. It is not a copy, and it is not what the row ends up with unless the user leaves the boxes checked.
The API pre-selects nothing. A caller of POST /api/insert must name the roles explicitly. Full statement: docs/rest.md → POST /api/insert.
The type resource and the row’s resource are independent from the row’s first moment, so a role declared in :type-roles never flows down to a row by itself. Exactly three paths put a role onto a row’s resource:
:suppress-roles t, the built-in Add form pre-checks the type’s :type-roles among the Roles checkboxes (selectable-roles); whatever is left checked rides with the insert. A holder of the role who creates a row and touches nothing gets a row every other holder can read and edit. Unchecking only locks other holders out, and admin can always repair that. This is the system’s only automatic bridge from a type’s roles onto new rows, and :suppress-roles t switches it off entirely — no palette renders, for admin included, so a role-suppressed type’s rows can never carry the type’s roles through the UI.:usage precedent (usage-insert calls update-roles with ("admin" "usage" …) on every row). Covers rows created after the change, forever; requires a code change in the writer.a:add-resource-role on the row’s resource. The only path that reaches rows created before either of the above.The symptom of skipping this step is the empty-list trap: a user holding a type role with no attach on the rows sees the tab (read on the type) and an empty list, and is denied on every existing row. The grant looks alive and does nothing. It is not a bug; it is the two lists being independent.
Reads, updates, and deletes of an existing row go through user-allowed-resource on the row’s own resource: be-rec, be-id, be-update, be-delete. valid-user-permissions is not on that path. Holding create on the type says nothing about whether you can read a row someone else created, and holding read on a row says nothing about whether you can create one.
Every check above has two halves. a:user-allowed — the join under both valid-user-permissions (type resources) and user-allowed-resource (rows) — answers yes only when the user holds the role (role_users), the role is attached to the resource (resource_roles), and the role carries the permission. Holding a role alone does nothing; a role on a resource alone does nothing. Admin’s reach is these two halves meeting.
The hold side is bootstrapped once, by a:initialize-database on a fresh database — init-database reaches it through initialize-tables when the admin user is absent, and reset-database after truncating; it short-circuits when any user exists. It creates the base permissions, the base roles (admin with full CRUD; public and logged-in with read only), and the two base users. Admin is created through add-user … :roles *init-roles*, and add-user appends *default-user-roles* (public, logged-in) for every user, links the user to each resulting role, and set-exclusive-role creates and links a full-CRUD <user>:exclusive. From birth, then, admin holds admin, public, logged-in, and admin:exclusive. Guest ends up holding public and guest:exclusive; the logged-in default is stripped immediately after creation.
The rest of the hold side arrives one role at a time: every role created through a:add-role is linked to admin as part of its creation — the (link rbac "roles" "users" role *admin*) tail, which is why init uses the internal insert-role instead (admin does not exist yet). Both of data-ui’s role creators go through add-role: ensure-model-roles (:type-roles entries) and ensure-declared-roles (model :new-roles). Admin holds every role the running model has ever declared, without anyone granting them.
A second admin does not automatically hold roles created after its grant: a:add-role links each new role to the user named admin only, so the one-at-a-time arrival above never reaches a second admin. It can still grant such a role to any user — the rule that a non-admin may grant on :users only roles it holds exempts anyone holding admin — and it reaches every row through the admin role, which is attached to every type and row resource. It comes to hold the role itself only through an explicit grant.
The attach side is the rest of this document: add-type-roles always appends admin to the type resource, update-roles force-adds admin to every row resource, and the library’s own add-resource attaches *default-resource-roles* (admin) to every resource it creates. Held plus attached, with admin carrying full CRUD, is why admin passes every user-allowed in the system — deploy-model-find-secret-id’s (be-list :secrets "admin" …) is the production proof on a built-in, non-base type.
Do not claim that the user named admin does not hold a role without checking — a review during the styling-type work made exactly that claim about the role admin itself, and it did not survive the source. When a permission check fails for admin, suspect the attach side (is the role on the resource?) before the hold side.
The recurring ask, in the exact shape it arrives: let a trusted non-admin manage :styling (banner / footer) without admin powers. The base model now ships exactly this configuration — :type-roles ("styling"), no :suppress-roles t — so the recipe is live: grant styling and it works. The steps below are its anatomy, and what you would repeat for another role name or another built-in.
:styling (:type-roles ("styler")), legal on any non-internal built-in; the author’s list replaces the default). The string form creates the role with full CRUD, admin holds it automatically, and type-styling carries it. Grant it to the user (Users → Edit → the role name).admin and the creator’s exclusive role. That is the empty-list trap, not a bug.:suppress-roles off the type (a code change in the base def — suppression is not reachable from a model redeclaration). The Add form’s Roles palette now preselects the type’s role, the rows a holder creates carry it, and every holder can edit them. Declaration plus one line — both shipped for :styling under the role name styling.update-roles force-adds admin), and a holder can grant styler onward only to users they can edit — in practice nobody but admin.:type-roles alone. That is the question the key exists to answer."read" (e.g. ("r" :create)) hides the tab from holders while API inserts still work.:type-roles (("r" :read :update :create)), or :new-roles for a badge role that gates membership without touching any type.admin role) can grant any role to any user, admin, ai-user and deployer included; a non-admin can grant on :users only roles it holds, never the admin-only ones; the built-in admin user always keeps admin and cannot be deleted; a user editing a row can attach roles they hold to that row’s resource — plus what the palette deliberately offers (public, the type’s declared :type-roles, shareable exclusives) — and the write path enforces exactly that: a crafted POST /api/update naming an unheld role beyond the exemptions is rejected, while removing or retaining roles the row already carries stays free.add-type-roles is add-only; old grants survive a redeploy. Removal is explicit (be-remove-type-roles, admin edit) or a clean slate.be-types emits a type only when the user holds read on the type resource, so the type selector happens to follow :type-roles. That is the same resource being consulted for a second question, not the reason the key exists. Do not treat “cannot see the tab” as “cannot read the row,” or the reverse: a user can hold read on a row whose type they cannot see, and a user can see a tab and still be unable to read a particular row.
A :page t type follows the same rule with nothing behind it: read on the page’s own type resource is what puts the tab in be-types and what be-list checks — the content type’s type resource and the content row’s roles are never consulted (the rollup precedent; no row-level RBAC on content rows). :type-roles on a page type is who may read the projection; the author who wants a private page is an author who points no page at that row. Creating the prose itself is the ordinary rule: :type-roles on the content type gates be-insert, and the rows carry their own roles as usual.
The REST handlers used to add a third, contradictory check here: require-auth was called with get-type-roles before the backend ran, so a caller who could read a row but held none of the type’s roles got a 401 and the row check never ran. That membership preflight is gone from the existing-row endpoints (/api/list, /api/item, /api/id, /api/value-id, /api/value, /api/column, /api/update, /api/delete, /api/actions, /api/file): they authenticate (a missing or invalid token is still a 401) and then authorize on the real resource — the row itself for item/value/update/delete/action/file, the readable-row set for lists.
What stays type-level: create (/api/insert, /api/upload — a row that does not exist yet has no resource), the pre-row validation endpoints (/api/validate-field, /api/validate-form), app-level metadata (/api/types, /api/info, /api/css-variables), and list access for rollups and built-in types — rollup rows have no resources, and built-in types keep their system contracts, so be-list gates those on the type resource. An ordinary author-defined type’s list needs only an authenticated caller: the list filters to the rows that caller can read, so a public grant on one row of an admin-only type is reachable directly even though the type never appears in that caller’s type selector. “Public” means the public role held by an authenticated user; under /api/* it is never anonymous. Under /p/ it is: a public grant on a row of an eligible type in a :guest-allowed model is anonymous read of that row’s View-form projection — exactly what the guest token already reaches, no more.
a: library)Every a: function in the data-ui source is the rbac library (~/common-lisp/rbac/, nickname a: via lisp/data-ui-package.lisp); its README is the complete generated reference manual. Every function takes the connection object first — at a data-ui REPL that is *rbac*. This section is the subset an agent actually reaches for at a REPL, verified live; learn the naming system once and the rest of the ~100 exports read without a lookup.
The naming system: every listing comes in three spellings — list-X-names returns plain strings, list-X returns full row plists, and X-count counts. The trap is calling list-X when you wanted names and then mapping plists by hand — there is almost always a -names twin. add-X and remove-X pair up symmetrically.
(a:list-user-names *rbac*), (a:list-user-role-names *rbac* "user") — the roles a user holds, names only (list-user-roles is the plist twin).(a:list-role-names *rbac*), a role’s permissions (a:list-role-permission-names *rbac* "role"), the users holding a role (a:list-role-user-names *rbac* "role"), the resources a role sits on (a:list-role-resource-names *rbac* "role").(a:list-resource-names *rbac*), (a:list-resource-role-names *rbac* "type-scenes") — works for type and row resources alike.(a:list-user-resource-names *rbac* "user" "read"); the row resources of one type (a:list-user-resource-names-of-type *rbac* "user" "scenes" :permissions '("read")); the permissions one user holds on one resource (a:list-user-resource-permission-names *rbac* "user" "type-scenes"); the users who hold one permission on one resource (a:list-resource-user-names *rbac* "type-home" "read").(a:user-has-role *rbac* "user" "role") (any-of over multiple role args), (a:user-allowed *rbac* "user" "read" "type-scenes") (the join behind every gate — hold plus attach plus permission), (a:get-id *rbac* "roles" "reader"), (a:id-exists-p *rbac* "users" "<uuid>").(a:add-user-role *rbac* "user" "role") / (a:remove-user-role *rbac* "user" "role") (also spelled add-role-user / remove-role-user, role first); (a:add-resource-role *rbac* "resource" "role") / (a:remove-resource-role *rbac* "resource" "role"); (a:add-role-permission *rbac* "role" "update") / (a:remove-role-permission *rbac* "role" "update").(a:add-user *rbac* "name" "email" "password" :roles '("reader")), (a:add-role *rbac* "name" :permissions '("read")), (a:add-resource *rbac* "name" :roles '("reader")), with remove-user / remove-role / remove-resource twins.data-ui’s resource names, for the resource arguments above: a type’s resource is type-<type-key> (type-scenes, type-resource-name); a row’s resource is <type>:<field-key>:<sanitized-value>:<uuid> (scenes:label:047:735394e1-..., make-resource-name — :name preferred, else the first non-base field in DATA’s own order carrying a value; characters other than alphanumerics, dash, and slash become dashes, and the value caps at 32 characters; find-resource-name is the lookup for an existing record). The stale-grant pattern from the scenebook v0.6 session: add-type-roles is add-only, so a type resource that outlived a model change keeps its old grants — read them with (a:list-resource-role-names *rbac* "type-<t>"), strip with (a:remove-resource-role *rbac* "type-<t>" "logged-in"); fresh deploys and reset-database never see the problem.