Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

State machines

aggregates.yaml declares what a bucket’s records may be and how they move. It is the one file that decides what is possible; the pages only decide who presses what.

aggregates:
  - bucket: applications
    initial: open
    states:
      open:        { event: received }
      incomplete:  { event: incomplete }
      complete:    { event: complete }
      on_hearing:  { event: on_hearing }
      recommended: { event: recommended }
      approved:    { event: approved }
      refused:     { event: refused }
      withdrawn:   { event: withdrawn }
    transitions:
      open:        [incomplete, complete, withdrawn]
      incomplete:  [complete, withdrawn]
      complete:    [incomplete, on_hearing, refused, withdrawn]
      on_hearing:  [incomplete, recommended, refused, withdrawn]
      recommended: [approved, refused, withdrawn]

transitions is an arbitrary directed graph. Cycles are allowed and are often the honest shape: a case sent back for the drawing it was missing returns to a stage it was already past. A good ending may sit partway along — an authority that changes its own decision finishes the case without walking to the end of the line.

On a desk, each record shows its state and a button for every move the graph allows from there. Here, the counter of the machine-hire example, with one hire out with its customer and one waiting to be handed over:

Each state’s event string is the name written into the log, and must be unique within the bucket. A record’s state is replayed from its own events, so renaming an event orphans the records that carry the old name: when rebuilding a live site, keep the names it already has.

What a state may carry

Beside its event, a state may say what happens when a record arrives in it: a mail, a group granted or taken back, a move after a while, a payment asked for, something handed on to a program, a line in the books, and the words a list shows.

mail

      approved:
        event: approved
        mail:
          to: submitter            # or one fixed address
          subject: "Your application"
          body: |
            Hello,

            {property_address} is approved. The decision is at
            {site}/status/{chain}.

{field} is any field of the record, plus {site}, {chain}, {email}, {bucket}, {state} and {link} - the page where the reader acts on the record, their own or the desk’s (every variable is in Mail). The body is markdown; it is sent as text with an HTML alternative. to: submitter means the record’s email field, and the lint then requires every form filling that bucket to collect a required email.

A record that belongs to another (a type: record field, say notice) can write to that record’s people: to: "{notice.email}" goes to whoever posted the notice, and {notice.what} in the body is what they posted. The lint requires every form filling the bucket to carry that field. This is how an answer to a notice on a board reaches the neighbour who put it there, without anyone in between.

Portal renders it in the same write as the move, and gdo delivers it; a reply comes back as a note beside the record. A note never moves a case.

A mail about a time carries the time, for the reader’s calendar:

        mail:
          to: submitter
          subject: "Your visit"
          body: "See you on {day}."
          event:
            start: day                # a `type: date` or `type: datetime-local` field
            end: until                # optional; an hour after a time, the day of a date
            title: "Visit, {name}"    # optional; the subject when left out
            location: "{where}"       # optional

start and end name fields of the record, read as the form sent them, in the site’s timezone; title and location take the mail’s variables. The lint wants every form filling the bucket to collect start required, and end where it is named, as a date or a date and time. Portal puts the event on the mail and gdo decides how it reaches a calendar: as an invite the reader’s mail client offers to add, and onto a calendar of the site’s own when gdo has one (see Mail). The same record entering the same state again updates the entry rather than adding a second.

grants

      approved:
        event: approved
        grants: approved_firms

The person the record is about becomes a member of that group when the record arrives here. An approval that means membership should not also need somebody to remember to invite them afterwards.

The lint requires every form filling that bucket to collect a required name (or navn) and a required email (or epost) of type email, because by the time a desk presses approve there is nobody left to ask. (An invite: on a form asks less: a required name, and a required email or, with a group, phone. See Content reference.)

A grant goes the way an invite does, through the same call. With Kanidm as the people backend it makes the account and adds to the Kanidm group. With memberships it writes a record in portal_memberships, and a Kanidm configured beside memberships makes the account too, with the one-time link in the mail (see Memberships). There a phone number on an older record does as well as an address; through Kanidm it does not. An instance with neither configured grants nothing and says so in the log; the transition itself always stands.

A state may grant several groups (grants: [committees, committees_{key}_member]), and a group may have a gap a record fills (groups): committees_{key}_member is that group of the record this one belongs to, or of this record itself when its bucket has groups:; committees_{committee}_member fills the gap from the field committee. Such a group is granted only while the record it is of is open. The person is the record’s own, or the one in the fields a grant names:

      active:
        event: active
        grants:
        - { group: "committees_{key}_lead", email: lead_email, name: lead }
        - { group: "committees_{key}_member", email: lead_email, name: lead }

