Skip to content

Access rules and rights

An access rule says which roles can open a page, a region, a note or a lifecycle transition, or use one action of a region, and which rows each role sees. A right gives a set of rules a name, so that many pages can use the same rules. For a walkthrough, read Control who sees what.

The rule has two spellings. The property gives every named role the same filter:

access: board, trainer
access: authenticated where id = :user.member_id

The block gives each role its own line, its own filter and its own grants:

access {
head { grants: marks.points }
class_teacher where class.class_teacher = :user.teacher_id
student where id = :user.student_id
}
Rule Effect
No rule at all the page renders for nobody. On a page this is a compile error
One rule per role a second line for the same role in one block is a compile error
Several roles held a login can hold several roles. Every rule that names one of them applies, and the login sees the rows that any of those rules admits
where a filter on the rows of the rule’s table. It can read :user.… and :route.…, and not a data row or a var
{ grants: <table>.<column> } the role can read and write that sensitive column. A name without a dot grants a sensitivity class. See grants
On a note the rule can name roles only. A note shows no rows, so a where on a note is a compile error
In an action block the rule limits who can use delete, duplicate or a sheet’s add. It can only narrow the region’s rule, and it takes no grants:
A name a declared role, public, authenticated, or a right

owner, anonymous, tenant_admin, job and system are refused in a rule. See Reserved names.

access {
head_teacher { grants: grades.points, grades.remark }
teacher where course.teacher = :user.teacher_id { grants: grades.points }
}

grants: gives one role access to sensitive columns. Write it in braces after the role and after its where, if there is one. The value is one or more names, separated by commas. Each name is a <table>.<column>, or a sensitivity class without a dot.

A sensitive column is denied to every role that has no grant for it. A grant has these effects for its role, on the page or region that holds the rule:

  • A report, a list, a detail region and a CSV or XLSX export show the column. Without the grant, the engine leaves the column out of the query. There is no cell, no heading and no error.
  • A form renders a control for the column, and a sheet an editable cell. Without the grant, there is no control, and a request that names the column is ignored and logged.
  • A save without the grant keeps the stored value of the column.

A grant does not change which rows the role sees. The where does that. The engine records the reads and the writes of a granted column in the audit log. See Sensitive columns are granted per role.

The rules of the page and of the region together decide. A region can have its own access { … } with grants for its columns.

The compiler refuses these:

You write The compiler says
a value with more than one dot a grant names a table and a column
a name without a dot that no column declares as its class the message names the nearest class. For a column name, it shows the name with its table
a table’s name alone, such as grants: marks a table is never granted whole. The message lists the table’s sensitive columns
<class>.<column>, such as grants: grades.points a class is granted by its name alone
a table or a column that does not exist the message names the nearest name
a column that is not sensitive there is nothing to grant. Mark the column sensitive, or remove the grant
grants: directly in a page or a region, outside an access rule a grant belongs to one role. The message shows the rule to write
a form that creates rows, when an admitted role has no grant for a required sensitive column the role could never save the form
a column that reads a sensitive column, such as a sum or a value:, and is not sensitive see Sensitive columns are granted per role

The engine refuses a region that shows a sensitive column when no rule of its page or of the region grants the column, because no role could ever see it. It refuses the region when it opens the application, and the message names the grant to add.

The shorthand access: board, trainer has no grants. Use the block to grant a column. In a right, write the grant on the line of the role. The line that names a right has no grants of its own.

table marks "Marks" {
points int sensitive(grades) "Points"
remark long text sensitive(remarks) "Remark"
}
table enrolments "Enrolments" {
final int sensitive(grades) "Final grade"
}
access {
head_teacher { grants: grades, remarks }
student where enrolment.student = :user.student_id { grants: grades }
}

sensitive(<class>) puts a column in a named sensitivity class. A grant that names the class grants every column in it, in every table. Above, grants: grades grants marks.points and enrolments.final.

Rule Effect
Declaration a class exists when a column names it. There is no separate declaration
One class per column a column is in one class, or in none. A plain sensitive is in none, and only a grant of the column itself reads it
Mixed grants grants: can name classes and columns together. A column that both name is granted once
Rights a right can grant a class. When two sources give one role a rule, the compiler compares the columns, not the names: grants: grades and grants: enrolments.final, marks.points are the same rule
Names a class cannot have the name of a table, so grants: marks is never read as “every sensitive column of marks”
Calculated columns a column that reads a sensitive column must be sensitive too. It can use the same class, another class or none. The compiler suggests the class when every sensitive column it reads is in one class

The compiler replaces a class with its columns when it compiles the application. The engine therefore decides every read and write exactly as for column grants.

The compiled model lists the expanded columns in every rule’s grants, so a comparison of two models shows the extra column.

A right is a top-level declaration, like table and page. Write it in any .mtd file of the application. app.mtd, beside the roles, is the usual place.

right edit_members "Edit members" {
board
trainer
}
right edit_own_team of members "Edit your team" {
trainer where team.trainer = :user.member_id { grants: members.fee }
}

The declaration has a name, an optional of <table>, a label, and a body. The label is required. The body is the body of an access block: one line per role, each with an optional where and optional grants.

Name the right wherever an access rule can go, alone or beside roles:

page members "Members" {
route: /members
access: edit_members, treasurer
}
page member "Member" {
route: /members/{id}
access {
edit_own_team
board
}
data member of members
}

The compiler replaces the right with its rules where you name it. The engine never sees a right. It sees one rule per role, as if you had written the rules on the page.

A filter is a condition on the rows of one table. When a line of a right has a where, the right must say of <table>. The compiler reads the filter against that table.

You can then name the right only where the rule is about that table:

  • on a page, the table of the page’s first data row or region;
  • on a region, the region’s table;
  • on a lifecycle transition, the table of the lifecycle.

A right without of can be named anywhere.

You write The compiler says
a right with the name of a declared role roles and rights share one namespace
a right named public, authenticated, owner, anonymous, tenant_admin, job or system the name is a reserved role’s
a right that names another right a right lists roles only
a where in a right without of the filter needs a table
of <table> with a table that does not exist unknown table
a right with of members named on a page about teams the filter would mean something else there
:route.… in a right’s filter a right is named on pages with different routes
access: edit_members where …, or access { edit_members { grants: … } } the line that names a right has no filter or grants of its own
a right with a filter named on a note a note shows no rows
a right named twice in one block name it once
two sources that give one role different rules see the next section

Two sources can give the same role a rule: two rights, or a right and a line you wrote in place. When the two rules are the same — the same filter and the same grants — the compiler keeps one. When they differ, it is a compile error that names both. Two different rules for one role would add up, and the role would see more than either rule allows.

right edit_members "Edit members" { board }
right see_fees "See fees" { board { grants: members.fee } }
page members "Members" {
route: /members
access: edit_members, see_fees // refused: board gets two different rules
}

Every check on access rules reads the rules a right expands to. A right does not hide a rule from any of them. For example, a form that creates a row must grant every required sensitive column to every role it admits, and the error names the right that should carry the grant.

The compiled model lists the application’s rights, sorted by name, with their label, their table and their rules. Each rule that came from a right records its name in from_right. A rule written in place records nothing. When two sources gave a role the same rule, the model keeps the rule written in place, or else the one from the right whose name sorts first.

Website privacy policy