Permissions
Role rules, row rules, permission files for other apps' RecTypes, and the as_system allow-list.
Cardinal checks permissions on every Cardinal.DB call and every REST route. An app declares who may do what in YAML.
Role rules
Each rule in a RecType's permissions gives one role a list of rights.
permissions:
- {role: System Manager, rights: [read, write, create, delete, report, export, print, email, share]}
- {role: Sales User, rights: [read, write, create, delete, report, export, print, email, share]}A rule may also set permlevel (fields at that level) and if_owner: true (only records the user created). Submittable RecTypes add submit, cancel and amend. The roles an app creates go in the manifest's roles.
Row rules
row_rules are expressions that must hold for a user to see a record. They only restrict.
row_rules:
- doc.to_user == user || has_role("System Manager")inherit_permission gives a record the access of another record it names. A CRM Task on a lead follows the lead's rules:
inherit_permission: {rectype_field: reference_doctype, name_field: reference_docname}Rules on another app's RecTypes
A file in permissions/ adds rules to a RecType another app owns. CRM lets Sales Users edit core's Address:
schema: 1
rectype: Address
permissions:
- {role: Sales User, rights: [read, write, create, report, print, email, share]}The owning app must agree before a file adds rights to its own roles. It lists the RecType in its manifest's widenable. Without that, a file may only narrow those roles' rules.
Check a decision
cardinal perm explain -t mysite.localhost --user rep@acme.test --rectype "CRM Lead" --ptype writeas_system
Cardinal.DB.as_system(ctx) skips the permission checks. An app may call it only in lib/controllers/, never in lib/rpc/. Every call site goes in as_system_allowlist.txt with a comment saying why:
# Makes the manager's CRM Sales Hierarchy node a group, which a Sales Manager may only read, as
# Frappe CRM's validate does with frappe.db.set_value.
apps/crm/lib/controllers/crm_sales_hierarchy.ex validateEach line is <file> <function>. A test compares the list to the code and fails on a missing, stale or refused line:
defmodule Crm.AsSystemTest do
use ExUnit.Case, async: true
alias Cardinal.Test.AsSystem
@root Path.expand("../../..", __DIR__)
@allowlist Path.join(@root, "apps/crm/as_system_allowlist.txt")
test "every as_system call site is in the app's reviewed allow-list" do
AsSystem.assert_allowlist!(AsSystem.sources(@root, "crm"), @allowlist)
end
endas_system does not lift the System Manager guard. Only a System Manager writes a system_manager_only RecType, even through as_system.