console: download the DPA as a PDF from the record page
GET /a/{sqid}/settings/dpa.pdf (handleDPAPDF, dpapdfroute.go): any
member; no acceptance in force, or no PDF engine, is the plain 404;
the write limit bounds the cost. It renders the acceptance's own
document and letterhead and posts them to the engine with a no-proxy
client the Server owns. 200 is application/pdf, attachment with the
approved filename, no-store. A render or engine failure is the record
page at 502 with record.pdf_failed, logged with the sqid and category.
The record page shows Download PDF as the main button when an engine is
configured, print beside it. The confirmation email adds the PDF line
after the record link, from the console's Origin, only with an engine.
Census: claim route list, fixture and probe, parity row, perfTargets,
and the record-write re-pin of routeDecls (dpa_pdf_census_test.go).
Deck rows PDF-C15 to PDF-C18 are built.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/parity.md+1 −1internal/console/approved_dpa_pdf_copy_test.go+3 −0internal/console/claim_invariant_fixtures_test.go+1 −0internal/console/claim_invariant_probes_read_test.go+14 −2internal/console/dpapane.go+19 −4internal/console/dpapane_test.go+1 −1internal/console/dpapdf_test.go+13 −0internal/console/dpapdfroute.go+107 −0internal/console/dpapdfroute_test.go+381 −0internal/console/dparecord.go+47 −20internal/console/perfwalk_test.go+3 −0internal/console/routedecls.go+1 −0internal/console/server.go+7 −2internal/console/templates/dpa_record.html+3 −1internal/console/testdata/claim-routes.txt+1 −0internal/provision/dpa_pdf_census_test.go+36 −0internal/provision/plan9_b8_census_test.go+1 −1parity/parity.tsv+1 −1
CI cancelled — superseded by a newer push — run details
Intent
<task-notification> <task-id>a2221c82887481403</task-id> <tool-use-id>toolu_015xK7pQF2oKcDxvA4DbExRs</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/a2221c82887481403.output</output-file> <status>completed</status> <summary>Agent "Implement S2 Task 2: engine client" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE. All three test-hygiene fixes and the two comments are in. Commit: b805f3b5 "console: harden the DPA PDF engine client tests". It is not pushed. The stale-lock message appeared again, but `git log -1` shows the commit. Tests: `go test ./internal/console -run TestPDFFromHTML -count=1` passes, and `gofmt` is clean. Concerns: for fix 1, closing `stall` in `t.Cleanup` alone would not stop a hang. Each subtest's `defer srv.Close()` runs before the parent's cleanup, so the server would wait on the stalled handler first. I kept the `t.Cleanup` and also gave the stalled handler a 5 s `time.After` exit. I did not re-run `make code-health` after this change. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-pdf/.superpowers/sdd/2026-11-26-dpa-pdf/task-2-report.md</result> <usage><subagent_tokens>52440</subagent_tokens><tool_uses>3</tool_uses><duration_ms>100181</duration_ms></usage> </task-notification>
Attributed to this commit: 15.9 g CO₂e (2,065,382 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on dpa-pdf, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/parity.md b/docs/parity.md| index 97a8ca7ad..8e262fba4 100644 |
| --- a/docs/parity.md |
| +++ b/docs/parity.md |
| @@ -28,7 +28,7 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| | auth-login | cli-only | `auth login` | | | Signs this terminal in; the browser half is an auth row. | |
| | auth-identity | cli-only | `auth whoami`<br>`auth logout`<br>`auth default` | | | This terminal's own identity and default console. | |
| | account-delete | console-only | | `POST /a/{sqid}/delete` | | Deleting an account needs a passkey. | |
| -| dpa-accept | console-only | | `GET /a/{sqid}/settings`<br>`GET /a/{sqid}/settings/dpa`<br>`POST /a/{sqid}/dpa/accept` | | An owner accepts the data processing agreement, and confirms with a passkey. | |
| +| dpa-accept | console-only | | `GET /a/{sqid}/settings`<br>`GET /a/{sqid}/settings/dpa`<br>`GET /a/{sqid}/settings/dpa.pdf`<br>`POST /a/{sqid}/dpa/accept` | | An owner accepts the data processing agreement, and confirms with a passkey. | |
| | plan-keep | gap | | `GET /a/{sqid}/plan/keep`<br>`POST /a/{sqid}/plan/keep` | [wp-cli-verbs](#wp-cli-verbs) | Choosing which apps to keep when a plan lapses. | |
| | getting-started | console-only | | `POST /a/{sqid}/getting-started/hide`<br>`POST /a/{sqid}/getting-started/show`<br>`POST /a/{sqid}/getting-started/skip`<br>`POST /a/{sqid}/getting-started/done` | | A checklist in the page. | |
| | nav-index | console-only | | `GET /a/{sqid}/index`<br>`GET /a/{sqid}/apps/{app}/index`<br>`GET /a/{sqid}/apps/{app}/settings/index` | | Phone navigation pages that list sections. | |
diff --git a/internal/console/approved_dpa_pdf_copy_test.go b/internal/console/approved_dpa_pdf_copy_test.go| index ba4730976..f82852128 100644 |
| --- a/internal/console/approved_dpa_pdf_copy_test.go |
| +++ b/internal/console/approved_dpa_pdf_copy_test.go |
| @@ -27,6 +27,9 @@ var dpaPDFCopyBuilt = map[string]bool{ |
| "PDF-C05": true, "PDF-C06": true, "PDF-C07": true, "PDF-C08": true, |
| "PDF-C09": true, "PDF-C10": true, "PDF-C11": true, "PDF-C12": true, |
| "PDF-C13": true, "PDF-C14": true, |
| + // Task 3: the download's filename and failure (dpapdfroute.go), the |
| + // record page's button and the confirmation email's line. |
| + "PDF-C15": true, "PDF-C16": true, "PDF-C17": true, "PDF-C18": true, |
| } |
| func parseDPAPDFCopyDeck(t *testing.T) []navCopyRow { |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index fa1ef386d..3836f339f 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -861,6 +861,7 @@ var claimFixtures = map[string]claimFixture{ |
| "route GET /a/{sqid}/index": claimRead("renders the account's sections as a phone index"), |
| "route GET /a/{sqid}/settings": claimRead("renders account settings"), |
| "route GET /a/{sqid}/settings/dpa": claimRead("renders the account's data processing agreement record; writes nothing"), |
| + "route GET /a/{sqid}/settings/dpa.pdf": claimRead("answers the account's executed data processing agreement as a PDF from the PDF engine; writes nothing"), |
| "route GET /a/{sqid}/plan/keep": claimRead("renders the keep page (plans 4d) from the plan row, lapse items and an inventory read; writes nothing"), |
| "route GET /a/{sqid}/team": claimRead("renders members and invites"), |
| "route GET /a/{sqid}/trash": claimRead("lists trashed apps; purge is the trash/delete door"), |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 1a07fa649..2a3343bd2 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -46,6 +46,15 @@ func claimWorldInstance(t *testing.T, cx *claimCase) { |
| func claimWorldFleet(t *testing.T, cx *claimCase) { t.Helper(); cx.fleet(t) } |
| +// claimWorldDPAPDF is an acceptance in force for account bab and a fake PDF |
| +// engine (dpapdfroute_test.go). |
| +func claimWorldDPAPDF(t *testing.T, cx *claimCase) { |
| + t.Helper() |
| + docID, lhID := dpaWorld(t, cx.consoleFixture) |
| + dpaAcceptFor(t, cx.consoleFixture, docID, lhID) |
| + dpaPDFEngineFor(t, cx.consoleFixture) |
| +} |
| + |
| // claimWorldLapse turns plans on and puts account bab on a lapse (plans 4d). |
| func claimWorldLapse(t *testing.T, cx *claimCase) { |
| t.Helper() |
| @@ -218,8 +227,11 @@ var claimReadProbes = map[string]claimProbe{ |
| "route GET /a/{sqid}/index": claimPageRead(nil, "/a/bab/index", `id="nav-apps"`), |
| "route GET /a/{sqid}/settings": claimPageRead(nil, "/a/bab/settings", "<h1>Account settings</h1>"), |
| "route GET /a/{sqid}/settings/dpa": claimPageRead(nil, "/a/bab/settings/dpa", "<h1>Data processing agreement</h1>"), |
| - "route GET /a/{sqid}/plan/keep": claimPageRead(claimWorldLapse, "/a/bab/plan/keep", "<h1>Choose what stays</h1>"), |
| - "route GET /a/{sqid}/team": claimPageRead(nil, "/a/bab/team", "<h1>Team</h1>", claimFxOwner), |
| + // An acceptance in force and a fake engine: the PDF's bytes. |
| + "route GET /a/{sqid}/settings/dpa.pdf": claimPageRead(claimWorldDPAPDF, "/a/bab/settings/dpa.pdf", |
| + "%PDF-1.7 test"), |
| + "route GET /a/{sqid}/plan/keep": claimPageRead(claimWorldLapse, "/a/bab/plan/keep", "<h1>Choose what stays</h1>"), |
| + "route GET /a/{sqid}/team": claimPageRead(nil, "/a/bab/team", "<h1>Team</h1>", claimFxOwner), |
| "route GET /a/{sqid}/trash": claimPageRead(func(t *testing.T, cx *claimCase) { cx.trash(t, "titogo") }, |
| "/a/bab/trash", "<h1>Trash</h1>", "titogo"), |
| "route GET /a/{sqid}/{$}": claimPageRead(nil, "/a/bab/", "kass"), |
diff --git a/internal/console/dpapane.go b/internal/console/dpapane.go| index c9ed5dde6..b5076843c 100644 |
| --- a/internal/console/dpapane.go |
| +++ b/internal/console/dpapane.go |
| @@ -93,8 +93,9 @@ func dpaObjectText(privacyAddress string) string { |
| // dpaAcceptEmail is the confirmation sent to the accepting owner |
| // (dpa.email.subject and dpa.email.body). A multi-line address is written |
| -// on one line, its lines joined by commas. |
| -func dpaAcceptEmail(doc *LegalDocument, lh *Letterhead, a DPAAcceptance, recordURL string) (subject, body string) { |
| +// on one line, its lines joined by commas. pdfURL, when set (a PDF engine |
| +// is configured), adds email.pdf_line after the record link. |
| +func dpaAcceptEmail(doc *LegalDocument, lh *Letterhead, a DPAAcceptance, recordURL, pdfURL string) (subject, body string) { |
| at := a.AcceptedAt.UTC() |
| address := strings.Join(strings.Split(a.Address, "\n"), ", ") |
| subject = "Data processing agreement accepted for " + a.LegalName |
| @@ -104,11 +105,20 @@ func dpaAcceptEmail(doc *LegalDocument, lh *Letterhead, a DPAAcceptance, recordU |
| "Accepted by: " + a.SignerName + ", " + a.SignerRole + " (" + a.AcceptedBy + ")\n" + |
| "Agreement: " + doc.URL + "\n" + |
| "Fingerprint of the text: " + doc.SHA256 + "\n\n" + |
| - "The record is in your account settings: " + recordURL + "\n\n" + |
| + "The record is in your account settings: " + recordURL + "\n" + dpaEmailPDFLine(pdfURL) + "\n" + |
| "Questions: " + lh.PrivacyAddress |
| return subject, body |
| } |
| +// dpaEmailPDFLine is email.pdf_line and its line break, or nothing when |
| +// there is no PDF to download. |
| +func dpaEmailPDFLine(pdfURL string) string { |
| + if pdfURL == "" { |
| + return "" |
| + } |
| + return "Download it as a PDF: " + pdfURL + "\n" |
| +} |
| + |
| // dpaForm is the acceptance form as typed. |
| type dpaForm struct { |
| LegalName, Address, Country, SignerName, SignerRole string |
| @@ -401,7 +411,12 @@ func (s *Server) handleDPAAccept(w http.ResponseWriter, r *http.Request) { |
| // acceptance row and nowhere else. |
| s.audit(acct, "", addr, "dpa.accept", "version "+doc.Version) |
| - subject, body := dpaAcceptEmail(doc, lh, a, s.cfg.Origin+settings+"/dpa") |
| + // Both links are the console's own origin, never the request's Host. |
| + pdfURL := "" |
| + if s.cfg.PDFEngine != "" { |
| + pdfURL = s.cfg.Origin + dpaPDFURL(acct.Sqid) |
| + } |
| + subject, body := dpaAcceptEmail(doc, lh, a, s.cfg.Origin+settings+"/dpa", pdfURL) |
| mctx, cancel := context.WithTimeout(ctx, dpaMailTimeout) |
| defer cancel() |
| if _, err := s.deliver(mctx, addr, subject, body, dpaMailKeymailShare); err != nil { |
diff --git a/internal/console/dpapane_test.go b/internal/console/dpapane_test.go| index b0f351565..c2708aeb9 100644 |
| --- a/internal/console/dpapane_test.go |
| +++ b/internal/console/dpapane_test.go |
| @@ -515,7 +515,7 @@ func TestDPAAcceptEmailCopy(t *testing.T) { |
| lh := &Letterhead{Entity: "Example Hosting Limited", PrivacyAddress: "privacy@example.com"} |
| a := DPAAcceptance{LegalName: "Shop Limited", Address: "1 Main Street\nDublin", Country: "IE", |
| SignerName: "Ada Lovelace", SignerRole: "Director", AcceptedBy: "ada@example.com", AcceptedAt: at} |
| - subject, body := dpaAcceptEmail(doc, lh, a, "https://console.example.com/a/bab/settings/dpa") |
| + subject, body := dpaAcceptEmail(doc, lh, a, "https://console.example.com/a/bab/settings/dpa", "") |
| if want := oplDeck(t, "DPA-C42", "legal_name", "Shop Limited"); subject != want { |
| t.Errorf("subject = %q, want %q", subject, want) |
| } |
diff --git a/internal/console/dpapdf_test.go b/internal/console/dpapdf_test.go| index 31c5c7053..f8cfb51fb 100644 |
| --- a/internal/console/dpapdf_test.go |
| +++ b/internal/console/dpapdf_test.go |
| @@ -138,6 +138,19 @@ func TestDPAPDFCopy(t *testing.T) { |
| if want := `Page <span class="pageNumber"></span> of <span class="totalPages"></span>`; !strings.Contains(footer, want) { |
| t.Errorf("footer.html is missing %q:\n%s", want, footer) |
| } |
| + // PDF-C15, the download's filename. A version is free text, so anything |
| + // but a letter, digit, dot, hyphen or underscore becomes a hyphen: the |
| + // name always fits a quoted header value. |
| + for version, filled := range map[string]string{ |
| + "1": "1", |
| + "2026-11.b_2": "2026-11.b_2", |
| + `2 "beta"/x`: "2--beta--x", |
| + "é\r\n": "---", |
| + } { |
| + if got, want := dpaPDFFilename(version), dpaPDFDeck(t, "PDF-C15", "version", filled); got != want { |
| + t.Errorf("dpaPDFFilename(%q) = %q, want %q", version, got, want) |
| + } |
| + } |
| } |
| func TestDPAPDFHTMLEscapes(t *testing.T) { |
diff --git a/internal/console/dpapdfroute.go b/internal/console/dpapdfroute.go| new file mode 100644 |
| index 000000000..c093ac59c |
| --- /dev/null |
| +++ b/internal/console/dpapdfroute.go |
| @@ -0,0 +1,107 @@ |
| +package console |
| + |
| +import ( |
| + "log" |
| + "net/http" |
| + "strconv" |
| + "strings" |
| + "time" |
| +) |
| + |
| +// The executed data processing agreement as a PDF (DPA and retention spec |
| +// §3.8): GET /a/{sqid}/settings/dpa.pdf. Any member may download it. It |
| +// carries the document and letterhead the acceptance itself names, never |
| +// the current ones. |
| + |
| +// dpaPDFFailedText is record.pdf_failed: the engine or the render failed. |
| +const dpaPDFFailedText = "We couldn't make the PDF just now. Try again in a minute, or print this page instead." |
| + |
| +// dpaPDFFilename is pdf.filename, the download's name. The version is free |
| +// text an operator typed, so every character but a letter, digit, dot, |
| +// hyphen or underscore becomes a hyphen: the name always fits a quoted |
| +// Content-Disposition value. |
| +func dpaPDFFilename(version string) string { |
| + safe := strings.Map(func(r rune) rune { |
| + switch { |
| + case r >= 'a' && r <= 'z', r >= 'A' && r <= 'Z', r >= '0' && r <= '9', r == '.', r == '-', r == '_': |
| + return r |
| + } |
| + return '-' |
| + }, version) |
| + return "data-processing-agreement-v" + safe + ".pdf" |
| +} |
| + |
| +// dpaPDFURL is the download's path for an account. |
| +func dpaPDFURL(sqid string) string { return accountSettingsURL(sqid) + "/dpa.pdf" } |
| + |
| +// newDPAPDFClient is the console's client for the PDF engine. The engine is |
| +// internal, so no proxy, and a redirect is answered as it stands (a non-200, |
| +// so an error in pdfFromHTML). pdfFromHTML sets the deadline. |
| +func newDPAPDFClient() *http.Client { |
| + transport := http.DefaultTransport.(*http.Transport).Clone() |
| + transport.Proxy = nil |
| + return &http.Client{Transport: transport, CheckRedirect: func(*http.Request, []*http.Request) error { |
| + return http.ErrUseLastResponse |
| + }} |
| +} |
| + |
| +// dpaPDFConsoleName is the console's name as the PDF's "in the {console} |
| +// console" lines want it: the page chrome's name without a trailing |
| +// " console", so the default "CARLOS console" does not read twice. |
| +func (s *Server) dpaPDFConsoleName() string { |
| + return strings.TrimSuffix(s.brandName(), " console") |
| +} |
| + |
| +// handleDPAPDF answers the PDF. Gates, in order: membership (the |
| +// byte-identical 404 for anyone else); an acceptance in force (else the |
| +// 404 the record page gives a member); an engine configured (else the |
| +// plain 404); the write limit, as a cost bound. A render or engine failure |
| +// is the record page at 502 with record.pdf_failed, logged with the |
| +// account and the error's category only. |
| +func (s *Server) handleDPAPDF(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, acct, role, ok := s.account(w, r) |
| + if !ok { |
| + return |
| + } |
| + ctx := r.Context() |
| + live, doc, lh, err := s.dpaLiveRecord(ctx, acct.ID) |
| + if err != nil { |
| + log.Printf("console: dpa pdf %s: %v", acct.Sqid, err) |
| + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| + return |
| + } |
| + if live == nil || s.cfg.PDFEngine == "" { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + if !s.allowWrite(Principal{Address: addr}, time.Now()) { |
| + s.renderMessage(w, r, http.StatusTooManyRequests, "Refused", dpaRateLimitText) |
| + return |
| + } |
| + failed := func(category string) { |
| + log.Printf("console: dpa pdf %s: %s", acct.Sqid, category) |
| + s.renderDPARecord(w, r, addr, raw, acct, role, http.StatusBadGateway, dpaPDFFailedText) |
| + } |
| + index, header, footer, err := renderDPAPDF(dpaPDFInput{ |
| + Acceptance: *live, Doc: *doc, Letterhead: *lh, ConsoleName: s.dpaPDFConsoleName(), |
| + }) |
| + if err != nil { |
| + // The error names the document and the check that failed; the |
| + // category is enough here. |
| + failed("render") |
| + return |
| + } |
| + pdf, err := pdfFromHTML(ctx, s.dpaPDFHTTP, s.cfg.PDFEngine, index, header, footer) |
| + if err != nil { |
| + // pdfFromHTML's errors are categories already. |
| + failed("pdf engine: " + err.Error()) |
| + return |
| + } |
| + h := w.Header() |
| + h.Set("Content-Type", "application/pdf") |
| + h.Set("Content-Disposition", `attachment; filename="`+dpaPDFFilename(doc.Version)+`"`) |
| + h.Set("Content-Length", strconv.Itoa(len(pdf))) |
| + h.Set("Cache-Control", "no-store") |
| + w.WriteHeader(http.StatusOK) |
| + _, _ = w.Write(pdf) |
| +} |
diff --git a/internal/console/dpapdfroute_test.go b/internal/console/dpapdfroute_test.go| new file mode 100644 |
| index 000000000..065b3341a |
| --- /dev/null |
| +++ b/internal/console/dpapdfroute_test.go |
| @@ -0,0 +1,381 @@ |
| +package console |
| + |
| +import ( |
| + "bytes" |
| + "io" |
| + "log" |
| + "net/http" |
| + "net/http/httptest" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// The DPA PDF download (dpapdfroute.go, spec §3.8): the route, the record |
| +// page's button and the confirmation email's PDF line. |
| + |
| +// dpaPDFDeck is a PDF deck row's text with its {names} filled from kv. |
| +func dpaPDFDeck(t *testing.T, id string, kv ...string) string { |
| + t.Helper() |
| + for _, r := range parseDPAPDFCopyDeck(t) { |
| + if r.ID == id { |
| + s := r.New |
| + for i := 0; i+1 < len(kv); i += 2 { |
| + s = strings.ReplaceAll(s, "{"+kv[i]+"}", kv[i+1]) |
| + } |
| + return s |
| + } |
| + } |
| + t.Fatalf("no deck row %s", id) |
| + return "" |
| +} |
| + |
| +// dpaFakeEngine is a PDF engine that records each index.html it is sent |
| +// and answers status, with "%PDF-1.7 test" when that is 200. |
| +type dpaFakeEngine struct { |
| + mu sync.Mutex |
| + index []string |
| + status int |
| +} |
| + |
| +func (e *dpaFakeEngine) sent() []string { |
| + e.mu.Lock() |
| + defer e.mu.Unlock() |
| + return append([]string(nil), e.index...) |
| +} |
| + |
| +// dpaPDFEngineFor starts a fake engine and points the console at it. |
| +func dpaPDFEngineFor(t *testing.T, fx *consoleFixture) *dpaFakeEngine { |
| + t.Helper() |
| + e := &dpaFakeEngine{status: http.StatusOK} |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if r.Method != http.MethodPost || r.URL.Path != "/forms/chromium/convert/html" { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + if err := r.ParseMultipartForm(4 << 20); err != nil { |
| + http.Error(w, "bad form", http.StatusBadRequest) |
| + return |
| + } |
| + var index string |
| + for _, h := range r.MultipartForm.File["files"] { |
| + if h.Filename != "index.html" { |
| + continue |
| + } |
| + f, err := h.Open() |
| + if err != nil { |
| + continue |
| + } |
| + b, _ := io.ReadAll(f) |
| + f.Close() |
| + index = string(b) |
| + } |
| + e.mu.Lock() |
| + e.index = append(e.index, index) |
| + status := e.status |
| + e.mu.Unlock() |
| + if status != http.StatusOK { |
| + http.Error(w, "engine trouble", status) |
| + return |
| + } |
| + w.Header().Set("Content-Type", "application/pdf") |
| + _, _ = io.WriteString(w, "%PDF-1.7 test") |
| + })) |
| + t.Cleanup(srv.Close) |
| + fx.srv.cfg.PDFEngine = srv.URL |
| + return e |
| +} |
| + |
| +// dpaGet is a GET with its headers. |
| +func dpaGet(t *testing.T, c *http.Client, u string) (int, http.Header, string) { |
| + t.Helper() |
| + res, err := c.Get(u) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer res.Body.Close() |
| + raw, err := io.ReadAll(res.Body) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return res.StatusCode, res.Header, string(raw) |
| +} |
| + |
| +// dpaMember adds kim as a plain member of the ops account and signs her in. |
| +func dpaMember(t *testing.T, fx *consoleFixture) *http.Client { |
| + t.Helper() |
| + if err := fx.st.AddMember(OpsAccountID, "kim@keymail.dev", RoleMember, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + c, _ := signInAs(t, fx, "kim@keymail.dev", "code-"+t.Name()+"-kim") |
| + return c |
| +} |
| + |
| +func TestDPAPDFDownload(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + member := dpaMember(t, fx) |
| + docID, lhID := dpaWorld(t, fx) |
| + dpaAcceptFor(t, fx, docID, lhID) |
| + engine := dpaPDFEngineFor(t, fx) |
| + |
| + status, h, body := dpaGet(t, member, fx.u("/settings/dpa.pdf")) |
| + if status != http.StatusOK || body != "%PDF-1.7 test" { |
| + t.Fatalf("download = %d %q", status, body) |
| + } |
| + if ct := h.Get("Content-Type"); ct != "application/pdf" { |
| + t.Errorf("Content-Type = %q", ct) |
| + } |
| + if cd, want := h.Get("Content-Disposition"), `attachment; filename="`+dpaPDFDeck(t, "PDF-C15", "version", "1")+`"`; cd != want { |
| + t.Errorf("Content-Disposition = %q, want %q", cd, want) |
| + } |
| + if cc := h.Get("Cache-Control"); cc != "no-store" { |
| + t.Errorf("Cache-Control = %q", cc) |
| + } |
| + sent := engine.sent() |
| + if len(sent) != 1 { |
| + t.Fatalf("engine got %d requests, want 1", len(sent)) |
| + } |
| + for _, want := range []string{"Version 1", "https://example.com/dpa/1/", oplDigest([]byte(oplFragment)), |
| + "Shop <Limited>", "Example Hosting Limited"} { |
| + if !strings.Contains(sent[0], want) { |
| + t.Errorf("the HTML sent lacks %q", want) |
| + } |
| + } |
| +} |
| + |
| +func TestDPAPDFUsesAcceptedIDs(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + docID, lhID := dpaWorld(t, fx) |
| + dpaAcceptFor(t, fx, docID, lhID) |
| + // A newer letterhead and a newer version, already effective, published |
| + // after the acceptance. |
| + dpaLetterhead(t, fx, "Newer Hosting Limited") |
| + dpaPublish(t, fx, "2", dpaFragmentV2, time.Now().Add(-time.Minute)) |
| + engine := dpaPDFEngineFor(t, fx) |
| + |
| + status, h, _ := dpaGet(t, c, fx.u("/settings/dpa.pdf")) |
| + if status != http.StatusOK { |
| + t.Fatalf("download = %d", status) |
| + } |
| + if cd := h.Get("Content-Disposition"); !strings.Contains(cd, dpaPDFDeck(t, "PDF-C15", "version", "1")) { |
| + t.Errorf("Content-Disposition = %q, want version 1's name", cd) |
| + } |
| + sent := engine.sent() |
| + if len(sent) != 1 { |
| + t.Fatalf("engine got %d requests, want 1", len(sent)) |
| + } |
| + for _, want := range []string{"https://example.com/dpa/1/", "Example Hosting Limited", oplDigest([]byte(oplFragment))} { |
| + if !strings.Contains(sent[0], want) { |
| + t.Errorf("the HTML sent lacks the accepted %q", want) |
| + } |
| + } |
| + for _, bad := range []string{"Newer Hosting", "example.com/dpa/2/", oplDigest([]byte(dpaFragmentV2)), "version 2"} { |
| + if strings.Contains(sent[0], bad) { |
| + t.Errorf("the HTML sent carries the current %q, not the accepted one", bad) |
| + } |
| + } |
| +} |
| + |
| +func TestDPAPDFGates(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + member := dpaMember(t, fx) |
| + owner := signInPaul(t, fx) |
| + stranger, _ := signInAs(t, fx, "eve@keymail.dev", "code-dpa-pdf-stranger") |
| + docID, lhID := dpaWorld(t, fx) |
| + engine := dpaPDFEngineFor(t, fx) |
| + |
| + // No acceptance in force: the record page's 404 for a member, and the |
| + // same for an owner (whose record page is the "none yet" page instead). |
| + _, _, recordMember := get(t, member, fx.u("/settings/dpa")) |
| + _, _, unrouted := get(t, member, fx.ts.URL+"/no/such/path") |
| + if recordMember != unrouted { |
| + t.Fatalf("the record page's member 404 is not the plain one") |
| + } |
| + for name, c := range map[string]*http.Client{"member": member, "owner": owner} { |
| + if s, _, b := get(t, c, fx.u("/settings/dpa.pdf")); s != http.StatusNotFound || b != recordMember { |
| + t.Errorf("%s with no acceptance = %d, want the record page's 404", name, s) |
| + } |
| + } |
| + |
| + dpaAcceptFor(t, fx, docID, lhID) |
| + // A non-member: the byte-identical 404. |
| + if s, _, b := get(t, stranger, fx.u("/settings/dpa.pdf")); s != http.StatusNotFound || b != unrouted { |
| + t.Errorf("non-member = %d, want the byte-identical 404", s) |
| + } |
| + // Signed out: no page either. |
| + if s, _, _ := get(t, newBrowser(t), fx.u("/settings/dpa.pdf")); s == http.StatusOK { |
| + t.Errorf("signed out = %d", s) |
| + } |
| + if n := len(engine.sent()); n != 0 { |
| + t.Fatalf("engine called %d times by refused requests", n) |
| + } |
| + |
| + // Over the write limit: the DPA pages' refusal, and no engine call. |
| + fx.srv.cli.write = newRateLimiter(1, time.Hour) |
| + if !fx.srv.allowWrite(Principal{Address: "kim@keymail.dev"}, time.Now()) { |
| + t.Fatal("the fresh limiter refused the first write") |
| + } |
| + s, _, b := get(t, member, fx.u("/settings/dpa.pdf")) |
| + if s != http.StatusTooManyRequests || !strings.Contains(oplText(b), dpaRateLimitText) { |
| + t.Errorf("over the limit = %d, want 429 with %q:\n%s", s, dpaRateLimitText, b) |
| + } |
| + if n := len(engine.sent()); n != 0 { |
| + t.Errorf("engine called %d times over the limit", n) |
| + } |
| +} |
| + |
| +func TestDPAPDFNoEngine(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + docID, lhID := dpaWorld(t, fx) |
| + dpaAcceptFor(t, fx, docID, lhID) |
| + |
| + _, _, page := get(t, c, fx.u("/settings/dpa")) |
| + if strings.Contains(page, dpaPDFDeck(t, "PDF-C16")) || strings.Contains(page, "dpa.pdf") { |
| + t.Errorf("record page offers the PDF with no engine:\n%s", page) |
| + } |
| + if !strings.Contains(page, `<button type="button" onclick="window.print()">`) { |
| + t.Errorf("print is not the main button with no engine:\n%s", page) |
| + } |
| + status, _, body := get(t, c, fx.u("/settings/dpa.pdf")) |
| + _, _, unrouted := get(t, c, fx.ts.URL+"/no/such/path") |
| + if status != http.StatusNotFound || body != unrouted { |
| + t.Errorf("no engine = %d, want the plain 404", status) |
| + } |
| +} |
| + |
| +func TestDPAPDFEngineFailure(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + member := dpaMember(t, fx) |
| + docID, lhID := dpaWorld(t, fx) |
| + dpaAcceptFor(t, fx, docID, lhID) |
| + engine := dpaPDFEngineFor(t, fx) |
| + engine.status = http.StatusInternalServerError |
| + |
| + var logs bytes.Buffer |
| + prev := log.Writer() |
| + log.SetOutput(&logs) |
| + t.Cleanup(func() { log.SetOutput(prev) }) |
| + |
| + want := dpaPDFDeck(t, "PDF-C17") |
| + status, h, body := dpaGet(t, member, fx.u("/settings/dpa.pdf")) |
| + log.SetOutput(prev) |
| + if status != http.StatusBadGateway || !strings.Contains(oplText(body), want) { |
| + t.Fatalf("engine failure = %d, want 502 with %q:\n%s", status, want, body) |
| + } |
| + if cd := h.Get("Content-Disposition"); cd != "" || strings.Contains(h.Get("Content-Type"), "pdf") { |
| + t.Errorf("a failure answers as a download: %q %q", cd, h.Get("Content-Type")) |
| + } |
| + // The page is the record, so "print this page" prints the record. |
| + if !strings.Contains(oplText(body), "Ada Lovelace, Director (paul@keymail.dev)") { |
| + t.Errorf("the failure page is not the record:\n%s", body) |
| + } |
| + line := logs.String() |
| + if !strings.Contains(line, "dpa pdf "+fx.sqid) || !strings.Contains(line, "engine status 500") { |
| + t.Errorf("log = %q, want the sqid and the category", line) |
| + } |
| + if strings.Contains(line, fx.srv.cfg.PDFEngine) || strings.Contains(line, "engine trouble") || strings.Contains(line, "Shop") { |
| + t.Errorf("log carries more than the category: %q", line) |
| + } |
| + |
| + // A stored body that no longer passes canonicalAgreement: the same 502, |
| + // and the engine is not called. |
| + fx2 := newConsoleFixture(t) |
| + c2 := signInPaul(t, fx2) |
| + bad := dpaPublish(t, fx2, "1", "<section><script>alert(1)</script></section>\n", time.Now().Add(-time.Hour)) |
| + dpaAcceptFor(t, fx2, bad, dpaLetterhead(t, fx2, "Example Hosting Limited")) |
| + engine2 := dpaPDFEngineFor(t, fx2) |
| + if s, _, b := get(t, c2, fx2.u("/settings/dpa.pdf")); s != http.StatusBadGateway || !strings.Contains(oplText(b), want) { |
| + t.Errorf("render failure = %d, want 502 with %q", s, want) |
| + } |
| + if n := len(engine2.sent()); n != 0 { |
| + t.Errorf("engine called %d times for a body that failed the check", n) |
| + } |
| +} |
| + |
| +func TestDPARecordDownloadButton(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + member := dpaMember(t, fx) |
| + docID, lhID := dpaWorld(t, fx) |
| + dpaAcceptFor(t, fx, docID, lhID) |
| + dpaPDFEngineFor(t, fx) |
| + |
| + status, _, raw := get(t, member, fx.u("/settings/dpa")) |
| + if status != http.StatusOK { |
| + t.Fatalf("record = %d", status) |
| + } |
| + body := oplText(raw) |
| + for _, want := range []string{ |
| + `<a class="btn" href="` + fx.path("/settings/dpa.pdf") + `">` + dpaPDFDeck(t, "PDF-C16") + `</a>`, |
| + `<button type="button" class="btn-secondary" onclick="window.print()">` + oplDeck(t, "DPA-C39") + "</button>", |
| + } { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("record lacks %q:\n%s", want, body) |
| + } |
| + } |
| + if strings.Index(body, dpaPDFDeck(t, "PDF-C16")) > strings.Index(body, oplDeck(t, "DPA-C39")) { |
| + t.Errorf("Download PDF is not the first button") |
| + } |
| + |
| + // The owner's "none yet" page has nothing to download. |
| + fx2 := newConsoleFixture(t) |
| + c2 := signInPaul(t, fx2) |
| + dpaWorld(t, fx2) |
| + dpaPDFEngineFor(t, fx2) |
| + if _, _, none := get(t, c2, fx2.u("/settings/dpa")); strings.Contains(none, "dpa.pdf") { |
| + t.Errorf("the none-yet page offers a PDF:\n%s", none) |
| + } |
| +} |
| + |
| +func TestDPAAcceptEmailPDFLine(t *testing.T) { |
| + at := time.Date(2026, 11, 25, 9, 5, 0, 0, time.UTC) |
| + doc := &LegalDocument{Version: "3", URL: "https://example.com/dpa/3/", SHA256: "abc123"} |
| + lh := &Letterhead{Entity: "Example Hosting Limited", PrivacyAddress: "privacy@example.com"} |
| + a := DPAAcceptance{LegalName: "Shop Limited", Address: "1 Main Street", Country: "IE", |
| + SignerName: "Ada Lovelace", SignerRole: "Director", AcceptedBy: "ada@example.com", AcceptedAt: at} |
| + const record = "https://console.example.com/a/bab/settings/dpa" |
| + const pdf = "https://console.example.com/a/bab/settings/dpa.pdf" |
| + line := dpaPDFDeck(t, "PDF-C18", "pdf_url", pdf) |
| + |
| + _, with := dpaAcceptEmail(doc, lh, a, record, pdf) |
| + if !strings.Contains(with, record+"\n"+line+"\n\n") { |
| + t.Errorf("with an engine, the PDF line %q does not follow the record link:\n%s", line, with) |
| + } |
| + _, without := dpaAcceptEmail(doc, lh, a, record, "") |
| + if strings.Contains(without, "PDF") || strings.Contains(without, "dpa.pdf") { |
| + t.Errorf("without an engine, the email mentions a PDF:\n%s", without) |
| + } |
| + if with != strings.Replace(without, record+"\n", record+"\n"+line+"\n", 1) { |
| + t.Errorf("the PDF line changes more than its own line:\n%s\n---\n%s", with, without) |
| + } |
| + |
| + // Through the accept POST: the PDF URL is the console's own origin. |
| + for _, engine := range []bool{true, false} { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + csrf := sessionToken(t, fx, c) |
| + dpaWorld(t, fx) |
| + if engine { |
| + dpaPDFEngineFor(t, fx) |
| + } |
| + mail := dpaCaptureMail(fx) |
| + dpaFreshAs(t, fx, c, "paul@keymail.dev") |
| + h := dpaHidden(t, dpaSettings(t, fx, c)) |
| + if s, _, b := postForm(t, c, fx.u("/dpa/accept"), dpaPost(csrf, h)); s != http.StatusSeeOther { |
| + t.Fatalf("accept = %d:\n%s", s, b) |
| + } |
| + mail.mu.Lock() |
| + if len(mail.sent) != 1 { |
| + mail.mu.Unlock() |
| + t.Fatalf("%d deliveries, want 1", len(mail.sent)) |
| + } |
| + got := mail.sent[0].body |
| + mail.mu.Unlock() |
| + want := dpaPDFDeck(t, "PDF-C18", "pdf_url", fx.srv.cfg.Origin+fx.path("/settings/dpa.pdf")) |
| + if engine != strings.Contains(got, want) { |
| + t.Errorf("engine %v: email PDF line present = %v, want %v:\n%s", engine, !engine, engine, got) |
| + } |
| + } |
| +} |
diff --git a/internal/console/dparecord.go b/internal/console/dparecord.go| index 817fbc999..99b4be8ea 100644 |
| --- a/internal/console/dparecord.go |
| +++ b/internal/console/dparecord.go |
| @@ -1,7 +1,9 @@ |
| package console |
| import ( |
| + "context" |
| "errors" |
| + "fmt" |
| "log" |
| "net/http" |
| "strings" |
| @@ -29,6 +31,7 @@ type dpaRecordView struct { |
| DigestShort string |
| Processor string |
| SettingsURL string |
| + PDFURL string // the download, when an engine is configured |
| } |
| // dpaRecordWhenLayout is dpa.record.row.when's value format. |
| @@ -68,13 +71,45 @@ func (s *Server) handleDPARecord(w http.ResponseWriter, r *http.Request) { |
| if !ok { |
| return |
| } |
| - fail := func(what string, err error) { |
| - log.Printf("console: dpa record %s: %s: %v", acct.Sqid, what, err) |
| + s.renderDPARecord(w, r, addr, raw, acct, role, http.StatusOK, "") |
| +} |
| + |
| +// dpaLiveRecord is the account's acceptance in force and the document and |
| +// letterhead it names; all nil when none is in force. A gone document or |
| +// letterhead is an error. |
| +func (s *Server) dpaLiveRecord(ctx context.Context, accountID int64) (*DPAAcceptance, *LegalDocument, *Letterhead, error) { |
| + live, err := s.store.LiveDPA(ctx, accountID) |
| + if err != nil { |
| + return nil, nil, nil, fmt.Errorf("live acceptance: %w", err) |
| + } |
| + if live == nil { |
| + return nil, nil, nil, nil |
| + } |
| + doc, err := s.store.LegalDocument(ctx, live.DocumentID) |
| + if err != nil { |
| + return nil, nil, nil, fmt.Errorf("document: %w", err) |
| + } |
| + lh, err := s.store.LetterheadByID(ctx, live.LetterheadID) |
| + if err != nil { |
| + return nil, nil, nil, fmt.Errorf("letterhead: %w", err) |
| + } |
| + if doc == nil || lh == nil { |
| + return nil, nil, nil, fmt.Errorf("acceptance references: %w", errDPARecordMissing) |
| + } |
| + return live, doc, lh, nil |
| +} |
| + |
| +// renderDPARecord renders the record page for a viewer the caller has |
| +// admitted as a member, with status. failed, when set, is a banner: the |
| +// PDF download (dpapdfroute.go) answers its failure with this page. |
| +func (s *Server) renderDPARecord(w http.ResponseWriter, r *http.Request, addr, raw string, acct *Account, role string, status int, failed string) { |
| + fail := func(err error) { |
| + log.Printf("console: dpa record %s: %v", acct.Sqid, err) |
| http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| } |
| - live, err := s.store.LiveDPA(r.Context(), acct.ID) |
| + live, doc, lh, err := s.dpaLiveRecord(r.Context(), acct.ID) |
| if err != nil { |
| - fail("live acceptance", err) |
| + fail(err) |
| return |
| } |
| v := &dpaRecordView{SettingsURL: accountSettingsURL(acct.Sqid)} |
| @@ -84,23 +119,9 @@ func (s *Server) handleDPARecord(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| } else { |
| - doc, err := s.store.LegalDocument(r.Context(), live.DocumentID) |
| - if err != nil { |
| - fail("document", err) |
| - return |
| - } |
| - lh, err := s.store.LetterheadByID(r.Context(), live.LetterheadID) |
| - if err != nil { |
| - fail("letterhead", err) |
| - return |
| - } |
| docs, err := s.store.LegalDocuments(r.Context(), "dpa") |
| if err != nil { |
| - fail("documents", err) |
| - return |
| - } |
| - if doc == nil || lh == nil { |
| - fail("acceptance references", errDPARecordMissing) |
| + fail(fmt.Errorf("documents: %w", err)) |
| return |
| } |
| inForce := dpaInForce(*live, docs, nil, s.now()) |
| @@ -121,12 +142,18 @@ func (s *Server) handleDPARecord(w http.ResponseWriter, r *http.Request) { |
| v.InForce = inForce.Version |
| v.Digest, v.DigestShort = doc.SHA256, dpaShortDigest(doc.SHA256) |
| v.Processor = dpaRecordProcessorText(lh) |
| + if s.cfg.PDFEngine != "" { |
| + v.PDFURL = dpaPDFURL(acct.Sqid) |
| + } |
| } |
| p := s.accountPage(w, r, addr, raw, acct, role) |
| p.Title = "Data processing agreement" |
| p.ActiveNav = "settings" |
| p.DPARecord = v |
| - s.render(w, http.StatusOK, "dpa_record", p) |
| + if failed != "" { |
| + p.FlashErr = failed |
| + } |
| + s.render(w, status, "dpa_record", p) |
| } |
| // errDPARecordMissing: an acceptance names a document or letterhead that is gone. |
diff --git a/internal/console/perfwalk_test.go b/internal/console/perfwalk_test.go| index 974a8a725..f534bc9a2 100644 |
| --- a/internal/console/perfwalk_test.go |
| +++ b/internal/console/perfwalk_test.go |
| @@ -529,6 +529,9 @@ func perfTargets(fx *consoleFixture) map[string][]perfTarget { |
| for _, p := range []string{"billing", "billing/continue", "billing/done"} { |
| m["GET /a/{sqid}/"+p] = []perfTarget{{Path: fx.path("/" + p), Expect: http.StatusNotFound}} |
| } |
| + // The walk's world has no PDF engine (and the owner no acceptance), so |
| + // the DPA PDF answers the plain 404 before any render (dpapdfroute.go). |
| + m["GET /a/{sqid}/settings/dpa.pdf"] = []perfTarget{{Path: fx.path("/settings/dpa.pdf"), Expect: http.StatusNotFound}} |
| // GET /upgrade has no parameter but is gated the same way (billingpage.go). |
| m["GET /upgrade"] = []perfTarget{{Path: "/upgrade", Expect: http.StatusNotFound}} |
| // The operator billing pages answer the missing-route 404 with billing |
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go| index 28ba17b87..f9ce14ab0 100644 |
| --- a/internal/console/routedecls.go |
| +++ b/internal/console/routedecls.go |
| @@ -119,6 +119,7 @@ var routeDecls = []routeDecl{ |
| {Pattern: "POST /a/{sqid}/store/apply", Handler: (*Server).handleStoreApplyPage}, |
| {Pattern: "POST /a/{sqid}/dpa/accept", Handler: (*Server).handleDPAAccept}, |
| {Pattern: "GET /a/{sqid}/settings/dpa", Handler: (*Server).handleDPARecord}, |
| + {Pattern: "GET /a/{sqid}/settings/dpa.pdf", Handler: (*Server).handleDPAPDF}, |
| {Pattern: "GET /fleet/metrics", Handler: (*Server).handleFleetMetrics}, |
| // Fleet alerts (alertpages.go): the operator pages, same gate. Their |
| // writes are registered without a method, as the economics doors below |
diff --git a/internal/console/server.go b/internal/console/server.go| index 378d3d91f..b89f0ee5f 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1171,8 +1171,12 @@ type Server struct { |
| // at its own server. dpaAcceptHook, when set (tests only), runs in |
| // handleDPAAccept after its checks and before the acceptance is |
| // recorded (dpapane.go). |
| - legalHTTP *http.Client |
| - dpaAcceptHook func() |
| + legalHTTP *http.Client |
| + dpaAcceptHook func() |
| + // dpaPDFHTTP posts the DPA PDF's HTML to the PDF engine |
| + // (dpapdfroute.go): newDPAPDFClient, set in NewServer; a test may |
| + // replace it. |
| + dpaPDFHTTP *http.Client |
| alertSeal atomic.Pointer[connectorSeal] |
| alertTests alertTestWindow |
| alertClock func() time.Time |
| @@ -2081,6 +2085,7 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| billing: newBillingRuntime(cfg.Billing), |
| seen: map[string]time.Time{}, |
| legalHTTP: newLegalHTTPClient(), |
| + dpaPDFHTTP: newDPAPDFClient(), |
| } |
| s.initMedia() |
| if capacity, err := parseHACapacityConfig(cfg.HACapacityConfig, cfg.HARegions, cfg.HomeRegion); err != nil { |
diff --git a/internal/console/templates/dpa_record.html b/internal/console/templates/dpa_record.html| index 28374f22a..54129e173 100644 |
| --- a/internal/console/templates/dpa_record.html |
| +++ b/internal/console/templates/dpa_record.html |
| @@ -5,6 +5,7 @@ |
| <h1>Data processing agreement</h1> |
| <p class="lede">The record of what was accepted, and by whom.</p> |
| </div> |
| +{{with $.FlashErr}}<p class="banner error no-print">{{.}}</p>{{end}} |
| {{if .Live}}<div class="tablewrap"> |
| <table> |
| <tr><th>Customer</th><td>{{.LegalName}}<br>{{range .AddressLines}}{{.}}<br>{{end}}{{.Country}}</td></tr> |
| @@ -17,7 +18,8 @@ |
| </table> |
| </div> |
| <p class="small">The fingerprint changes if a single character of the agreement changes, so it proves which text was accepted.</p> |
| -<p class="no-print"><button type="button" onclick="window.print()">Print this record</button> |
| +<p class="no-print">{{if .PDFURL}}<a class="btn" href="{{.PDFURL}}">Download PDF</a> |
| +<button type="button" class="btn-secondary" onclick="window.print()">Print this record</button>{{else}}<button type="button" onclick="window.print()">Print this record</button>{{end}} |
| <a class="btn btn-secondary" href="{{.SettingsURL}}">Back to settings</a></p> |
| {{else}}<p>No agreement is in force yet. You can accept one in account settings.</p> |
| <p class="no-print"><a class="btn btn-secondary" href="{{.SettingsURL}}">Back to settings</a></p> |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index 79cd853f6..864fb88f7 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -65,6 +65,7 @@ route GET /a/{sqid}/index |
| route GET /a/{sqid}/plan/keep |
| route GET /a/{sqid}/settings |
| route GET /a/{sqid}/settings/dpa |
| +route GET /a/{sqid}/settings/dpa.pdf |
| route GET /a/{sqid}/team |
| route GET /a/{sqid}/trash |
| route GET /a/{sqid}/{$} |
diff --git a/internal/provision/dpa_pdf_census_test.go b/internal/provision/dpa_pdf_census_test.go| new file mode 100644 |
| index 000000000..26d4df232 |
| --- /dev/null |
| +++ b/internal/provision/dpa_pdf_census_test.go |
| @@ -0,0 +1,36 @@ |
| +package provision |
| + |
| +// dpaPDFWriteCensusInventory is the record-write census for branch dpa-pdf |
| +// (the DPA as a PDF, DPA and retention spec §3.8), layered on |
| +// certImport1429WriteCensusInventory (the inventory |
| +// TestPlan9B8RecordWriteCensus used before this branch). Reviewed by the |
| +// branch author against the source. No record write is added, moved or |
| +// reclassified; one key-site table is re-pinned: |
| +// |
| +// - var routeDecls (console): one new declaration, GET |
| +// /a/{sqid}/settings/dpa.pdf (handleDPAPDF, dpapdfroute.go), for |
| +// account members. It reads the console database's legal tables and |
| +// posts HTML to the PDF engine; it writes nothing, and reads or writes |
| +// no app record, sidecar or bucket object. The instances and sidecars |
| +// literals are unchanged: still key-site. |
| +func dpaPDFWriteCensusInventory() []censusEntry { |
| + entries := append([]censusEntry(nil), certImport1429WriteCensusInventory()...) |
| + repins := []censusEntry{ |
| + {"internal/console/routedecls.go", "var routeDecls", "key-site", "lit:instances,lit:sidecars", "185c96c2315a3653c11521806e97df2a07bb2c6c2948a358983a30948b2a39ff"}, |
| + } |
| + for _, r := range repins { |
| + found := false |
| + for i, e := range entries { |
| + if e.File == r.File && e.Unit == r.Unit { |
| + if e.Class != r.Class || e.Kinds != r.Kinds { |
| + panic("dpa-pdf re-pin changes the class or kinds of " + r.File + ":" + r.Unit) |
| + } |
| + entries[i], found = r, true |
| + } |
| + } |
| + if !found { |
| + panic("dpa-pdf re-pin of an unlisted unit " + r.File + ":" + r.Unit) |
| + } |
| + } |
| + return entries |
| +} |
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go| index 48e48cf01..520b27bc4 100644 |
| --- a/internal/provision/plan9_b8_census_test.go |
| +++ b/internal/provision/plan9_b8_census_test.go |
| @@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) { |
| if len(got) < 100 { |
| t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root) |
| } |
| - inventory := certImport1429WriteCensusInventory() |
| + inventory := dpaPDFWriteCensusInventory() |
| problems := append(censusDiff(inventory, got), censusPolicy(inventory)...) |
| if len(problems) > 0 { |
| t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n ")) |
diff --git a/parity/parity.tsv b/parity/parity.tsv| index 2671e1202..066ac3e2a 100644 |
| --- a/parity/parity.tsv |
| +++ b/parity/parity.tsv |
| @@ -184,7 +184,7 @@ cli-tokens account gap GET /settings ; GET /auth/cli/tokens ; POST /auth/cli/to |
| auth-login account cli-only auth login Signs this terminal in; the browser half is an auth row. |
| auth-identity account cli-only auth whoami ; auth logout ; auth default This terminal's own identity and default console. |
| account-delete account console-only POST /a/{sqid}/delete Deleting an account needs a passkey. |
| -dpa-accept account console-only GET /a/{sqid}/settings ; GET /a/{sqid}/settings/dpa ; POST /a/{sqid}/dpa/accept An owner accepts the data processing agreement, and confirms with a passkey. |
| +dpa-accept account console-only GET /a/{sqid}/settings ; GET /a/{sqid}/settings/dpa ; GET /a/{sqid}/settings/dpa.pdf ; POST /a/{sqid}/dpa/accept An owner accepts the data processing agreement, and confirms with a passkey. |
| plan-keep account gap GET /a/{sqid}/plan/keep ; POST /a/{sqid}/plan/keep wp-cli-verbs Choosing which apps to keep when a plan lapses. |
| getting-started account console-only POST /a/{sqid}/getting-started/hide ; POST /a/{sqid}/getting-started/show ; POST /a/{sqid}/getting-started/skip ; POST /a/{sqid}/getting-started/done A checklist in the page. |
| nav-index account console-only GET /a/{sqid}/index ; GET /a/{sqid}/apps/{app}/index ; GET /a/{sqid}/apps/{app}/settings/index Phone navigation pages that list sections. |