Queries and permissions
cardinal_query compiles list requests to SQL. cardinal_perm decides every right.
Apps never write SQL. A list request and the user's permission scope compile together into one parametrized statement.
A list request, step by step
GET /api/rec/Sales Invoice?filters=[["status","=","Overdue"]] reaches RecordService.list.
Elixir loads the principal (user, roles, User Permissions, shares) and the compiled metadata, and asks cardinal_perm for the list scope.
cardinal_perm returns a predicate: the role rules, User Permissions, owner-only rules, row rules and shares that decide which rows the user may read.
cardinal_query compiles fields, filters, order, page and that predicate into one SELECT with $n placeholders. Every table and column name comes from metadata and is quoted. Every value is bound.
Elixir runs the statement in the request's transaction.
cardinal_query
| Input | Compiles to |
|---|---|
fields with items.qty | A LEFT JOIN of the Table field's rows |
fields with customer.territory | A LEFT JOIN of the Link target |
filters on items.item_code | An EXISTS over the child table |
count(*), sum(f), avg(f), min(f), max(f) with group_by | Report groups |
sum(f, [filters]) | A sum with a CASE on the main row |
month(f), quarter(f), year(f), day(f) | Date buckets, in the site's zone |
_assign, _tags, _comments | ToDo, Tag Link and Comment, as arrays or counts |
rank | Rows whose name holds the text first, for Link search |
for_update: true | FOR UPDATE OF t on a plain list |
A column the user cannot read fails with forbidden_field, and * selects only readable columns. A JSON column cannot be sorted on. An alias over 63 bytes fails, since Postgres would cut it.
cardinal_perm
| Part | Decides |
|---|---|
| Rights bitset | 14 standard rights (select, read, write, create, delete, submit, cancel, amend, print, email, report, import, export, share) and room for 18 extra rights |
| Rule layers | App rules, then the site's Custom RecPerm rows, with tombstones that remove a rule |
| Role decision | decide with a trace, including child Records that defer to their parent, and singles |
| User Permissions | Strict mode, the owner fallback, and defaults for new Records |
| Field levels | Which fields a user reads or writes (permlevel) |
| List scope | The SQL predicate above |
| Row rules | cardinal_expr rules, checked on a Record or pushed down into SQL |
| Inherit rule | A Record's rights taken from another Record it names |
cardinal perm explain and the core.perm.explain RPC print the trace. The browser runs no permission checks. CI still builds the crate for WASM.
Both crates replay golden corpora, which ExUnit also runs through the NIF.