console: DPA pane names the processor and links the version
Branch review finding P2-5. Above the agreement and the form, the pane shows the processor from the letterhead the form binds (the record page's Processor label and line, VAT when set), a "Read version" link to the document's page, and the version's summary, all escaped. No new copy: the strings are deck rows DPA-C23 and DPA-C35 to C37.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+75
−3
internal/console/dpapane.go+9 −3internal/console/dpapane_test.go+59 −0internal/console/templates/account_settings.html+7 −0
diff --git a/internal/console/dpapane.go b/internal/console/dpapane.go| index e39fddf60..8f58c9eef 100644 |
| --- a/internal/console/dpapane.go |
| +++ b/internal/console/dpapane.go |
| @@ -21,8 +21,9 @@ import ( |
| // |
| // The pane renders only when a letterhead is set and a dpa document is |
| // published. An owner of an account with no acceptance in force sees the |
| -// newest published version (even one not yet effective), its stored text, |
| -// and a form for the customer's details. The form is bound to what was |
| +// newest published version (even one not yet effective): the processor from |
| +// the letterhead the form binds, a link to the version's page and its |
| +// summary, its stored text, and a form for the customer's details. The form is bound to what was |
| // shown: it carries the document's id and digest and the letterhead's id, |
| // and the POST, and the step-up replay of it, records nothing unless all |
| // three are still current. A member sees the in-force line or a line saying |
| @@ -148,8 +149,11 @@ type dpaPane struct { |
| // Body is Doc's stored agreement, re-checked canonical at render time. |
| Body template.HTML |
| - // The rendered lines and links. |
| + // The rendered lines and links. Processor (dpa.record.processor) is |
| + // from Letterhead, the one the form binds; DocLink |
| + // (dpa.pane.pending_link) links Doc's page. |
| AgreementHeading, ChangedText string |
| + Processor, DocLink string |
| InForceLine, PendingLine, PendingLink string |
| ObjectLine, RecordURL string |
| Countries []dpaCountry |
| @@ -217,6 +221,8 @@ func (s *Server) dpaPaneFor(ctx context.Context, p *page, acct *Account, role st |
| pane.State = "form" |
| pane.Body = template.HTML(doc.Body) // canonicalAgreement just passed |
| pane.AgreementHeading = dpaAgreementHeading(doc.Version) |
| + pane.Processor = dpaRecordProcessorText(lh) |
| + pane.DocLink = dpaPendingLinkText(doc.Version) |
| pane.Countries = dpaCountries |
| } |
| p.DPA = pane |
diff --git a/internal/console/dpapane_test.go b/internal/console/dpapane_test.go| index d38ec99f4..f478a50e7 100644 |
| --- a/internal/console/dpapane_test.go |
| +++ b/internal/console/dpapane_test.go |
| @@ -2,6 +2,7 @@ package console |
| import ( |
| "context" |
| + "html" |
| "net/http" |
| "net/url" |
| "regexp" |
| @@ -397,6 +398,10 @@ func TestDPAAcceptStaleLetterhead(t *testing.T) { |
| if dpaHidden(t, body)["letterhead_id"] != itoa64(lh2) { |
| t.Errorf("the pane is not bound to the new letterhead") |
| } |
| + if text := oplText(body); !strings.Contains(text, "Example Hosting Group Limited, 1 Main Street, Dublin.") || |
| + strings.Contains(text, "Example Hosting Limited,") { |
| + t.Errorf("the re-rendered pane does not name the new letterhead's processor:\n%s", body) |
| + } |
| } |
| func TestDPAAcceptStaleAfterStepUpReplay(t *testing.T) { |
| @@ -599,3 +604,57 @@ func TestDPAAcceptOwnerRemovedMidRequest(t *testing.T) { |
| t.Fatalf("%d rows recorded for a removed owner", n) |
| } |
| } |
| + |
| +// The pane names the processor from the letterhead its form binds, links |
| +// the version's page, and shows the version's summary, all escaped. |
| +func TestDPAPaneShowsProcessorAndDocument(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + const summary = "We added <b>a</b> subprocessor & a region." |
| + eff := time.Now().Add(-time.Hour) |
| + docID, err := fx.st.PublishLegalDocument(t.Context(), LegalDocument{Kind: "dpa", Version: "1", |
| + URL: "https://example.com/dpa/1/?a=1&b=2", Body: oplFragment, SHA256: oplDigest([]byte(oplFragment)), |
| + Summary: summary, PublishedAt: eff, EffectiveAt: &eff, PublishedBy: "paul@keymail.dev"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + dpaLetterhead(t, fx, "Old Hosting Limited") |
| + lh := Letterhead{Entity: "Example <Hosting> Limited", RegisteredOffice: "1 Main Street, Dublin", |
| + CompanyNumber: "123456", VATNumber: "IE999", Signatory: "For Example Hosting Limited", |
| + PrivacyAddress: "privacy@example.com", CreatedBy: "paul@keymail.dev", CreatedAt: time.Now()} |
| + lhID, err := fx.st.SetLetterhead(t.Context(), lh) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + body := dpaSettings(t, fx, c) |
| + h := dpaHidden(t, body) |
| + if h["letterhead_id"] != itoa64(lhID) || h["document_id"] != itoa64(docID) { |
| + t.Fatalf("binding = %v, want document %d and letterhead %d", h, docID, lhID) |
| + } |
| + processor := oplDeck(t, "DPA-C36", "entity", lh.Entity, "office", lh.RegisteredOffice, "company_number", "123456") + |
| + " " + oplDeck(t, "DPA-C37", "vat_number", "IE999") |
| + for _, want := range []string{ |
| + "<p><strong>" + oplDeck(t, "DPA-C35") + "</strong><br>" + html.EscapeString(processor) + "</p>", |
| + `<p class="small">` + html.EscapeString(summary) + "</p>", |
| + `<a href="https://example.com/dpa/1/?a=1&b=2">` + oplDeck(t, "DPA-C23", "version", "1") + "</a>", |
| + } { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("the pane lacks %q:\n%s", want, body) |
| + } |
| + } |
| + // Escaped, and the current letterhead's, not the earlier one's. |
| + if strings.Contains(body, "<Hosting>") || strings.Contains(body, "<b>a</b>") { |
| + t.Error("the processor or summary is not escaped") |
| + } |
| + if strings.Contains(body, "Old Hosting Limited") { |
| + t.Error("the pane names a letterhead the form does not bind") |
| + } |
| + // Above the form, and the agreement still as stored. |
| + if strings.Index(body, html.EscapeString(processor)) > strings.Index(body, `<form class="dpa-form"`) { |
| + t.Error("the processor is below the form") |
| + } |
| + if !strings.Contains(body, `<div class="agreement">`+oplFragment+"\n</div>") { |
| + t.Error("the agreement body is not rendered as stored") |
| + } |
| +} |
diff --git a/internal/console/templates/account_settings.html b/internal/console/templates/account_settings.html| index 137238860..facccd41c 100644 |
| --- a/internal/console/templates/account_settings.html |
| +++ b/internal/console/templates/account_settings.html |
| @@ -225,6 +225,13 @@ start with analytics on.</p> |
| <p class="error">{{.}}</p> |
| {{- end}} |
| <h3>{{.AgreementHeading}}</h3> |
| +{{/* Who the processor is, from the letterhead the form below binds, and |
| + the version's own page and summary. */ -}} |
| +<p><strong>Processor</strong><br>{{.Processor}}</p> |
| +{{- with .Doc.Summary}} |
| +<p class="small">{{.}}</p> |
| +{{- end}} |
| +<p class="small"><a href="{{.Doc.URL}}">{{.DocLink}}</a></p> |
| {{/* The agreement passed canonicalAgreement at render time (dpapane.go). |
| The newline straight after it is load-bearing: a trailing character |
| reference in the fragment is only harmless before a newline. */ -}} |