panel-redesign: three choices for a domain's report address; row actions

Follows the design and guard commits before it. Written by Sonnet,
reviewed by Opus.

The report address
  - Baseline: users.dmarc_default_mode, users.dmarc_default_address and
    domains.dmarc_rua_user_id are gone. domains.dmarc_rua alone says
    where reports go: '' is no reports (a new domain), the address
    SelfPost derives for the domain is the hosted choice (while hosted
    reports are on), anything else is a typed address.
  - Removed: the user default and its store functions, a domain
    following a user, keep / inherit, followCreator, POST /account/dmarc
    with its handler, the DMARC box of Account, the user-delete item
    about domains losing their address.
  - Domain settings offers the three choices; beside the typed address a
    "Use my e-mail" button fills in the profile e-mail (panel.js: one
    generic data-fill hook; absent without a profile e-mail; it fills,
    it does not save).
  - The DMARC record's note names the address and no user. This closes
    L4 of the security review.
  - Domain export / import carries the address as a plain string.
  - The ingest allow-list is the generic mailbox plus each domain's
    address on this host; the generic mailbox is always open now.
  - dev/migrate1x (not in the tree): a 1.x domain that inherited the
    instance default gets that address as its own, so no published rua=
    changes.

Row actions
  - row_action partial (RowAction: Label, Post, Confirm, Danger);
    panel.css has the mockup's three rules. A row of the Applications
    table is Edit, New password, Delete; the confirmation texts are the
    ones the application page's head uses. Both roles, with the checks
    of the application page.

Tests cover: a new domain has no reports; each choice saved and shown
selected; hosted refused when hosted reports are off; a bad address
refused with what was typed kept; an untouched save changes nothing in
each state; the fill button with and without a profile e-mail; deleting
a user leaves every domain's address; the row's forms, targets and
confirmations for both roles and a 404 for a stranger.

Known: if hosted reports are switched off later, a stored hosted address
reads as a typed one. docs/guide.md still describes the old choices -
the documentation step.

Evidence
  - docs/assets/panel-redesign/evidence/account.png,
    out-domain-settings.png, out-domain.png, user-delete.png, help.png:
    1440 px wide, headless Edge, real templates served locally with
    their fixtures - NOT from the container.
  - panel/audit.js on out-domain, out-domain-settings, account, help,
    components and user-delete at 1440 and 1280: 1420 texts checked,
    problems: [].
  - In a browser: the fill button sets the field and does not submit;
    the row buttons have the font, size and colour of the Edit link,
    Delete the red of the other delete links; data-confirm fires on
    both. Hover and focus states were not observed.
  - go test -count=1 ./internal/web/... ./internal/store/...
    ./internal/dmarc/... ./internal/app/... ./internal/inbound/...
    ./cmd/panel: ok (ten packages; dev/migrate1x also ok).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mix
