The other side reviews a draft (phase 13, step 1)
CI / secret scan (push) Successful in 5s
CI / fmt, clippy, tests (push) Successful in 49s
CI / release (push) Skipped

A lawyer sends a contract version to one of its parties with a link. On
it the other side marks the text up in an editor that keeps every change
visible, as tracked changes do: deleting our text crosses it out in red,
typing is marked as added in green, and the highlighter marks a passage
in yellow with a comment. Restore and Undo take marks back. They send it
back once a round; each later version comes on the same link.

- Migration 0014: review_links (token kept as a SHA-256, one open link a
  party) and review_rounds (the reply written once: their pieces, text,
  SHA-256, name, message; a trigger refuses any other change and every
  delete). Journal entries "sent for review", "review returned" (with the
  fingerprint of their text) and "review link closed"; audit entity
  "review".
- The reply is a list of pieces (same, ins, del, mark). The server checks
  that the pieces without the added ones are exactly the version sent, so
  nothing changes unseen (reviews::check).
- Our review page: their message, the changes numbered with the words
  around them and a box each, the highlights with comments, a git-style
  diff (line numbers, - and + lines, the changed words marked, three lines
  of context per hunk) and their markup. "Take the ticked changes" opens
  the contract page with the version form filled with our text plus those
  changes.
- static/review-editor.js: edits work on the pieces and redraw, so our
  text cannot vanish; keyboard compositions and edits the browser will not
  cancel are compared with the text and taken as edits.
- Property tests (any markup is accepted and taken back exactly; markup
  that changes our text unseen is refused), the fuzz text target runs
  reviews::check, integration tests, and the demo has the label's review
  of the recording agreement.