revokes takes a gap the same way.

revokes

      left:
        event: left
        revokes: members

The mirror of grants: the person the record is about is taken out of that group when the record arrives here. A household that leaves, or a year’s dues nobody paid, is a decision that means the membership is over, and it should not also need somebody to remember to remove them. A state grants a group or revokes it, not both.

The lint requires every form filling that bucket to collect a required phone or email, since a membership is known by one of those. With memberships the record moves to removed and stays, so a desk sees who was in and may put them back; through Kanidm the person is taken out of the group by address, and a record with a phone number alone is said in the log and left. Best-effort, like the grant: the transition stands either way.

after

      on_hearing:
        event: on_hearing
        after: { days: 42, to: recommended }

The move a clock makes rather than a person. A hearing that gets no answer in six weeks has to go on without one, and nobody in the building is in a position to press that button.

A deadline may only do what a person could have done: after.to is held to the same declared edge as a desk button, and content that says otherwise is refused when it loads, not when the hour comes round. The wait is measured from the record’s last move. The move goes through the same transition path, fires the same mail, and is announced like any decision, stamped deadline.

The unit is days and the sweep is hourly. This is a deadline, not a job queue.

payment

      awaiting_payment:
        event: awaiting_payment
        payment:
          amount: 250                   # whole kroner; or { field: amount }
          text: Annual dues
          then: paid                    # where the record goes once it is paid
          expires: 30 days         # optional; the request lapses after
          by_hand: true                 # the treasurer marks it paid; no money service
      paid:
        event: paid
        grants: members

Entering the state asks for money. Once it is paid, portal moves the record to then itself, stamped payment:<reference>, with whatever then carries (a mail, a grant), as if a desk had pressed the button. It asks however the record arrived (a form, a desk, a clock), so a record that comes round owes again each round. A request nobody answers in expires days lapses, and nothing else happens.

Each payment is a record in the built-in portal_payments bucket: reference (what the bank sees), owner (bucket:id), amount and currency (minor units, NOK unless said), text, phone, email, provider, psp (the provider’s id) and by (bucket:state). It goes requested, then paid or registered (paid some other way), or failed, expired or refunded. The amount is fixed when asked; a later change to the field changes nothing. A record with no amount, or neither a phone number nor an address, is asked nothing, and the log says why.

By hand (by_hand: true, required without a money service), a desk that lists portal_payments marks a payment registered, in the treasurer’s name. The other states are the money service’s to say.

With a money service, the site names PAY_URL (Operations) and leaves by_hand out. The request waits in the payments outbox for kron, which takes it over dhd/1 and pushes it to the person’s app by phone number (Vipps), or gives a card link (Stripe), then says back what became of it. Portal picks the provider as it asks: Vipps for a Norwegian mobile number, else Stripe, else whichever service there is. A word about an unknown payment, or with another amount or currency, is refused and logged; a word said twice is one event.

{payment_url} in the paying state’s mail: is the link to pay: the service’s link, or the person’s own page where the request went to their app or is paid by hand. With a service, that mail goes once the request is out.

The person’s own page (one with a self_transition on the bucket) is where they land after paying, and shows the latest payment: waiting, paid, refunded, refused or run out. After expired or failed a button there asks again, under the next reference. Nobody is asked twice for one payment any other way.

The lint wants then to be a declared move from the paying state, every form filling the bucket to collect a required phone or email, and { field } to be a required type: money field. The move into then is portal’s: a desk button, an own link or a clock into it is refused, and so is a desk naming a state that is not registered, or {payment_url} on a state with no payment:.

post

A record entering a state can be handed on: read through a template and given to a program beside the site, which answers, and the answer moves the record. A case sorted by a model, a filing sent to an authority, a letter typeset: each is the same three lines.

