The legal practice: clients, lawyers, contracts, papers, the journal
CI / secret scan (push) Successful in 7s
CI / fmt, clippy, tests (push) Successful in 45s
CI / release (push) Skipped

Lanna Desk's larger work is contracts, general ones and artists', for
clients who are Thai or foreign, people or organizations, with several
lawyers in the team. The back office gets a Legal section (phase 9 in
docs/PLAN.md):

- Lawyers: license number, contact, the login of one who uses the app
  (then "My contracts"), in the team or left.
- Clients, as record cards: person or organization, names in English and
  Thai, stage name or brand, a Thai ID number (checked), a passport or a
  registration number, the lawyer in charge.
- Contracts: code LD-<year>-<n>, the general kinds and the artist kinds
  (recording, management, publishing, performance, license,
  merchandise), other party, status, lawyer, dates and value; a contract
  in force shows its notice day and its end ahead. Filters: general or
  artists, a lawyer, mine, those over.
- Versions: a text kept here, a file (PDF or scan, encrypted as the
  client's document) or both. They never change: the database refuses
  UPDATE and DELETE, a version's file cannot be deleted and no document's
  checksum can change. Any version reads against the one before as a
  line diff.
- Paper copies: the id <code>-P<n> to write on the paper or print as a
  90 x 50 mm label with a QR code; where it lies, its state and holder,
  each move journaled; found again by its id.
- The journal: every change in words, in the change's transaction, each
  entry chained to the one before by SHA-256. The database refuses to
  change, delete or truncate it; /journal checks the chain and every
  version's text and fingerprints against its entry, shows the last hash
  and exports CSV.

The sidebar groups its sections: Legal, Visas and stays, Office. Demo data
(seed-demo) adds three lawyers, six clients and seven contracts with
versions, papers and moves. Documents take a third owner, the client
(migration 0009).

Checks: fmt, clippy, 115 unit and 62 integration tests (new: versions and
the journal, the database refusing changes, a change around the app
breaking the chain, paper ids and moves, the demo checking whole);
screenshots of the new pages in light, dark and on a phone.
This commit is contained in:
grabowski committed 2026-11-21 23:20:20 +07:00
1 parent 424f212b23
commit 16e4cdc73d
32 files changed
+4758 -45

No files matched your search

+133
View File
@@ -0,0 +1,133 @@
{% extends "base.html" %}
{% import "_fields.html" as fm %}
{% import "_agreement_text.html" as ag %}
{% import "_journal.html" as jn %}
{% block main %}
<div class="phead">
<div class="crumbs"><a href="/contracts">Contracts</a> <span class="sep">/</span> <a href="/clients/{{ head.client_id }}">{{ client_name }}</a></div>
<div class="pagehead">
<div>
<div class="ccode mono">{{ head.code }}</div>
<h1>{{ head.title }}</h1>
</div>
<div class="actions"><a class="btn sm" href="/contracts/{{ id }}/edit" id="edit-contract">Edit the facts</a></div>
</div>
<p class="meta">{% if artist %}<span class="tag gold">artist</span> {% endif %}{{ kind_label }}<span class="sep">·</span>for <a href="/clients/{{ head.client_id }}">{{ client_name }}</a>{% if shown.status %} <span class="chip {{ shown.status.level }}">{{ shown.status.label }}</span>{% endif %}</p>
</div>
<div class="cols">
<section class="card" id="details">
<header><h2>Facts</h2></header>
<dl class="kv">
{% for it in shown.items %}
<dt>{{ it.label }}</dt><dd class="{% if it.pre %}pre{% endif %}{% if it.mono %} mono{% endif %}">{% if it.href %}<a href="{{ it.href }}">{{ it.value }}</a>{% else %}{{ it.value }}{% endif %}</dd>
{% endfor %}
<dt>Opened</dt><dd>{{ opened }}{% if head.created_by %} by {{ head.created_by }}{% endif %}</dd>
</dl>
</section>
<section class="card" id="versions">
<header><h2>Versions</h2><span class="muted small">never changed once added</span></header>
{% for v in versions %}
<div class="item{% if reading and v.version != reading %} old{% endif %}" id="version-{{ v.version }}">
<div class="row"><b>Version {{ v.version }}</b>{% if loop.first %}<span class="tag">newest</span>{% endif %}<span class="muted small">{{ v.at }} · {{ v.by }}</span></div>
<div>{{ v.note }}</div>
<div class="vlinks small">
{% if v.has_text %}<a href="/contracts/{{ id }}?v={{ v.version }}#reading">Read the text</a> <span class="muted">({{ v.chars }} characters)</span>{% endif %}
{% if v.file %}<a href="{{ v.file }}" target="_blank" rel="noopener">{{ v.file_name }}</a> <a href="{{ v.file }}?download=1">download</a>{% endif %}
</div>
{% if v.body_sha %}<div class="muted small mono" title="SHA-256 of the text: {{ v.body_sha }}">text {{ v.body_sha[:16] }}…</div>{% endif %}
{% if v.file_sha %}<div class="muted small mono" title="SHA-256 of the file: {{ v.file_sha }}">file {{ v.file_sha[:16] }}…</div>{% endif %}
</div>
{% else %}
<p class="empty-inline">No version yet: add the first draft below, as a text, a file or both.</p>
{% endfor %}
</section>
</div>
{% 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>
{% if before %}{% if compare %}<a class="small" href="/contracts/{{ id }}?v={{ reading }}#reading">Show the text</a>{% else %}<a class="small" href="/contracts/{{ id }}?v={{ reading }}&amp;compare=1#reading" id="compare">Compare with version {{ before }}</a>{% endif %}{% endif %}
</header>
{% if compare %}
{% if diff %}
<p class="hint">Lines taken out are struck through in red, lines added are marked in green.</p>
<div class="diff">{% for l in diff %}<div class="dl {{ l.op }}">{% if l.op == "removed" %}<del>{{ l.text or " " }}</del>{% elif l.op == "added" %}<ins>{{ l.text or " " }}</ins>{% else %}{{ l.text or " " }}{% endif %}</div>{% endfor %}</div>
{% else %}<p class="empty-inline">The texts are too long to compare here.</p>{% endif %}
{% else %}
{{ ag.text(blocks) }}
{% if reading_sha %}<p class="muted small mono hashline">SHA-256 {{ reading_sha }}</p>{% endif %}
{% endif %}
</section>
{% endif %}
<form method="post" action="/contracts/{{ id }}/versions" enctype="multipart/form-data" class="form upload" id="version-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<section class="card">
<header><h2>Add version {{ next_version }}</h2></header>
<p class="hint lead">A new draft, the other side's changes, the final text, the scan of the signed paper: each is a version. Keep the text here, attach the file (PDF or a scan), or both. A version never changes once added; its fingerprints go into the journal.</p>
<div class="grid">
{{ fm.text("note", "What this version is", draft_note, err=errors.note, req=true, cls="wide", ph="Such as: first draft, the label's changes, signed by both sides") }}
{{ fm.area("body", "Text", draft_body, err=errors.body, rows=14, fcls="wide", hint="Paragraphs separated by an empty line, # before a heading, - before a list item. It starts as the last version's text; leave it as it is to add only a file.") }}
<div class="field wide{% if errors.file %} has-err{% endif %}">
<label for="f-file">File</label>
{% if uploads %}<input id="f-file" name="file" type="file" accept="application/pdf,image/jpeg,image/png,image/webp">
<p class="hint">PDF, JPEG, PNG or WebP, up to {{ file_mb }} MB. Stored encrypted, like every document.</p>{% else %}<p class="hint">This server keeps no files: add the text only.</p>{% endif %}
{% if errors.file %}<p class="err" id="e-file">{{ errors.file }}</p>{% endif %}
</div>
</div>
<div class="formactions"><button type="submit" class="btn pri" id="add-version">Add version {{ next_version }}</button></div>
</section>
</form>
<h2 class="sechead" id="papers">Paper copies</h2>
<p class="meta">Each paper gets an id to write on it, or a label to print. Its record says where it lies; every move goes into the journal.</p>
{% if papers %}
<div class="card flush">
<div class="tblwrap">
<table class="tbl" id="paper-list">
<thead><tr><th>Id</th><th>Paper</th><th>Where it is</th><th></th></tr></thead>
<tbody>
{% for p in papers %}
<tr id="paper-{{ p.id }}"{% if p.gone %} class="old"{% endif %}>
<td><span class="pcode mono">{{ p.code }}</span></td>
<td>{{ p.what }}{% if p.version %}<div class="sub">version {{ p.version }}</div>{% endif %}</td>
<td><span class="chip {% if p.state == "filed" %}ok{% elif p.state == "out" %}warn{% else %}plain{% endif %}">{{ p.state_label }}</span> {{ p.location }}{% if p.holder %}<div class="sub">with {{ p.holder }}</div>{% endif %}<div class="sub">since {{ p.moved }}</div></td>
<td class="pacts">
<a class="btn sm ghost" href="/papers/{{ p.id }}/label" target="_blank" rel="noopener">Label</a>
<details class="move"><summary class="btn sm ghost">Move</summary>
<form method="post" action="/papers/{{ p.id }}/move" class="form mini">
<input type="hidden" name="csrf" value="{{ csrf }}">
<label>Where it is now<input name="location" value="{{ p.location }}" list="locations" required></label>
<label>State<select name="state">{% for s in states %}<option value="{{ s[0] }}"{% if s[0] == p.state %} selected{% endif %}>{{ s[1] }}</option>{% endfor %}</select></label>
<label>With whom<input name="holder" value="{{ p.holder }}" placeholder="While it is out, or whom it went to"></label>
<label>Note<input name="note" placeholder="Such as: for the signing at the label"></label>
<button type="submit" class="btn sm pri">Save the move</button>
</form>
</details>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
<form method="post" action="/contracts/{{ id }}/papers" class="form" id="paper-form">
<input type="hidden" name="csrf" value="{{ csrf }}">
<section class="card">
<header><h2>Register a paper copy</h2></header>
<div class="grid">
{{ fm.text("what", "What it is", "", req=true, list="whats", ph="Signed original") }}
<div class="field">
<label for="f-version">Version</label>
<select id="f-version" name="version"><option value="">Not known</option>{% for v in versions %}<option value="{{ v.version }}"{% if loop.first %} selected{% endif %}>Version {{ v.version }}: {{ v.note }}</option>{% endfor %}</select>
</div>
{{ fm.text("location", "Where it is filed", "", req=true, list="locations", cls="wide", ph="Office, cabinet A, drawer 2, folder of the client") }}
</div>
<div class="formactions"><button type="submit" class="btn" id="add-paper">Register and give it an id</button></div>
</section>
</form>
<datalist id="whats">{% for w in whats %}<option value="{{ w }}"></option>{% endfor %}</datalist>
<datalist id="locations">{% for l in locations %}<option value="{{ l }}"></option>{% endfor %}</datalist>
<section class="card" id="contract-journal">
<header><h2>Journal of this contract</h2><a class="small" href="/journal">The whole journal, checked</a></header>
{% if entries %}{{ jn.list(entries) }}{% else %}<p class="empty-inline">Nothing yet.</p>{% endif %}
</section>
{% endblock %}