- PLAN: phase 13.
This commit is contained in:
grabowski committed 2026-11-23 15:31:43 +07:00
1 parent ff716eb9d3
commit a4155548b8
24 files changed
+3004 -6

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
{#- A marked-up text: unchanged, added (green), crossed out (red), highlighted
(yellow, its comment on hover and after it); each change numbered. -#}
{% macro marked(shown, id="rv-marked") -%}
<div class="rvtext" id="{{ id }}">{% for p in shown %}{% if p.n %}<sup class="rvn" aria-label="change {{ p.n }}">{{ p.n }}</sup>{% endif %}{% if p.op == "ins" %}<ins>{{ p.text }}</ins>{% elif p.op == "del" %}<del>{{ p.text }}</del>{% elif p.op == "mark" %}<mark{% if p.comment %} title="{{ p.comment }}"{% endif %}>{{ p.text }}</mark>{% if p.comment %}<span class="rvc">{{ p.comment }}</span>{% endif %}{% else %}{{ p.text }}{% endif %}{% endfor %}</div>
{%- endmacro %}
+32
View File
@@ -74,6 +74,38 @@
</details>
<datalist id="roles">{% for r in roles %}<option value="{{ r }}"></option>{% endfor %}</datalist>
</section>
<section class="card" id="reviews">
<header><h2>Review by the other side</h2><span class="muted small">a link where a party marks up a version and sends it back</span></header>
{% for l in reviews %}
<div class="item{% if not l.open %} old{% endif %}" id="review-link-{{ l.id }}">
<div class="row"><b>{{ l.party }}</b><span class="muted small">{{ l.state }}</span>
{% if l.open %}<form method="post" action="/contracts/{{ id }}/review-links/{{ l.id }}/close" class="inline-form" data-confirm="Close {{ l.party }}'s review link? It stops working; sending again makes a new one."><input type="hidden" name="csrf" value="{{ csrf }}"><button type="submit" class="btn sm ghost">Close the link</button></form>{% endif %}
</div>
<ul class="rvrounds">
{% for r in l.rounds %}
<li id="round-{{ r.id }}">Version {{ r.version }} sent {{ r.sent }} by {{ r.by }}:
{% if r.replied %}<a href="/contracts/{{ id }}/reviews/{{ r.id }}">sent back {{ r.replied }}</a>, <span class="chip {% if r.changes %}warn{% else %}ok{% endif %}">{{ r.changes }} {% if r.changes == 1 %}change{% else %}changes{% endif %}</span>{% if r.highlights %} <span class="chip plain">{{ r.highlights }} {% if r.highlights == 1 %}highlight{% else %}highlights{% endif %}</span>{% endif %}
{% elif loop.first %}<span class="muted">waiting for them</span>{% else %}<span class="muted">not sent back; a newer version followed</span>{% endif %}</li>
{% endfor %}
</ul>
</div>
{% endfor %}
{% if live_parties and text_versions %}
<details class="addparty"{% if not reviews %} open{% endif %}>
<summary class="btn sm" id="send-review-open">Send a version for review</summary>
<form method="post" action="/contracts/{{ id }}/reviews" class="form" id="send-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<div class="grid">
{{ fm.select("review_party", "To", "", review_parties, req=true, blank="Choose the party") }}
{{ fm.select("review_version", "Version", text_versions[0][0], text_versions, req=true, blank="Choose") }}
{{ fm.area("review_message", "Message to them", "", rows=3, fcls="wide", hint="Optional: what to look at, by when.") }}
</div>
<div class="formactions"><button type="submit" class="btn pri" id="send-review">Send</button></div>
</form>
</details>
{% elif not live_parties %}<p class="empty-inline">Add the other party above to send them a version to review.</p>
{% else %}<p class="empty-inline">Add a version with a text to send it for review: the editor works on the text.</p>{% endif %}
</section>
{% if reading %}
<section class="card" id="reading">
<header><h2>{% if compare %}Version {{ reading }} against version {{ before }}{% else %}Version {{ reading }}{% endif %}{% if reading_note %}: {{ reading_note }}{% endif %}</h2>
+57
View File
@@ -0,0 +1,57 @@
{% extends "client_base.html" %}
{% import "_review_marks.html" as rm %}
{% import "_fields.html" as fm %}
{% block main %}
<section class="card" id="review-head">
<div class="ccode mono">{{ head.code }}</div>
<h1>{{ head.title }}</h1>
<p>Version {{ round.version }}, sent by Lanna Desk for {{ client }} to {{ party }} on {{ round.sent }}.</p>
{% if round.message %}<p class="pre rvmsg">{{ round.message }}</p>{% endif %}
</section>
{% if replied %}
<section class="card" id="sent-back">
<h2>Thank you</h2>
<p>You sent this version back on {{ round.replied }} with {{ round.changes }} {% if round.changes == 1 %}change{% else %}changes{% endif %} and {{ round.highlights }} {% if round.highlights == 1 %}highlight{% else %}highlights{% endif %}. Lanna Desk reads it and answers here with the next version. This is what you sent:</p>
{{ rm.marked(shown) }}
</section>
{% else %}
<form method="post" action="{{ action }}" class="form" id="review-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<input type="hidden" name="round" value="{{ round_id }}">
<input type="hidden" name="pieces" id="rv-pieces" value="">
<section class="card" id="editor-card">
<header><h2>Your changes</h2><span class="muted small" id="rv-count" aria-live="polite"></span></header>
<p class="hint">Edit the text as you would any text. What you delete stays in place, crossed out; what you type is marked as added; so Lanna Desk sees every change. To mark a passage for discussion, select it and press Highlight, with a comment if you like. Restore takes your marks back from what you select.</p>
{% if errors.pieces %}<div class="notice warn">{{ errors.pieces }}</div>{% endif %}
<div class="rvtools" role="toolbar" aria-label="Marking tools" aria-controls="rv-editor">
<button type="button" class="btn sm" data-rv="del" title="Cross out the selection (Delete)"><del>Cross out</del></button>
<button type="button" class="btn sm" data-rv="mark" title="Highlight the selection"><mark>Highlight</mark></button>
<input type="text" id="rv-comment" class="rvcomment" placeholder="Comment for the highlight" aria-label="Comment for the highlight" maxlength="500" autocomplete="off">
<button type="button" class="btn sm ghost" data-rv="restore" title="Take your marks back from the selection">Restore</button>
<button type="button" class="btn sm ghost" data-rv="undo" title="Undo (Ctrl+Z)">Undo</button>
</div>
<div class="rvtext rvedit" id="rv-editor" contenteditable="true" spellcheck="true" role="textbox" aria-multiline="true" aria-label="The contract text, to mark up" data-rv-editor></div>
<p class="muted small" id="rv-note" aria-live="polite"></p>
<noscript><p class="notice warn">The editor needs JavaScript. Without it, write your changes in the message below.</p></noscript>
<script type="application/json" id="rv-data">{{ pieces|safe }}</script>
</section>
<section class="card" id="send-back">
<header><h2>Send it back</h2></header>
<div class="grid">
{{ fm.text("name", "Your name", name, err=errors.name, req=true, auto="name", hint="Who at " ~ party ~ " sends this.") }}
{{ fm.area("message", "Message to Lanna Desk", reply_message, err=errors.message, rows=4, fcls="wide", hint="Optional: what your changes are about.") }}
</div>
<div class="formactions"><button type="submit" class="btn pri" id="send-review">Send it back</button></div>
<p class="muted small">You can send this version back once. Lanna Desk then answers with its next version on this same link.</p>
</section>
</form>
<script src="/static/review-editor.js?v={{ v }}" defer></script>
{% endif %}
{% if earlier %}
<section class="card" id="earlier">
<header><h2>Earlier versions</h2></header>
<ul class="rvrounds">{% for r in earlier %}<li>Version {{ r.version }}, sent {{ r.sent }}{% if r.replied %}; you sent it back {{ r.replied }} with {{ r.changes }} {% if r.changes == 1 %}change{% else %}changes{% endif %}{% else %}; not sent back{% endif %}</li>{% endfor %}</ul>
</section>
{% endif %}
<footer class="ft">This link works until {{ link_until }}. Only Lanna Desk's team, who act for {{ client }}, see what you send here.</footer>
{% endblock %}
+53
View File
@@ -0,0 +1,53 @@
{% extends "base.html" %}
{% import "_review_marks.html" as rm %}
{% block main %}
<div class="phead">
<div class="crumbs"><a href="/contracts">Contracts</a> <span class="sep">/</span> <a href="/contracts/{{ id }}#reviews">{{ head.code }}</a></div>
<div class="pagehead"><h1>{{ party }}'s review of version {{ review_version }}</h1></div>
<p class="meta">Sent {{ round.sent }} by {{ round.by }}.{% if replied %} Sent back {{ round.replied }} by {{ round.reply_name }}: {{ round.changes }} {% if round.changes == 1 %}change{% else %}changes{% endif %}, {{ round.highlights }} {% if round.highlights == 1 %}highlight{% else %}highlights{% endif %}.{% endif %}</p>
</div>
{% if not replied %}
<section class="card"><h2>Nothing back yet</h2><p>{{ party }} has not sent this version back yet.</p></section>
{% else %}
{% if reply_message %}
<section class="card" id="reply-message">
<header><h2>Their message</h2></header>
<p class="pre">{{ reply_message }}</p>
</section>
{% endif %}
<section class="card" id="take">
<header><h2>The changes</h2></header>
{% if changes %}
<form method="post" action="/contracts/{{ id }}/reviews/{{ round.id }}/take" id="take-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<p class="hint">Tick the changes to take. The contract page then opens with the version form filled with version {{ review_version }} and those changes, to finish and add as the next version.</p>
<ol class="rvchanges">
{% for c in changes %}
<li id="change-{{ c.n }}"><label class="check"><input type="checkbox" name="take" value="{{ c.n }}" checked><span class="rvn">{{ c.n }}</span><span class="rvchange"><span class="muted">{{ c.before }}</span>{% if c.removed %}<del>{{ c.removed }}</del>{% endif %}{% if c.added %}<ins>{{ c.added }}</ins>{% endif %}<span class="muted">{{ c.after }}</span></span></label></li>
{% endfor %}
</ol>
<div class="formactions"><button type="submit" class="btn pri" id="take-changes">Take the ticked changes</button></div>
</form>
{% else %}
<p class="empty-inline">They changed nothing{% if highlights %}; they highlighted what is listed below{% endif %}.</p>
{% endif %}
</section>
{% if highlights %}
<section class="card" id="highlights">
<header><h2>Highlighted</h2></header>
<ul class="rvhl">{% for h in highlights %}<li><mark>{{ h.text }}</mark>{% if h.comment %}<div class="sub">{{ h.comment }}</div>{% endif %}</li>{% endfor %}</ul>
</section>
{% endif %}
<section class="card" id="diff">
<header><h2>As a diff</h2><span class="muted small">our version {{ review_version }} against their text</span></header>
{% if git %}
<div class="gitdiff">{% for l in git %}{% if l.op == "hunk" %}<div class="gl hunk"><span class="gn"></span><span class="gn"></span><span class="gt">@@ line {{ l.old or l.new }} @@</span></div>{% else %}<div class="gl {{ l.op }}"><span class="gn">{{ l.old or "" }}</span><span class="gn">{{ l.new or "" }}</span><span class="gt"><span class="gs" aria-hidden="true">{% if l.op == "removed" %}-{% elif l.op == "added" %}+{% else %} {% endif %}</span>{% for s in l.segs %}{% if s.hl %}<b>{{ s.text }}</b>{% else %}{{ s.text }}{% endif %}{% endfor %}</span></div>{% endif %}{% else %}<p class="empty-inline">No line changed.</p>{% endfor %}</div>
{% else %}<p class="empty-inline">The texts are too long to compare here.</p>{% endif %}
</section>
<section class="card" id="markup">
<header><h2>As they marked it</h2></header>
{{ rm.marked(shown) }}
<p class="muted small mono hashline">Their text, SHA-256 {{ reply_sha }}</p>
</section>
{% endif %}
{% endblock %}
+23
View File
@@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block main %}
<div class="phead">
<div class="crumbs"><a href="/contracts">Contracts</a> <span class="sep">/</span> <a href="/contracts/{{ id }}">{{ head.code }}</a></div>
<div class="pagehead"><h1>Sent for review</h1></div>
</div>
<section class="card linkcard" id="review-made">
{% if url %}
<header><h2>The link for {{ party }}</h2></header>
<p>Give this link to {{ party }}: by email or chat, or let them scan the code. On it they read version {{ review_version }}, cross out, add and highlight, and send it back. It works until {{ until }}; every version you send them later comes on the same link.</p>
<div class="linkrow">
<input type="text" readonly value="{{ url }}" id="link-url" aria-label="The link" data-select-all>
<button type="button" class="btn" data-copy="#link-url">Copy</button>
</div>
{% if qr %}<div class="qr" aria-label="The link as a QR code">{{ qr|safe }}</div>{% endif %}
<p class="notice warn">The link is shown only now: the app keeps only a fingerprint of it. Copy it before you leave this page; otherwise close the link on the contract page and send again, which makes a new one.</p>
{% else %}
<header><h2>On {{ party }}'s link</h2></header>
<p>Version {{ review_version }} is now on the link {{ party }} has already. Tell them it is there; the link works until {{ until }}.</p>
{% endif %}
<div class="formactions"><a class="btn pri" href="/contracts/{{ id }}#reviews">Done</a></div>
</section>
{% endblock %}