cases:
  states:
    received:
      event: received
      post:
        sort:                               # a step, by a name of yours
          template: triage.txt              # templates/triage.txt in the repo
          to: { service: scribe }           # a program beside the site
      then: { ok: sorted, refused: needs_a_person }
{# templates/triage.txt #}
Say which desk this is for, from {{ me.fields.name }}: {{ me.fields.text }}
  • post: is a map of named steps. Each renders its template over a reading and hands the rendering on, once per record and state.

  • read: says what the template sees, by names of yours; left out, it is the record as me (id, bucket, state, fields, at). An entry is one of:

    • { record: true }, the record itself;
    • { source: { bucket: <bucket> } }, other records, with states:, where: { field, equals }, since: and limit:;
    • { events: <bucket> }, what happened there (each event’s record, event, at and payload), with where:, since: 3 months and limit:. A sum over a month is read from here, since it is over what happened and not what is.

    {field}, {id} and {bucket} in a where are the record’s own, never a visitor’s. A reading gives the newest first, 500 unless limit: says (5000 at most), and is kept on the request, so how a number came to be can be shown. What a step reads is sent to the program it names: read what it needs.

  • template is a file under templates/ in the content repo, ending in .txt, .json, .xml, .html or .csv, with {{ }} over the reading. It reaches nothing outside the reading, and a name the reading lacks fails the step rather than leave a hole.

  • to is { service: <name> }, a program beside the site, or { credential: <name> }, a credential a courier holds. Content names it; where it leads, with which model or key, is the deploy’s (Operations). An address or a key in content fails the lint.

  • after: [<step>] makes a step wait: it is handed on once each step it names has answered ok, with their answers in its reading as steps.<name> (state, words, reference, object). A step whose wait was refused is never handed on. Steps with nothing between them go at once.

  • takes: [<field>] lets the answer write on the record: only the fields named, only with ok, only text, a number or true/false, written with the move the answers make and logged as the program’s. A supplier’s price, a model’s category. It is never a field a form asks a person for, so an answer cannot write over what someone typed, and a list may show: it like any field.

  • then, beside post:, moves the record once every step has answered ok, or once one was refused. Each must be a declared move from the state. Left out, the record stays and the answers are kept.

Every step is a case of its own in portal_posts (requested, then ok, refused or failed), which a desk may list like any bucket: that is where a filing nobody has taken shows. The program’s words are kept as a note on the record, where a mail’s reply lands, and its name, version and the rules it applied are on the step, so “why did this go to a person” has an answer. A failed step waits for the program to try again; no answer never counts as yes.

The lint holds a post: to what it can check without the program: the template is there and reads as a template, to says one destination by name, and then names real moves.

Not yet built of the design (#119): a gate that asks before the move, jq on a reading, .typ templates and to: { mail }.

ledger

      paid:
        event: paid
        grants: members
        ledger:
          from: "member:{id}"            # the account value leaves
          to: "dues:{year}"              # the account it lands in
          amount: { field: amount }      # kroner, from the record; or a number
          text: "Dues {year}"            # the statement line

A ledger beside the log. Entering a state with ledger: posts: value moves from one account to another, in an amount the record says, and the posting is written on the move’s own event, so the log says what was posted then and a later change to the content changes nothing already posted. Portal keeps the postings as balances and statement lines a page reads with source: { kind: ledger } (Content reference). Portal never refuses a move because of a balance: a balance is shown where the content asks for it, and the people at the desk decide.

Accounts are names the content makes up: lowercase letters, digits, :, /, ., -, _. {id} is the record’s id, {year} the year of the move in the site’s zone, {bucket} and {state} are what they say, and {<field>} is a field of the record, lowercased. A name with no placeholder is one account for the whole site; dues:2026 is what every household paid that year, member:<id> is one household over every year. The chart of accounts is whatever names the content uses; the lint holds them to the shape, and holds every form filing into the bucket to collecting the fields a posting reads.

Amounts are a number of whole units, { field: amount } a required type: money or type: number field of the record, { field: count, times: price } the product of two, or payment, what the bucket’s payment: state asks for. On the wire and in the balances they are hundredths of the unit, øre for kroner. A field that is missing or not a number leaves that posting out, said in the log; the move itself always goes.

Units. NOK unless said. A unit is letters, one to eight: a currency by its three capitals (NOK, EUR), or a count (pcs, hours, seats). Two accounts in different units never meet in one posting, and a balance is read in its unit. One state may post kroner and another pieces on the same bucket; that is how stock is counted and costed by the same movement.

In bookkeeping’s words, from is the account credited and to the account debited. An account’s balance is what landed in it less what left, debits - credits: positive for stock on the shelf and for dues that have arrived, negative for a member’s own account once they have paid. The wire (dhd::ledger) spells the two sides credit and debit.

Several postings on one state are a list, and all of them post or none do. A bucket’s own ledger posts on every move without naming states:

  - bucket: invoices
    ledger: { amount: { field: amount } }

Each move posts the record’s amount from the account of the state it left to the account of the state it entered, invoices:sent to invoices:paid; a first arrival posts from invoices:_new. Each state is then an account and its balance is how much sits there: what is invoiced and not paid is the balance of invoices:sent. A state may carry its own postings beside the bucket’s for money that crosses buckets or years.

No deletes, no edits. A mistake is a reversing posting with a reason, as in bookkeeping: a form into a bucket of its own whose state posts from and to the fields the form asks for, so a correction has a form, a reason and a person. The ledger can always be built again from the log (portal ledger rebuild), and nothing else.

Accounting of all sorts, in content

The same key says each of these; the accounts and units differ.

Dues, once a year. Who paid this year, and what one household has paid over the years:

      paid:
        event: paid
        ledger: { from: "member:{id}", to: "dues:{year}", amount: 250, text: "Dues {year}" }

The treasurer reads dues:2026 for the year’s total, and a household’s page reads the statement of member:{key}.

Invoices and what is outstanding. A bucket’s own ledger over the order’s states:

  - bucket: orders
    ledger: { amount: { field: price } }

orders:invoiced is what is invoiced and unpaid, and orders:paid is the year’s takings; a cancelled order sits in orders:cancelled and never in revenue.

Stock, counted and costed. One movement record, two states, two units:

  - bucket: movements
    states:
      booked:
        event: booked
        ledger: { from: "stock:{sku}", to: "used:{order}", amount: { field: count }, unit: pcs }
      costed:
        event: costed
        ledger: { from: inventory, to: "order:{order}", amount: { field: count, times: price }, unit: NOK }

stock:<sku> in pcs is what is on the shelf; order:<id> in kroner is what the job cost in parts. A count is a movement whose from is counted and whose amount is the difference, so the shelf and the books meet. Receiving goods posts from supplier:{supplier} to stock:{sku}.

Payroll, for the a-melding. A payslip’s payout posts gross and tax in one go:

      paid_out:
        event: paid_out
        ledger:
          - { from: "wages:{period}", to: "employee:{id}", amount: { field: gross }, text: "Gross {period}" }
          - { from: "employee:{id}", to: "withholding:{period}", amount: { field: tax }, text: "Withholding {period}" }

wages:2026-11 is the period’s gross wage bill, withholding:2026-11 what is owed the tax office, and employee:<id> the net each person was paid. Those three numbers are the a-melding’s.

Hours. Approved time in a unit of its own:

      approved:
        event: approved
        ledger: { from: "hours:{id}", to: "hours:approved:{period}", amount: { field: hours }, unit: hours }

Seats. A board’s places are a count too. ledger: { amount: 1, unit: seats } on the places bucket makes places:taken how many seats the season gave, and the waiting list a balance of places:waiting.

A deposit held and returned. Two states, the second reversing the first:

      deposit_received: { event: deposit_received, ledger: { from: "customer:{id}", to: deposits, amount: { field: deposit } } }
      deposit_returned: { event: deposit_returned, ledger: { from: deposits, to: "customer:{id}", amount: { field: deposit } } }

deposits is what the firm holds for customers at any moment.

Closing a year. There is no year-end in the ledger; a closing is a posting like any other, from dues:2026 to equity, made by a desk’s form into a corrections bucket whose one state posts from and to the fields the form asks for, with a reason. The statement then shows who closed the year and why.

leaves_after

      taken_down:
        event: taken_down
        leaves_after: { minutes: 10 }

How long a record stays in its bucket’s lists once it has entered the state, when that is not for ever. A card taken off the front page leaves the desk’s list ten minutes later instead of standing there greyed out, and the ten minutes are the time to see what was just done. Days, hours and minutes add up, and a sweep takes records out once a minute. Nothing is decided and no mail goes. The record leaves the lists, and the event log keeps it.

text

      certificate_in:
        event: certificate_in
        text: Certificate received

The state in the site’s own words. A desk’s row and a list show it where they would otherwise show the id (certificate_in, open), and the row’s fields are headed by the labels of the form that files into the bucket rather than by their stored names. Optional: without it a row shows the id made readable, and the first state is “Open”, or “Mottatt” on a Norwegian site. bratac build writes it from the plan’s stages_text.

What portal does with a bucket

Five keys beside states hand a bucket to portal for work nobody presses a button for: a schedule that opens records, one record that comes round, a notice mailed to everyone it concerns, room for a number of people, and the places taken. Each is optional and changes nothing for a bucket without it.

recurs

  - bucket: inspections
    initial: due
    states:
      due: { event: due, after: { days: 21, to: overdue } }
      overdue: { event: overdue }
      done: { event: done }
    transitions:
      due: [done, overdue]
      overdue: [done]
    recurs:
      - id: fire-doors
        every: 6 months               # or 8 weeks, 2 years
        starting: 2026-11-01          # the first due date
        lead: 14 days                 # open it two weeks ahead
        handled_by: caretakers        # whose desk works these
        fields: { what: Fire door inspection }

A length of time is written as people say it, wherever one is taken: every: 6 months, lead: 14 days, shows: 3 weeks, expires: 30 days, an event’s duration: 3h 30m, a reading’s since: 3 months. ISO 8601 works too (P14D). Days and weeks count in days, months and years in months, so a series every month lands on the same day of each month and the 31st becomes the last day of a shorter one. lead, shows and expires count in whole days.

A series may say which dates it falls on instead of counting from starting. every can then be left out: a date in the year comes yearly, a weekday of the month monthly (every: 2 years with a starting skips every other).

      - { id: workday, on: first saturday of june, handled_by: caretakers }
      - { id: winter, on: last sunday of january, handled_by: caretakers }
      - { id: meeting, on: first monday of every month, at: "18:00", handled_by: caretakers }
      - { id: advent, on: fourth sunday before 25 december, handled_by: caretakers }   # the first in Advent
      - { id: summer, on: 21 june, handled_by: caretakers }

nth is 1 to 4, or last: not every month has a fifth Sunday, and the lint refuses one, as it does 30 February and 29 February, which three years in four do not have. before counts back from a day, not including it. These dates are on the site’s own calendar, in its timezone:. at: "18:00" gives the fields {due_at}, 2027-01-04T18:00. The map and the manual say it in words. every: 1 year also works with starting, as months do. With neither starting nor anything else to go on, a series with on starts from the day it first runs, and opens nothing for a date already gone. next: after_done does not go with on.

Once a minute portal opens the record that has fallen due: an ordinary record in the bucket’s first state, with the series’ fields (each a template), due (the day it is due) and the series as where it came from. The first state’s mail goes, and its answer is stamped schedule. Overdue is the clock that already exists, after: on the first state, counted from when the record was opened.

next: after_done waits for the one before to reach a done state (the bucket’s final states unless done: names them) and makes the next due every after that. for_each: { group: volunteers } keeps one series per member, first due every after they joined (and not before starting, if given); for_each: { bucket: b, states: [...] } one per record there, with link_as naming the field that points back at it. where: narrows those records as it narrows a list’s, so each kind of thing can have its own series:

      - id: service
        every: 6 months
        for_each:
          bucket: machines
          states: [running, in_the_workshop]
          where: { field: type, none_of: [Trailer, Scaffold] }
        link_as: machine
        handled_by: workshop
        fields: { what: Service, check: "Engine, oil and filters, hoses and tracks" }
      - id: trailer
        every: 1 year
        for_each:
          bucket: machines
          states: [running, in_the_workshop]
          where: { field: type, equals: Trailer }
        link_as: machine
        handled_by: workshop
        fields: { what: Trailer check, check: "Brakes, lights, tyres and coupling" }

The lint holds where to a field the bucket’s forms have, and to its choices where they offer choices, so a misspelt value is refused rather than matching nothing. A record that stops passing gets no new one, and the one it has stays open, as when it leaves states. Templates may use {due}, and a member’s {name}, {email} and {phone}, or every field of a record and its {id}.

A record is opened once. Its id is made from the series and its due day (or the record before it), and the event log refuses to make an id twice, so a second pass, a second instance or a restart opens nothing new; where each series has got to is kept in portal_recurring. After a long stop a series opens the latest one due, not every one it missed. The lint refuses a series no desk works: a list of the bucket with transitions under requires_group: <handled_by> must exist.

comes_round

  - bucket: events
    initial: resting
    states:
      resting: { event: resting, text: Until next time }
      out: { event: out, text: Coming up }
    transitions:
      resting: [out]
      out: [resting]
    comes_round:
      date: day             # the field holding this time's date
      on: fourth sunday before 25 december
      at: "17:00"           # the site's timezone
      shows: 21 days   # goes out this long before
      out: out
      back: resting         # returns here when the date has passed

recurs: opens a new record each time, so last year’s text and picture are done again. comes_round: keeps one. Once a minute, a record resting in back moves to out shows days before its date, with the date written into the field (a type: date field holds the day; another the day and at), and back when the date has passed: at at, or with none, when the day is over, on the site’s clock. The moves are ordinary moves, stamped comes_round: the state’s mail goes, and both must be declared. on takes what recurs takes.

Change it at any time, in either state, with edit:, and the change carries over. A date someone sets by hand, still to come, goes before the rule, the year it is moved a week. A person may take it in early with a button of their own; it does not go out again for that date. Portal keeps which date has been out and which year has been asked for in portal_comes_round, so a second pass, a second instance or a restart does nothing new.

Not every date repeats, and then there is no on:

    comes_round:
      date: day
      shows: 14 days
      out: out
      back: resting
      asks: { month: 3, day: 1 }   # the day each year to ask
      handled_by: editors          # who is asked, and may set it

On asks the group’s members are mailed, once a year, with the way to the form; the desk’s row says “Needs a date” and comes first; the log says it asked. It goes out only when someone sets a date. If nobody answers, nothing goes out, so nothing wrong does. A record first seen after this year’s asks is not asked about a season under way. The lint wants a form with the date field in it, and for handled_by a list of the bucket with edit: for that group.

belongs_to and owner

  - bucket: documents
    belongs_to: { bucket: committees, field: committee }   # or belongs_to: committees
    owner: board                                           # a record with no parent

A record of this bucket is another bucket’s record’s, or a named group’s. It says whose in one field (field; the bucket’s own name when belongs_to is only a name): its parent’s key, or the owner’s name, which portal fills in when a form leaves the field empty. A submission and a save are held to it: the parent must be there, or it is the owner. So a [key] page lists a committee’s own with where: { field: committee, equals: "{key}" }, and a page of the board’s the board’s with equals: board, and nothing else is needed. A form files one with a type: record field of: committees, or type: hidden with value: "{key}", and without an owner the lint wants one of those.

The relation only reads. Closing a parent is a state it stays in, and hides nothing: its children are in their own bucket, and their lists do not ask after the parent. So the lint refuses leaves_after on a state of a bucket others belong to, which would take the parent out of its lists. The map and the manual say it in words.

groups

  - bucket: committees
    groups:
      key: short_name            # the field a new record's short name, its key, comes from
      label: name              # what a person reads as its name
      while: [active]           # the groups exist in these states (default: the initial)
      member: { label: "{label}" }
      lead: { manages: [member, lead], label: "{label}, leads" }

Each record of a bucket with groups: has groups of its own, named <bucket>_<key>_<name>: committees_traffic_lead. That one name is the group in Kanidm or Rauthy (both take it), the name in the sign-in token’s groups claim, and the group’s room in the chat. Bucket names, keys and group names are slugs with no _, so a name reads back. A key is 2 to 40, so every name fits the providers’ 64; the lint works the longest out. A record kept under a longer key, such as a hash, has no groups.

Content names such a group with a gap. On a [key] page, in qualifies, requires_group and invite.group, committees_{key}_member is that group of the record the address names (quote it inside { }). A desk for it moves the records its group is of, so its bucket has groups: or belongs_to one that has; such a list offers no edit yet. In grants and revokes the gap is filled from the record (grants). A name with a gap stands nowhere else, and is never a group anyone holds. See access.

A new record filed by a form is kept under its short name: the key field made a slug, refused when it cannot be a key or is taken.

Open and closed. A record entering a while state has its groups made where the groups are kept (Rauthy, Kanidm, or nothing to make with memberships), and in Rauthy, for a group that manages others, the admin roles that go with it: rauthy_admin:<bucket>_<key>_<name> per managed group, or rauthy_admin:<bucket>_<key>_* when it manages them all. Anyone put in that group, by a grant or an invite, gets them, and loses them when taken out; they let a person bring people in and take them out in Rauthy’s admin, for that record’s groups only. Entering any other state empties every group and takes the admin roles back; the groups stay, empty. At start and on each reload every open record’s groups and roles are made, so records from before groups: (or brought in by portal import) have them too. Best-effort, as grants is.

owned_by and shared_with

  - bucket: courses
    owned_by: sender                              # the signed-in person who files it
    shared_with: { group: guides, while: [open] } # who else, and for how long
    states:
      open:  { event: received, after: { days: 84, to: ended } }
      ended: { event: ended }
    transitions:
      open: [ended]
  - bucket: notes
    belongs_to: { bucket: courses, field: course }  # the owner's too

A record of a bucket that says owned_by: sender is the person’s who filed it. The site writes their subject on the record, in the field owner, from the session: a form cannot name it, and where the form carries an email the session’s address is written there as well. Nobody signed in files one from a browser. Only the owner sees the record, whatever page lists it and whoever that page is for.

shared_with shares it: the group sees the record, moves it from its desk and talks with its owner while the record is in one of the states while names (the initial state unless said). A share is as long as the states say. It ends when a move takes the record out of them, whoever makes it: the owner by their own link (self_transition), the group’s desk, or a clock (after:), which is what makes it a share for a while. The record’s log is the log of the share, and moving it back is sharing it again. A desk moves an owned record only from a state the share holds in.

A bucket that belongs_to an owned one is its owner’s too, one step down: a record of it is seen, and filed, by whoever sees the record it belongs to as that record stands now. The lint refuses a second step, owned_by beside belongs_to or groups, a form field named owner, and an invite: filing into an owned bucket.

A list over an owned bucket needs neither public nor requires_group: anyone may ask for it and is shown what is theirs or shared with them, record by record. A list that names a group is still only that group’s, and still shows each member only what is shared. The record’s conversation in the chat goes by the same answer (rooms), so a person in no group at all talks with the group their record is shared with, and with nobody else.

This is the plain way to give one person’s records to the people who help them. groups: (below) is for records that are a body of people in their own right, a committee with members and leads.

notice

  - bucket: notices
    initial: draft
    states:
      draft: { event: draft }
      sending: { event: sending }
      sent: { event: sent }
    transitions:
      draft: [sending]
      sending: [sent]
    notice:
      sends_in: sending          # the initial state when left out
      sent: sent
      mandatory: true            # no way to stop it
      archive: true              # a public list of the bucket is allowed
      per_minute: 60
      to:
        - { id: everyone, label: every resident, bucket: residents, states: [living_here] }
        - { id: block, label: the block, bucket: residents, states: [living_here], where: { field: block, equals: "{block}" } }
        - { id: board, label: the board, group: board }

A notice that reaches sends_in (by a desk’s button, or by arriving, when that is the first state) is mailed to everyone in its audience: a group’s members (invited or active) or everyone with a record in those states, narrowed by where, whose equals may name the notice’s own fields. A field with several choices holds each of them, on the notice’s side as on the record’s, and any_of: [a, b] in place of equals takes any of several. One message per person, to that person alone. With more than one audience the form chooses one in a required select audience. The notice needs a required subject and text (and may have starts and ends, which the mail gives in words), unless mail: { subject, body } says what to send.

When everyone has it, portal moves the notice to sent with recipients, the count. Without mandatory, each message ends with the person’s own link to stop that bucket’s notices; with it, the message says it goes to everyone it concerns. The lint holds every form that writes a notice to qualifies, refuses an own link into sends_in and any button into sent, and allows a public list of the bucket only with archive: true.

holds

A record can keep something busy over days a person chooses: a hire its machine from its first day to its last, a booking its cabin, a service its machine and the mechanic who does it. holds: on the bucket says what, from which day until which, and in which states:

  - bucket: hires
    initial: confirmed
    states:
      confirmed: { event: confirmed, text: Confirmed }
      out: { event: out, text: Out with the customer }
      returned: { event: returned, text: Returned }
      cancelled: { event: cancelled, text: Cancelled }
    transitions:
      confirmed: [out, cancelled]
      out: [returned]
    holds: { what: machine, from: from, until: until, while: [confirmed, out] }
  • what is a field naming what is held: a required type: record field of: the bucket of the things (here of: machines), on every form that records into the bucket. With multiple: true the record holds each thing it names, and a type: collection field holds every record gathered in it.
  • from is a required type: date field, the first day held, and until the last, which counts. Or say for instead of until: a required type: duration field in days or weeks (units: [days, weeks]), so a form asks “first day” and “how long” and the last day follows.
  • while is the states in which the record holds it. Outside them it holds nothing.

A record holds what it names from the moment it enters a while state, in the same write as the move, and lets go the moment it leaves: a hire returned early frees the rest of its days at once, and a hire moved to other days moves its hold. One thing has one holder on any day, whichever bucket holds it: a bucket of services that holds the same machines refuses a service planned over a hire’s days, and the hire over a service’s. A submission or a move that would hold a thing someone else holds on any of its days is refused with nothing written, and the person is told so in words; so is a last day before the first.

A record can hold several kinds of thing; holds: then takes a list:

  - bucket: services
    initial: planned
    states:
      planned: { event: planned }
      done: { event: done }
    transitions:
      planned: [done]
    holds:
      - { what: machine, from: from, until: until, while: [planned] }
      - { what: mechanic, from: from, until: until, while: [planned] }

No bucket’s holds go before another’s: an urgent repair over a booking is a desk cancelling the hire, or moving it to another machine, and then planning the service. A list of the things can be narrowed to the ones free on a visitor’s days, and a booking made by picking one (see the content reference).

holds: is for a thing held over days a person chooses; board: and places: below are for a number of seats at a fixed time.

board and places

  - bucket: shifts
    initial: open
    states: { open: { event: posted }, full: { event: full }, cancelled: { event: cancelled } }
    transitions: { open: [full, cancelled], full: [open, cancelled] }
    board:
      capacity: places           # a field of the record, or a number
      full: full                 # portal moves open <-> full
      starts: start
      ends: end                  # or duration: 4h
      summary: what
      location: where
      needs: [{ field: has_key, label: Someone with a key, at_least: 1 }]
      plan: public               # who may subscribe to /ics/shifts.ics
  - bucket: shift_places
    initial: waiting
    states: { waiting: { event: waiting }, taken: { event: taken }, withdrawn: { event: withdrawn } }
    transitions: { waiting: [taken, withdrawn], taken: [withdrawn] }
    places: { on: shifts, slot: shift, taken: taken, waitlist: true }

A form recording into the places bucket takes a place on the thing its slot field (type: record, of: the board) names. Before anything is written, portal puts the place in the board’s ledger, which is written only over the revision it was read at: a thing never holds more than its capacity, and one person (by address, phone or account) never holds two places on it, however many arrive at once. Places are seated in the order they came; the last free places are kept for someone who meets a need still missing. A seated place moves from the first state to taken (stamped board, with that state’s mail); without room it waits there, or with waitlist: false it is refused, with words saying why. When a place leaves taken or the line (an own link, a desk), the next that fits moves up; the thing moves to full and back as it fills and frees.

A place that is decided on and still counts says so in keeps: a tender that takes three quotes (places: { on: tenders, slot: tender, taken: received, keeps: [chosen, not_chosen] }) keeps all three seats when the board chooses one and turns the others down, so the decision does not open the tender to a fourth. A quote withdrawn (not kept) still gives its seat up. Each state in keeps must be declared, and neither the first state nor taken. words: { places: quotes, full: Enough quotes } on the board: says what its places are called, and place: what one is, for a board of one (Content reference).

A place may count for more than one seat: places: { ..., count: people, at_most: 4 } names a type: number field on the form (empty counts 1; below 1 or above at_most is refused at submit, and the lint requires at_most), the ledger sums counts against capacity, a place moves up only whole (a smaller one later in line may pass one that does not fit; nothing else changes in the order), and count is refused on a board with needs, since a counted place meeting a need is not defined yet.

A desk may change a place (edit: on a list over the places bucket, see Content reference): the ledger first takes what the record will say, who it is for, what it meets and how many it counts for, keeping when the place came. A waiting place keeps its turn and moves up if it fits now. A seated place keeps its seat; it may count for more only where a place of that size would be seated (room for it, and what is kept for a need still missing left alone), and is refused otherwise. What a place gives back goes to the next in line. A place never moves to another thing this way. A record that holds no place (given up) changes in its log only.

Portal makes those moves and nobody else: the lint refuses a desk button, an own link or a clock into taken or into full, and a board no form can take a place on.

Moves portal makes

after gives a move to a clock; these give moves to portal: a place seated (initial -> taken), a board’s thing full and open again, a notice sent, a paid record moved to its then. Like a clock’s, they go through the same event log and fire the same mail, and the needs check and the map count them.

attended_by

  - bucket: newsletter
    initial: open
    states: { open: { event: received } }
    attended_by: n8n newsletter compose

Names who reads a bucket when no page does. The lint refuses a bucket that a form fills and nothing attends, so no answer is ever sent where nobody looks.

fields

  - bucket: portal_asks
    fields: [name, asker, asker_id, via, ask, to, question, seal_to, alternative, answer, answered_by, words]

The fields portal itself writes on a bucket’s records, when no form fills it. A list’s title: and show: are held to a form’s fields; where there is no form, they are held to these. The built-in portal_payments and portal_asks declare theirs; a content repo’s own bucket has no reason to, since a form says what its records carry.

Who moves what

Nothing in this file says who. A move becomes possible for somebody when a page offers it:

  • a desk resource’s transitions gives it to that resource’s requires_group;
  • an alternative’s self_transition gives it to the person who sent the record, by their link and their email, from the states its from names;
  • a state’s after gives it to the clock;
  • board, places, notice and payment give their own moves to portal.

All of them compile into the same access policy, and the engine refuses anything the graph above does not declare, whoever asks.

Testing one

iris replay runs cases through the same code the running site uses, in a store in memory, and reports what was accepted and what refused.

iris replay --path questions --cases cases.jsonl

Each line of cases.jsonl is one case: a need, a record, and the states it walks. --store <file> runs them in a file instead, and --report-only --store <file> reads a site’s own store back (with the site stopped: the store opens in one process).