cardinal

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

InputCompiles to
fields with items.qtyA LEFT JOIN of the Table field's rows
fields with customer.territoryA LEFT JOIN of the Link target
filters on items.item_codeAn EXISTS over the child table
count(*), sum(f), avg(f), min(f), max(f) with group_byReport 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, _commentsToDo, Tag Link and Comment, as arrays or counts
rankRows whose name holds the text first, for Link search
for_update: trueFOR 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

PartDecides
Rights bitset14 standard rights (select, read, write, create, delete, submit, cancel, amend, print, email, report, import, export, share) and room for 18 extra rights
Rule layersApp rules, then the site's Custom RecPerm rows, with tombstones that remove a rule
Role decisiondecide with a trace, including child Records that defer to their parent, and singles
User PermissionsStrict mode, the owner fallback, and defaults for new Records
Field levelsWhich fields a user reads or writes (permlevel)
List scopeThe SQL predicate above
Row rulescardinal_expr rules, checked on a Record or pushed down into SQL
Inherit ruleA 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.

On this page