Phase 11, step 2: the journal's daily anchor by mail
CI / secret scan (push) Successful in 7s
CI / fmt, clippy, tests (push) Successful in 50s
CI / release (push) Canceled after 34s

Every day from 07:00 Chiang Mai time the app mails the journal's last
entry number and its hash to the addresses set on the Notifications page
(src/anchor.rs, migration 0012: settings, journal_anchors), when anything
was added since the last anchor that went out. A day without news is
noted without a mail; a failed send is tried again after an hour; a
transaction-level advisory lock keeps two runs from both sending. "Send
the anchor now" sends at once. Each mail says whether the chain checked
whole (in capitals when it did not) and links to /journal/anchor, which
compares a kept entry number and hash with the journal now: the same
hash, another one, or no such entry. Changing the recipients is itself a
journal entry. Every anchor mail is in the notifications log.

Tests: the daily rule (before seven, once a day, an hour after a
failure), recipients checked and journaled, one mail per recipient with
the head hash, unchanged days, by hand, the check page's three answers,
and a chain broken around the app said in the mail. 126 unit, 67
integration.
This commit is contained in:
grabowski committed 2026-11-22 23:02:20 +07:00
1 parent 94ad25b6fc
commit 72a4faf71a
14 files changed
+990 -22

No files matched your search

+31
View File
@@ -37,6 +37,37 @@
<p>A provider for text messages to Thai and foreign numbers is being chosen. Reminders go by email first.</p>
</section>
</div>
<section class="card" id="anchor">
<header><h2>The journal's daily anchor</h2>{% if anchor_to %}<span class="chip ok">on</span>{% else %}<span class="chip warn">nobody set</span>{% endif %}</header>
<p class="hint lead">Every day from {{ anchor_hour }}:00 Chiang Mai time, the journal's last entry number and its hash go by mail to the addresses below, when something was added since the last one. Kept outside the server, those mails show later that nobody rebuilt the journal. Each mail links to <a href="/journal/anchor">Check an anchor</a>.</p>
{% if anchor_done %}<p class="notice ok" role="status" id="anchor-done">{{ anchor_done }}</p>{% endif %}
<form method="post" action="/notifications/anchor-to" class="form" id="anchor-to-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<div class="grid">
{{ fm.text("anchor_to", "Send it to", anchor_to, err=anchor_error, cls="wide", ph="lead@example.com, notary@example.com", hint="Addresses outside this server, separated by commas: a partner, the firm's lead, an archive mailbox elsewhere. Changes go into the journal.") }}
</div>
<div class="formactions">
<button type="submit" class="btn" id="save-anchor-to">Save</button>
{% if mail and anchor_to %}<button type="submit" class="btn pri" id="anchor-now" formaction="/notifications/anchor-now">Send the anchor now</button>{% endif %}
</div>
</form>
{% if anchors %}
<div class="tblwrap">
<table class="tbl" id="anchor-log">
<thead><tr><th>Day</th><th>Entry and hash</th><th>How it went</th></tr></thead>
<tbody>
{% for a in anchors %}
<tr>
<td class="nowrap">{{ a.day }}<div class="sub">{{ a.how }}, {{ a.at }}</div></td>
<td><b>{{ a.seq }}</b> <span class="mono small" title="{{ a.hash }}">{{ a.hash[:16] }}…</span>{% if not a.whole %} <span class="chip bad">chain broken</span>{% endif %}</td>
<td><span class="chip {% if a.status == "sent" %}ok{% elif a.status == "unchanged" %}plain{% else %}bad{% endif %}">{{ a.status }}</span>{% if a.recipients %}<div class="sub">{{ a.recipients }}</div>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</section>
<h2 class="sechead" id="log">Log</h2>
{% if log %}
<div class="card flush">