2026-10-10 12:38:35 +03:00
co-authored by Claude Opus 5.5
parent e15f8896c5
commit 96db0b7a86
49 changed files with 768 additions and 1214 deletions
@@ -6,10 +6,7 @@ import (
"strings"
"testing"
"github.com/mixeme/selfpost/internal/dmarc"
"github.com/mixeme/selfpost/internal/postfix"
"github.com/mixeme/selfpost/internal/store"
"github.com/mixeme/selfpost/internal/web/auth"
)
// The user form sets the account e-mail: create stores it, an edit changes it,
@@ -100,92 +97,3 @@ func TestUserFormRefusesABadEmailAndKeepsWhatWasTyped(t *testing.T) {
t.Errorf("a bad address on create = %d, user created: %v", rec.Code, fresh.ID != 0)
}
}
type countingMaps struct{ n int }
func (c *countingMaps) RebuildDMARCMaps(postfix.DMARCMapsConfig) error { c.n++; return nil }
// Changing the e-mail of a user whose default report address is "my account
// e-mail" rebuilds the ingest allow-list, exactly as the Account page does; for
// anyone else, or when the address is not changed, nothing is rebuilt.
func TestUserFormEmailChangeResyncsDMARCOnlyForTheAccountDefault(t *testing.T) {
h, st := inboundHandlers(t)
maps := &countingMaps{}
h.dmarc = dmarc.NewService(st, maps, "mail.example.org", true)
root := userWith(t, st, "root", store.RoleGlobal, store.Reach{})
follower := userWith(t, st, "follower", store.RoleGlobal, store.Reach{})
other := userWith(t, st, "other", store.RoleGlobal, store.Reach{})
if err := st.SetDMARCDefault(follower.ID, store.DMARCDefaultAccount, ""); err != nil {
t.Fatal(err)
}
save := func(who auth.Principal, email string) {
t.Helper()
rec := send(h.HandleUserEdit, &root, "POST", "/server/users/"+idStr(who.ID), map[string]string{"uid": idStr(who.ID)},
url.Values{"username": {who.Username}, "email": {email}, "role": {"global"}})
if rec.Code != http.StatusSeeOther {
t.Fatalf("save %s = %d:\n%s", who.Username, rec.Code, rec.Body.String())
}
}
save(other, "other@example.org")
if maps.n != 0 {
t.Errorf("a user whose default is not the account e-mail rebuilt the maps %d time(s)", maps.n)
}
save(follower, "follower@example.org")
if maps.n != 1 {
t.Errorf("changing the account e-mail of a follower rebuilt the maps %d time(s), want 1", maps.n)
}
save(follower, "follower@example.org")
if maps.n != 1 {
t.Errorf("saving the same address again rebuilt the maps (%d)", maps.n)
}
}
// Deleting a user leaves every domain that follows their default report address
// with none; the confirmation says which, and says nothing of the kind when no
// domain follows.
func TestUserDeleteConfirmationNamesTheDomainsThatLoseTheirReportAddress(t *testing.T) {
h, st := inboundHandlers(t)
root := userWith(t, st, "root", store.RoleGlobal, store.Reach{})
u := userWith(t, st, "shop", store.RoleGlobal, store.Reach{})
path, pv := "/server/users/"+idStr(u.ID)+"/delete", map[string]string{"uid": idStr(u.ID)}
page := func() string { return send(h.HandleUserDeleteConfirm, &root, "GET", path, pv, nil).Body.String() }
if body := page(); strings.Contains(body, "DMARC report address") {
t.Errorf("no domain follows the user, yet the page speaks of DMARC:\n%s", body)
}
var follows []store.Domain
for _, name := range []string{"a.example.com", "b.example.com", "c.example.com", "d.example.com"} {
d, _ := st.AddDomain(name, "mail")
if err := st.SetDomainDMARCUser(d.ID, u.ID); err != nil {
t.Fatal(err)
}
follows = append(follows, d)
}
elsewhere, _ := st.AddDomain("z.example.com", "mail")
if err := st.SetDomainDMARCUser(elsewhere.ID, root.ID); err != nil {
t.Fatal(err)
}
body := page()
want := `<strong>a.example.com</strong>, <strong>b.example.com</strong>, <strong>c.example.com</strong> and 1 more will have no DMARC report address until someone sets one.`
if !strings.Contains(body, want) {
t.Errorf("the delete page is missing %q:\n%s", want, body)
}
if strings.Contains(body, "z.example.com") || strings.Contains(body, "d.example.com") {
t.Error("the page names a domain that does not follow this user, or spells out a fourth name")
}
// What it says is what happens: the follower domains end up with no address.
if rec := send(h.HandleUserDelete, &root, "POST", path, pv, url.Values{}); rec.Code != http.StatusSeeOther {
t.Fatalf("delete = %d", rec.Code)
}
for _, d := range follows {
got, _ := st.GetDomain(d.ID)
rua, err := st.DomainDMARCRua(got, "")
if err != nil || rua != "" {
t.Errorf("%s still reports to %q (%v) after its user was deleted", d.Name, rua, err)
}
}
}