Skip to content
MyAppBuilder
StableGuide

Record-level permissions

A record-level rule limits a role to some records of an entity instead of all of them. The classic case is "own records": a customer sees only the quotes whose Customer Email equals the email they signed in with. The rule is part of the role's entity permission and is enforced on

Record-level permissions

A record-level rule limits a role to some records of an entity instead of all of them. The classic case is "own records": a customer sees only the quotes whose Customer Email equals the email they signed in with. The rule is part of the role's entity permission and is enforced on the server for reads and writes.

When to use

  • Customer portals: quotes, orders, bookings, jobs, files, messages of this customer.
  • Staff who should only edit records they created.
  • Partners or branches limited to their own data.

The two ways to scope records

  1. Only their own — pick the field that identifies the user: - an email field (or a text field holding an email): matched against Current user › email; - Created by: matched against the user's id, so people only see records they added themselves.
  2. Custom filter — any filters on the entity's fields, all of which must match; values can be fixed or Current user values. Example: Branch equals Current user › name (for branch accounts) or Status is not Draft.

The Public role cannot have a record scope: visitors without an account have no identity to compare with.

How to set an "own records" rule

  1. Make sure the entity has a field that holds the owner, for example Customer Email (type Email). Your forms should fill it with Current user › email (portal blocks do this automatically).
  2. Open Users → Roles & permissions → Data permissions and click the cell Customer × Quotes.
  3. Choose the operations (for example View and Edit).
  4. Under Which records? choose Only their own, then pick Which field holds the user? → Customer Email.
  5. Click Save access. The cell shows the person icon.
Example
Customer × Quotes
  View, Edit
  Only their own: Customer Email = Current user › email

How the server applies it

  • Reading: lists, detail views, charts and exports return only matching records; a direct request for another record answers "Record not found."
  • Creating: a new record must satisfy the rule, otherwise "You can only create quotes that belong to you." Your form should set the owner field from Current user › email.
  • Editing: the record must match before the change and after it — a customer cannot reassign a quote to someone else ("That change would move the record outside what you can access.").
  • Unresolvable values deny access. If the rule compares with the user's email and the visitor has no email (not signed in), nothing matches.

Portal blocks add it for you

Customer-portal business components (Quotes, Quote Approval, Orders, Jobs, Files, Messages, My Requests, Booking, Support Request, …) add a Customer rule on their entity scoped by Customer Email (or Email / Client Email) with the operations they need (read, sometimes create or update), and pre-fill that field in their forms. You can always adjust the rule in the matrix.

Rules that look up the user's organization (lookup rules)

Beta. Some records belong to a group — an organization, a team, a site — rather than to one person. A lookup rule keeps a record visible to everyone who is an active member of its group, without copying lists of people onto records.

Set it up in the builder

  1. Open Users → Roles & permissions → Data permissions and click the cell, for example Client × Requests.
  2. Choose the operations, then under Which records? → Lookup rules click Add lookup rule. The editor suggests a rule from your tables (a members table with an Email field that points at the same group table, filtered on Status is Active when it has one); adjust it: - Records whose… — the field of this table to check (Organization; ID on the organizations table itself); - …is one of the values in table — the table to look in (Portal Members). Changing it re-picks the fields below; - Taking the values of field — which values are allowed (Organization; ID takes the matched records' ids); - From the records where — the field that holds the user and whether it equals my email or my user id (Created by); - Only … records that also match — up to 5 extra conditions on the looked-up table (Status is Active).
  3. The card reads the rule back in plain words, e.g. Organization is one of the Organization values of the Portal Members records where Email is the current user's email and Status is “Active”. A missing field or table is shown in red and Save access stays disabled; comparing values that can never match (an organization with member ids) shows a warning.
  4. Click Save access. The cell shows the person icon. The rule is combined with Only their own / Custom filter: everything must match. Remove a lookup with its bin icon.

Rules made by an app plan or a starter (Customer & Supplier Portal) open in the same editor and are saved back unchanged unless you edit them.

In an app plan

Example
{ "role": "client", "entity": "Requests", "operations": ["read"],
  "where": [{ "field": "Organization", "op": "in_lookup",
              "lookup": { "entity": "Portal Members", "match": "Email", "equals": "{{user.email}}",
                          "value": "Organization", "where": [{ "field": "Status", "op": "eq", "value": "Active" }] } }] }

Read it as: the request's Organization must be one of the Organization values of the Portal Members records whose Email is my email and whose Status is Active. On the organizations table itself, use "field": "id". "value": "id" takes the matched records' ids.

  • Enforced by the server on every list, open, change, delete, total and file link, exactly like an "own records" rule (and combined with the rule's other filters: all must match). Adding or removing a member changes access on the next request — for every record at once.
  • Exact. Values are compared exactly (org_a never matches ORG_A or org_ab); emails compare case-insensitively. For a field with several values (a multi relation), one matching value is enough.
  • Deny by default. No signed-in email, a missing table or field, a lookup that can't be read, or more than 500 matching membership records → the user sees nothing.
  • Limits: at most 5 lookup rules per access rule; the lookup table is read once per request; the role needs no access to the lookup table itself.

Common mistakes

  • The owner field is empty on old records. They match nobody. Fill it in the Data section.
  • Different spelling or case. Emails are compared after lowercasing; other text is compared case-insensitively too, but extra spaces matter.
  • Scoping by a field the customer can edit. Combine the scope with a Read-only rule on the owner field so customers cannot change it.
  • Using Created by for records staff create on behalf of customers. Use an email field instead.

Advanced

The rule's condition is a list of filters { fieldId, op, value } where value is usually { type: "current_user", key: "email" | "id" } (created_by for the creator). resolveRuleFilters returns null — deny — when a value is empty; recordAllowed and writeKeepsScope check reads and writes in src/server/data/records.ts.

Related

Was this helpful?