oficina / fichas Public

UX fixes, review changes: contracts keep Email and Phone, tighter email

Claude Fable 5.1 reviewed e83ebe1: APPROVED WITH CHANGES.
- Email and Phone can still go to a Docs contract (they could as Text),
  and travel as text, which is all Docs knows (releaseKind;
  TestEmailAndPhoneStillGoToAContract).
- An email refuses what would make its mailto: link more than an
  address (? # & % / double quotes, brackets) and every kind of
  whitespace; apostrophes stay valid (o'brien@example.ie).
  TestAnEmailIsOnlyAnAddress.
- tel: links take ASCII digits only (telDigits); stripPhoneFormatting
  is left alone, because it is a print's canonical form.
- The print-preservation test uses a legacy-shaped email with spaces,
  so a change of canonical branch for Email is caught.
- The error page has a tab title ("Not found · Fichas").
Left, as the review accepted: a stored value the new kind refuses
blocks other edits on that card until it is fixed (as the Domain
upgrade does).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev b99376e0946aaed07ad7077636b73b39bc6dbbb2 parent e83ebe1
6 files changed, +89 −10
  • internal/fichas/contract_release.go +16 −2
  • internal/fichas/kinds_test.go +37 −1
  • internal/fichas/read.go +17 −2
  • internal/fichas/schema.go +17 −4
  • internal/fichas/templates/contract_prepare.html +1 −1
  • internal/fichas/templates/errors.html +1 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/fichastest/
=== fmt ===
=== test ===
go test ./...
?   	amadan.net/oficina/fichas/cmd/fichas	[no test files]
ok  	amadan.net/oficina/fichas/internal/fichas	1.952s
?   	amadan.net/oficina/fichas/internal/fichas/icons	[no test files]
ok  	amadan.net/oficina/fichas/internal/fichas/seal	(cached)
ok  	amadan.net/oficina/fichas/internal/fichastest	1.217s
?   	amadan.net/oficina/fichas/scripts/mockups	[no test files]
?   	amadan.net/oficina/fichas/scripts/preview	[no test files]
?   	amadan.net/oficina/fichas/scripts/writeestilo	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
diff --git a/internal/fichas/contract_release.go b/internal/fichas/contract_release.go
index 6ea401a..d045d23 100644
--- a/internal/fichas/contract_release.go
+++ b/internal/fichas/contract_release.go
@@ -137,10 +137,11 @@ func releaseFields(c CardView, keys []string) ([]releaseField, error) {
}
seen[key] = true
f := c.Field(key)
- if f.Def.Key == "" || (f.Def.Kind != KindText && f.Def.Kind != KindDate) || len(f.Value) > 8192 || len(f.Label) > 256 {
+ kind, ok := releaseKind(f.Def.Kind)
+ if f.Def.Key == "" || !ok || len(f.Value) > 8192 || len(f.Label) > 256 {
return nil, errRelease
}
- out = append(out, releaseField{key, f.Label, f.Def.Kind, f.Value})
+ out = append(out, releaseField{key, f.Label, kind, f.Value})
}
return out, nil
}
@@ -281,3 +282,16 @@ func releaseTeam(origin, team string) bool {
}
return true
}
+
+// releaseKind is the kind a field travels to Docs as. Docs knows text and
+// date; Email and Phone were Text until 2026-11-12 and still travel as
+// text, so the upgrade took nothing away from a contract.
+func releaseKind(kind string) (string, bool) {
+ switch kind {
+ case KindText, KindEmail, KindPhone:
+ return KindText, true
+ case KindDate:
+ return KindDate, true
+ }
+ return "", false
+}
diff --git a/internal/fichas/kinds_test.go b/internal/fichas/kinds_test.go
index 71f49f6..ca9c833 100644
--- a/internal/fichas/kinds_test.go
+++ b/internal/fichas/kinds_test.go
@@ -17,7 +17,9 @@ func TestSeedUpgradesEmailAndPhone(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- stored := map[string]string{FieldEmail: "Ana@Brightwater.example", FieldPhone: "+353 1 555 0142"}
+ // Legacy-shaped: Text took anything, internal spaces included, and
+ // the print must be exactly the one Text gave it.
+ stored := map[string]string{FieldEmail: "Ana @ Brightwater.example", FieldPhone: "+353 1 555 0142"}
prints := map[string]string{}
for key, value := range stored {
var fd FieldDef
@@ -98,3 +100,37 @@ func TestEmailAndPhoneAreCheckedAndTidied(t *testing.T) {
t.Errorf("the card does not link them: %v", links)
}
}
+
+// An email value cannot carry mailto: parameters, a fragment, encoding or
+// any whitespace into the card's link.
+func TestAnEmailIsOnlyAnAddress(t *testing.T) {
+ for _, v := range []string{
+ "ana@example.com?subject=hi&body=pay+now", "ana@example.com#x", "ana&bob@example.com",
+ "ana%40x@example.com", "ana/x@example.com", "\"ana\"@example.com", "<ana@example.com>",
+ "ana\n@example.com", "ana @example.com", "ana@exa mple.com",
+ } {
+ if looksLikeAnEmail(v) {
+ t.Errorf("%q accepted as an email address", v)
+ }
+ }
+ for _, v := range []string{"ana@example.com", "ana.ni+fichas@cnoc.example", "o'brien@example.ie"} {
+ if !looksLikeAnEmail(v) {
+ t.Errorf("%q refused", v)
+ }
+ }
+}
+
+// Email and Phone were Text, and a Docs contract could carry them. After
+// the upgrade they still can, as text, which is all Docs knows.
+func TestEmailAndPhoneStillGoToAContract(t *testing.T) {
+ for kind, want := range map[string]string{KindText: KindText, KindEmail: KindText, KindPhone: KindText, KindDate: KindDate} {
+ if got, ok := releaseKind(kind); !ok || got != want {
+ t.Errorf("%s releases as %q (%v), want %q", kind, got, ok, want)
+ }
+ }
+ for _, kind := range []string{KindEnum, KindNumber, KindLongText, KindURL} {
+ if _, ok := releaseKind(kind); ok {
+ t.Errorf("%s may now go to a contract; it never could", kind)
+ }
+ }
+}
diff --git a/internal/fichas/read.go b/internal/fichas/read.go
index 665cf46..7ac16e6 100644
--- a/internal/fichas/read.go
+++ b/internal/fichas/read.go
@@ -5,6 +5,7 @@ import (
"fmt"
"html/template"
"sort"
+ "strings"
"time"
"amadan.net/oficina/fichas/internal/fichas/seal"
@@ -397,8 +398,8 @@ func (c CardView) DetailItems() []map[string]any {
href = "mailto:" + v // html/template allows mailto: and escapes it
case f.Def.Kind == KindPhone && looksLikeAPhoneNumber(v):
// html/template refuses tel: unless told it is safe. It is: only
- // digits and a leading + survive stripPhoneFormatting.
- href = template.URL("tel:" + stripPhoneFormatting(v))
+ // ASCII digits and a leading + survive telDigits.
+ href = template.URL("tel:" + telDigits(v))
}
out = append(out, map[string]any{"Label": f.Label, "Value": v, "Href": href, "External": external})
}
@@ -494,3 +495,17 @@ func (c CardView) LongFields() []FieldView {
}
return out
}
+
+// telDigits is a phone number as a tel: link wants it: ASCII digits and a
+// leading +. Not stripPhoneFormatting, whose output is a print's canonical
+// form and must not change; it keeps any Unicode digit, which a dialler
+// cannot use.
+func telDigits(v string) string {
+ var b strings.Builder
+ for i, r := range strings.TrimSpace(v) {
+ if (r >= '0' && r <= '9') || (r == '+' && i == 0) {
+ b.WriteRune(r)
+ }
+ }
+ return b.String()
+}
diff --git a/internal/fichas/schema.go b/internal/fichas/schema.go
index 20aa814..b7e0f53 100644
--- a/internal/fichas/schema.go
+++ b/internal/fichas/schema.go
@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"time"
+ "unicode"
"unicode/utf8"
"amadan.net/oficina/fichas/internal/fichas/seal"
@@ -452,12 +453,24 @@ func IsFormError(err error) (FormError, bool) {
return nil, false
}
-// looksLikeAnEmail is a forgiving check: something@something.something,
-// no spaces. Whether the address exists is the mail server's question.
+// looksLikeAnEmail is a forgiving check: something@something.something.
+// Whether the address exists is the mail server's question. It refuses
+// what would turn a mailto: link into more than an address (?subject=,
+// &body=, a #), anything percent-encoded, slashes, double quotes,
+// brackets and every kind of whitespace (an apostrophe is fine:
+// o'brien@example.ie): a teammate's value must not pre-fill a draft
+// for whoever clicks it.
func looksLikeAnEmail(v string) bool {
local, domain, ok := strings.Cut(v, "@")
- return ok && local != "" && !strings.ContainsAny(v, " \t") &&
- !strings.Contains(domain, "@") && strings.Contains(strings.Trim(domain, "."), ".")
+ if !ok || local == "" || strings.Contains(domain, "@") || !strings.Contains(strings.Trim(domain, "."), ".") {
+ return false
+ }
+ for _, r := range v {
+ if unicode.IsSpace(r) || unicode.IsControl(r) || strings.ContainsRune("?#&/%\\\"<>()[]{},;:", r) {
+ return false
+ }
+ }
+ return true
}
// DefaultTier is the seal tier a kind gets unless someone chooses
diff --git a/internal/fichas/templates/contract_prepare.html b/internal/fichas/templates/contract_prepare.html
index 68fae31..4375806 100644
--- a/internal/fichas/templates/contract_prepare.html
+++ b/internal/fichas/templates/contract_prepare.html
@@ -4,7 +4,7 @@
<div rst-box>
{{if eq .Phase "choose"}}<h2>Choose a live customer</h2><p>Select the customer whose details belong in this agreement.</p>{{range .Cards}}<p><a rst-btn href="/contracts/prepare?flow={{$.Flow}}&amp;card={{.Card.ID}}">{{.Title}} →</a></p>{{else}}<p>No customer cards are available.</p>{{end}}{{end}}
{{if eq .Phase "fields"}}<h2>{{.Card.Title}}</h2><p>Choose the fields to use. Notes and call entries are not included automatically.</p><form method="post" action="/contracts/review"><input type="hidden" name="flow" value="{{.Flow}}"><input type="hidden" name="card" value="{{.Card.Card.ID}}"><input type="hidden" name="revision" value="{{.Card.Card.Revision}}">
-{{range .Card.Fields}}{{if or (eq .Def.Kind "text") (eq .Def.Kind "date")}}<p><label><input type="checkbox" name="field" value="{{.Def.Key}}" {{if eq .Def.Key "f_name"}}checked{{end}}> <strong>{{.Label}}</strong> — {{.Value}}</label></p>{{end}}{{end}}
+{{range .Card.Fields}}{{if or (eq .Def.Kind "text") (eq .Def.Kind "date") (eq .Def.Kind "email") (eq .Def.Kind "phone")}}<p><label><input type="checkbox" name="field" value="{{.Def.Key}}" {{if eq .Def.Key "f_name"}}checked{{end}}> <strong>{{.Label}}</strong> — {{.Value}}</label></p>{{end}}{{end}}
<button rst-btn="primary">Review selected details →</button></form>{{end}}
{{if eq .Phase "review"}}<h2>Approve these details for your contract</h2><dl rst-detail>{{range .Release.Fields}}<dt>{{.Label}}</dt><dd>{{.Value}}</dd>{{end}}</dl><p>Destination: <strong>{{.Destination}}</strong><br>Importer and signer: <strong>{{.Importer}}</strong><br>Source revision: {{.Release.Revision}}</p><p>This authorises these selected values for one contract you sign yourself. Docs must issue it within 30 minutes. Later edits or deletion in Fichas will not retract this approved copy. There is no external-recipient access in this pilot.</p><p>Issued demo records are available for seven days. Existing encrypted backups follow the app’s backup policy; deletion from this screen cannot recall downloaded copies or guarantee backup erasure.</p><form method="post" action="/contracts/approve"><input type="hidden" name="payload" value="{{.Payload}}"><input type="hidden" name="signature" value="{{.Signature}}"><button rst-btn="primary">Approve these details</button></form>{{end}}
{{if eq .Phase "send"}}<h2>Your details are approved.</h2><p>Continue to Docs to review the imported fields and write the agreement.</p><form method="post" action="{{.Destination}}/contracts/receive"><input type="hidden" name="payload" value="{{.Payload}}"><input type="hidden" name="signature" value="{{.Signature}}"><button rst-btn="primary">Continue to Docs →</button></form>{{end}}
diff --git a/internal/fichas/templates/errors.html b/internal/fichas/templates/errors.html
index 73a0e8c..8a78323 100644
--- a/internal/fichas/templates/errors.html
+++ b/internal/fichas/templates/errors.html
@@ -6,4 +6,5 @@
editing this file, or hand it Title/Body/HomeHref/BackHref to
override the partial's own catalog defaults; see
ui/partials/error-page.html for what it accepts. */}}
+{{define "title"}}{{if eq .Status 404}}Not found{{else}}Something went wrong{{end}} · Fichas{{end}}
{{define "content"}}{{template "error-page" dict "Status" .Status "Ref" .Ref}}{{end}}