Permissions: who may read and write
Who may read and write what: the built-in $users entity, the permissions on each entity and field, and the patterns that work. Part of the schema language; the rules a permission is made of are in schema-rules.md.
The built-in $users entity#
Users are created by sign-in (see api-sign-in.md), never by mutations. Every tenant has its own users: the same email in two tenants is two users.
The system schema defines:
- Lang
- EDN
:$users {:permissions {:view [(self? ?e ?user)]} :attrs {:email {:type :string :unique? true :format :email :view [(self? ?e ?user)]}}}
- In GraphQL the type is
User, with the rootsusers,user(id:)andme. - Users are closed by default. A signed-in user sees only themself
(
me, and themself inusersanduser(id:)); a signed-out caller sees no users. Wherever a user the caller can't see would appear, it isnull: anauthorref,createdBy, a member in a list of members. A<ref>Idfilter naming such a user matches nothing, as for an id that doesn't exist. A write naming such a user (authorId,addListMembers) isNOT_FOUND, as for any target the caller can't see. emailis visible only to the user themself, whatever the rule on$userssays.
You may add attributes and refs to $users:
- Lang
- EDN
:$users {:attrs {:display-name {:type :string :optional? true :min 1 :max 40 :trim? true :collapse-whitespace? true}}}
You may not redefine email or set :graphql/type on $users. When you
add attributes, october generates updateUser(id:, input:), and a user
may update only themself and only the attributes you added. A user's
attributes are readable by whoever may see the user; put a :view rule
on one that is for fewer people.
Who may see users#
Declare :permissions {:view <rule>} on $users to show users to more
people. It replaces the default (keep (self? ?e ?user) in it, or users
won't see themselves), and :view is the only action you may set on
$users: users come from sign-in, and updateUser is built in. Show
people the users they have a reason to see:
- Lang
- EDN
;; authors of things I can see: myself, and anyone who wrote a post ;; (posts here are readable by everyone, so signed-out readers see authors too) :$users {:permissions {:view [(or-join [?e ?user] (self? ?e ?user) [_ :posts/author ?e])]}} ;; teammates: myself, and anyone on a team with me :$users {:permissions {:view [(or-join [?e ?user] (self? ?e ?user) (teammate? ?e ?user))]}}
When the things are not public, join them to their own rule, so a user
is visible exactly when something they wrote is:
(and [?p :posts/author ?e] (can-see-post? ?p ?user)).
Avoid true and [(authenticated? ?user)]: with either, anyone who
signs up can list every user of your app (and their display names, and
every attribute without its own :view). october plan warns when the
rule lets every signed-in caller see every user: "anyone who signs up
can list every user".
To let people share with someone they have nothing in common with yet (adding a list member, inviting to a team), that person must be visible to them first. One way is an opt-in the user sets on themself:
- Lang
- EDN
:$users {:attrs {:findable {:type :boolean :optional? true}} :permissions {:view [(or-join [?e ?user] (self? ?e ?user) (shares-list? ?e ?user) (and (authenticated? ?user) [?e :$users/findable true]))]}}
Changed (October 2026). Before, $users was readable by anyone (:view true). A tenant whose schema declares no $users :view now gets the
closed default; october plan shows it as a $users permission change
("view true -> [(self? ?e ?user)]: the system default changed") until
the next push. To keep the old behaviour, declare a rule as above.
Refs from your entities to $users add reverse fields to User (for
example User.ownedLists).
Who may erase a user#
- Lang
- EDN
:$users {:permissions {:view [(or-join [?e ?user] (self? ?e ?user) (has-role? ?user :operator))] :erase [(has-role? ?user :operator)]}}
:erase (on $users only) adds eraseUser(id:): whoever passes the
rule (?e is the user to erase) erases a user they can see, as
eraseMe erases oneself (see api-mutations.md). Without
it there is no eraseUser, and only the user (eraseMe) and the
tenant's admins (october erase) can erase.
Permissions#
Each entity's :permissions maps an action to a rule:
| Action | Checked when |
|---|---|
:view |
on every read: list roots, by-id roots, nested fields, live queries |
:create |
on the new entity, as it would be after the write |
:update |
on the entity before and after the change, so a user can't hand an entity to someone else. A rule with (before ...) is instead checked once over both states. Not the :create rule: put create-only conditions on the attribute's own :update, or make it immutable (see Field :update rules and Immutable attributes) |
:delete |
on the entity before the delete, and on every component the delete removes |
A rule is one of:
true: anyone, signed in or not.- A vector of Datalog
:whereclauses, all of which must hold. Two variables are bound:?eis the entity and?useris the signed-in user. Any other variable is local to the rule.
An absent action is denied. If you leave out :delete, nobody can
delete, and october generates no delete mutation.
In october, a missing rule means no access and no mutation — not a table open to anyone.
Defaults#
What you get when you write nothing:
| You leave out | What happens |
|---|---|
:view on an entity |
Nobody can read it. Its type and roots are still generated, but lists are always empty, by-id roots answer null, and a create or update succeeds but answers null with a NOT_VIEWABLE warning in extensions.warnings. october plan warns: "nobody can read Note", or "Note can be created but never read" when it has a write rule. |
:create, :update or :delete |
Nobody can do it, and there is no mutation for it. |
:permissions altogether |
Nobody can read or write the entity through the API. |
:view on an attribute |
Anyone who can read the entity reads the attribute. october plan warns when you add such an attribute to an existing entity: "new field Employee.salary is readable by anyone who can read Employee, including signed-out users" (or, when only signed-in users can read the entity, a gentler note). |
:update on an attribute |
Any update the entity's :update rule allows may change it. |
:pinned? on a :default :auth/user ref |
It is pinned: a create or update may set it only to the signed-in user (see :default :auth/user). |
:view on $users |
Each user sees only themself; signed-out callers see no users. Authors and createdBy that the caller can't see are null. email is always the user's own only. Widen it with your own $users :view (see Who may see users); october plan warns when that lets anyone who signs up list every user. |
Anonymous callers: an anonymous caller never evaluates anything that
mentions ?user (also inside not, or, or a rule call). true and
rules that never mention ?user work for them as for anyone. A rule that
mentions ?user is cut for them: each top-level or (or or-join)
keeps only its branches that don't mention ?user, and the rule's other
top-level clauses stay. If one of those other clauses mentions ?user,
or an or has no such branch, the rule is denied to anonymous callers.
Signed-in callers always get the whole rule. See
Published or mine below.
The same applies to :create, :update and :delete: an anonymous
write through a user-free branch is allowed, just as with true. An
anonymous write that can't pass gets UNAUTHENTICATED.
A rule sees the database after the write for :create (so it can check
the new entity's own values) and the entity's refs as stored. A write is
decided on a snapshot; if anything a rule read changes before the write
commits (a moderator role revoked, an answer added), october decides the
write again on the new data, so a rule never passes on stale data. Patterns
compare refs by entity, so [?e :lists/owner ?user] means "the owner of
?e is the caller".
Examples:
- Lang
- EDN
;; public read, signed-in write as yourself, edit and delete your own :permissions {:view true :create [(authenticated? ?user) (post-author? ?e ?user)] :update [(post-author? ?e ?user)] :delete [(post-author? ?e ?user)]} ;; private to the author :permissions {:view [(author? ?e ?user)] :create [(authenticated? ?user) (author? ?e ?user)] :update [(author? ?e ?user)] :delete [(author? ?e ?user)]} ;; public read of published items only (no ?user, so it works anonymously) :permissions {:view [[?e :news/stage :news.stage/published]] ...} ;; a reply needs an unlocked thread :create [(authenticated? ?user) (post-author? ?e ?user) [?e :posts/thread ?t] (not [?t :threads/locked true])] ;; using the built-in creator rule instead of an author attribute :permissions {:view true :create [(authenticated? ?user) (created-by ?e ?user)] :update [(created-by ?e ?user)] :delete [(created-by ?e ?user)]}
The check [(authenticated? ?user) (author? ?e ?user)] on create is what
stops a caller from naming someone else as the author: the create would
give FORBIDDEN.
Hidden and missing are the same to a client. An entity the caller can't
view is left out of lists, is null from a by-id root, and gives
NOT_FOUND to a mutation.
Field-level :view#
Any attribute or ref may carry :view <rule>. When the rule fails for the
viewer, the field reads as null. The field is nullable in GraphQL, and it
is never a filter or an orderBy field, so a filter can't reveal the
value.
- Lang
- EDN
:owner-note {:type :string :optional? true :max 500 :view [(list-owner? ?e ?user)]}
Members of the list see ownerNote: null; the owner sees the value. A
field with a :view rule can be written only by a caller for whom the
rule holds.
createdBy is also guarded: if an entity has a :default :auth/user ref
with a :view rule (an anonymous author, for example), createdBy is
null unless that rule holds, because the creator is the person the rule
hides.
Field :update rules, before and :transitions#
An attribute may carry its own :update rule. It is checked only when
a write changes that attribute, in addition to the entity's :update
rule. Inside an :update rule (the entity's or an attribute's),
(before clause ...) reads the entity as it was before the write;
every other clause reads it as it is after. Together they say what a
plain rule over one state can't: who may hand a record on, which way a
flag may move, which moves a status may make.
Only the owner may hand a deal on#
- Lang
- EDN
:deals {:attrs {:title {:type :string :min 1 :max 200} :owner {:type :ref :to :$users :update [(before [?e :deals/owner ?user])]}} :permissions {:view true :create [(authenticated? ?user)] :update [(authenticated? ?user)] :delete [[?e :deals/owner ?user]]}}
Any signed-in teammate may edit a deal, but only the caller who owned
it before the write may change owner: give it to someone else, or
clear it. Without the field rule, the owner-only :delete would not
protect anything: a teammate could set owner to themselves, then
delete.
- Lang
- Text
mate updateDeal(title: "Acme 2") ok mate updateDeal(ownerId: <mate>) FORBIDDEN, extensions.field "ownerId" mate updateDeal(ownerId: <owner>) ok (the value it has: not a change) mate deleteDeal FORBIDDEN (not the owner) owner updateDeal(ownerId: <mate>) ok mate deleteDeal ok (mate owns it now)
Published moves one way#
- Lang
- EDN
:published {:type :boolean :update [(before [?e :articles/published false])]}The rule runs only when published changes, so before false means
the move is false to true. Unpublishing is FORBIDDEN with
extensions.field "published".
The author may close but never reopen#
- Lang
- EDN
:tickets {:attrs {:title {:type :string} :closed {:type :boolean :update [(before [?e :tickets/closed false])]} :author {:type :ref :to :$users :required? true :default :auth/user}} :permissions {:view true :create [(authenticated? ?user) [?e :tickets/author ?user]] :update [[?e :tickets/author ?user]]}}
The author edits the ticket and closes it; nobody reopens it. The title
stays editable, because the field rule runs only when closed changes.
:transitions on an enum#
- Lang
- EDN
:stage {:type :enum :values [:open :won :lost :archived] :transitions {:open #{:won :lost} :won #{:archived} :lost #{:archived}}}
:transitions {from #{to ...}} lists the moves a write may make. It
compiles to a field :update rule (ANDed with the attribute's own
:update, when it has one):
- a listed move passes; any other change of the value is
FORBIDDENwithextensions.field "stage", and the message names the move (Not allowed: Deal.stage may not go from won to open); - setting the value it already has is not a move, so it always passes;
- a value that is not a key (
:archivedhere) is terminal; - a create may set any declared value: the transitions govern
updates only. To restrict where entities start, say so in
:create([?e :deals/stage :deals.stage/open]); - an optional enum with no value may be set to any value, as a create
may; clearing it (
null) is never a move, so it is refused.
Every value named must be in :values; :transitions on anything but
an enum is refused.
How field rules and before work#
- When a field rule runs: the write's own changes decide it. A
datom of that attribute on the entity asserted or retracted: setting,
changing or clearing the value, and
add<T><Ref>/remove<T><Ref>on a many-ref. Setting a value it already has (or adding a target that is already there) changes nothing, so the rule doesn't run. Creates and deletes don't run field:updaterules. - A failure is
FORBIDDENwithextensions.field, the input field (ownerId,tagIds,stage), and the clause that failed (Not allowed: Deal.ownerId's update rule fails at (before [?e :deals/owner ?user]); see the API's errors). For an anonymous caller, a rule that mentions?userisUNAUTHENTICATED, as for the entity's rules. beforegoes at the top level of an:updaterule. Its clauses read the state before the write; patterns, rule calls,not,orand the-joinforms inside it all do.(before (owner? ?e ?user))calls a named rule on the state before. Variables join across:(before [?e :deals/owner ?old]) [?e :deals/owner ?new] [(!= ?old ?new)].- Without
beforean:updaterule keeps its old meaning: it must hold on the entity before and after the write (so[[?e :tickets/closed true]]on its own would refuse closing: before the write it isn't closed). A rule withbeforeis checked once, over both states. - Refused at plan:
beforein:view,:create,:deleteor a field:view;beforeinsidebefore, or inside anor/not(put theorinsidebeforeinstead);beforein a named rule under:rules; abeforethat shares no variable with the rest of the rule (?eand?usercount); a field:updateor:transitionson an immutable attribute (it never changes). - Races: what a
beforeclause read is watched like any other read of a rule, so if the owner changes between the check and the commit, the write is decided again on the new data. /schema.graphqlshows a field's rule as@auth(update: "...")on the field; the plan lists changes to it under Permissions.
Writing rules: patterns that work#
- Owner plus members. Use a named rule with two branches, as
on-list?in named rules. - Children inherit from the parent. Follow the ref, then call the
parent's rule:
[(on-item-list? ?i ?u) [?i :items/list ?l] (on-list? ?l ?u)]. - Write as yourself.
:default :auth/userdoes it: the ref is pinned to the caller (see:default :auth/user). A create rule that checks the ref, such as(author? ?e ?user), is still a good second line, and the only one with:pinned? false. - Public, but only some rows. Use clauses that don't mention
?user, like[?e :news/stage :news.stage/published]. - Public rows and private rows in one entity: a top-level
or-joinwith a user-free branch. See Published or mine. - States and moves between them (closed, deleted, draft): see Patterns.
- Joining by code or invitation: a user can't add themself to a list
whose
:updaterule is owner-only. Model an invitation as its own etype that the invited user may create, or let the owner add members.
Published or mine#
Posts that anyone may read once published, while each author also sees their own drafts:
- Lang
- EDN
{:rules [[(author? ?e ?u) [?e :posts/author ?u]]] :entities {:$users {:permissions {:view [(or-join [?e ?user] (self? ?e ?user) (and [?p :posts/author ?e] [?p :posts/published true]))]}} :posts {:attrs {:title {:type :string :min 1 :max 200} :published {:type :boolean} :author {:type :ref :to :$users :required? true :default :auth/user :reverse :posts :view [(or-join [?e ?user] [?e :posts/published true] (author? ?e ?user))]}} :permissions {:view [(or-join [?e ?user] [?e :posts/published true] (author? ?e ?user))] :create [(authenticated? ?user) (author? ?e ?user)] :update [(author? ?e ?user)] :delete [(author? ?e ?user)]}}}}
The branches use different variables, so it is an or-join that names
?e ?user (a plain or is refused at plan). A signed-in caller gets the
whole rule: published, or theirs. An anonymous caller gets only the
branch without ?user: published. The :view on author follows the
same rule, so the author of a draft (and its createdBy) stays hidden.
:create starts with (authenticated? ?user) outside any or, so
anonymous callers can't create posts. Users are closed by default (each
sees only themself), so the $users rule opens the authors of published
posts to everyone: without it, author would be null for everyone but
the author.
Alice created "Hello world" (published) and "Draft". The query
{ posts(first: 10) { items { title published author { id } } } }
gives:
- Lang
- Text
anonymous: {"posts":{"items":[{"title":"Hello world","published":true,"author":{"id":"2bbb08a2-..."}}]}} alice: {"posts":{"items":[{"title":"Hello world","published":true,"author":{"id":"2bbb08a2-..."}}, {"title":"Draft","published":false,"author":{"id":"2bbb08a2-..."}}]}} bob: {"posts":{"items":[{"title":"Hello world","published":true,"author":{"id":"2bbb08a2-..."}}]}}
An anonymous createPost gets UNAUTHENTICATED. An anonymous live
query on posts gets a push when Alice publishes her draft.
Anonymous callers never run a branch that mentions ?user, so a not
or not-join over the user can't let them through: in
(or-join [?e ?user] [?e :posts/published true] (not [?e :posts/author ?user]))
an anonymous caller is held to [?e :posts/published true] only.