panel-redesign: paths follow the menu; Account and Server settings split

Stage 1, step 3 (plan § Routes). BREAKING: every panel URL changes and the
old paths are removed without redirects.

Routes (web.go)
  - /status -> /overview; /domains -> /outbound/domains with the domain's
    settings actions under .../settings/ (reports, ratelimit, export);
    /deliveries -> /outbound/log; /mail-queue -> /outbound/queue; /dmarc ->
    /outbound/dmarc; /inbound -> /inbound/domains; /system-log ->
    /server/log; /backup -> /server/backup (import under it); /users ->
    /server/users; recheck and reload under /server/health/.
  - One fragment name: <page>/fragment everywhere.
  - Everything under /server/ is registered through server(), which wraps
    the handler in globalOnly: the subtree is guarded once, where a new
    route cannot forget it. Handlers keep their own requireGlobal.
  - GET / leads to /overview, /outbound/domains or /inbound/domains.
  - The /account -> /settings redirect is gone with /settings.

Account and Server > Settings
  - handlers_account.go: GET /account and three POSTs - profile (username,
    e-mail; no password asked, as designed), password (current password,
    rate-limited like a sign-in, signs out other sessions), dmarc (the
    user's default: hosted / account / custom / none, each validated).
    This replaces step 1's bridge through the old Settings form.
  - handlers_settings.go is the instance's page only: log retention and the
    read-only rate limits, global role.
  - One legacy template serves both pages by a flag until stage 2 gives each
    its own: a new legacy page cannot be added to the ratchet.

Still to come inside stage 1, and why @routes stays on the ratchet:
  - step 4: the application routes (one POST, under the domain);
  - step 5: GET /server/health.
With @routes removed by hand TestRoutesFollowNavigation reports exactly
those and nothing else - no template links to a path the router lacks.

Old templates, tests and the e2e client are retargeted. The e2e module was
edited but not run here (no Docker, and its dependency could not be
downloaded on this machine).

Tests: Account (page, profile, password, DMARC default in every mode, a
domain administrator's own row only), Server settings (saved without a
password, range, global only), the /server/ subtree answered 404 by the
router for a domain administrator with All on both lists and for no
principal.

go test ./...  green except the two Windows-only failures in internal/domain
and internal/logtail.

Roadmap 13/27.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mix
2026-10-09 21:51:55 +03:00
co-authored by Claude Opus 5.5
parent 3b86f6c3b6
commit bd746c61d7
55 changed files with 1006 additions and 692 deletions
+38 -4
View File
@@ -3,6 +3,7 @@ package web
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/mixeme/selfpost/internal/web/auth"
@@ -15,10 +16,10 @@ func TestRedirectHomeFollowsTheReach(t *testing.T) {
p auth.Principal
want string
}{
{"global", auth.Principal{Role: auth.RoleGlobal}, "/status"},
{"outbound", auth.Principal{Role: auth.RoleDomain, Domains: []int64{1}}, "/domains"},
{"both", auth.Principal{Role: auth.RoleDomain, AllDomains: true, AllInbound: true}, "/domains"},
{"inbound only", auth.Principal{Role: auth.RoleDomain, InboundDomains: []int64{1}}, "/inbound"},
{"global", auth.Principal{Role: auth.RoleGlobal}, "/overview"},
{"outbound", auth.Principal{Role: auth.RoleDomain, Domains: []int64{1}}, "/outbound/domains"},
{"both", auth.Principal{Role: auth.RoleDomain, AllDomains: true, AllInbound: true}, "/outbound/domains"},
{"inbound only", auth.Principal{Role: auth.RoleDomain, InboundDomains: []int64{1}}, "/inbound/domains"},
} {
rec := httptest.NewRecorder()
redirectHome(rec, auth.RequestWithPrincipal(httptest.NewRequest(http.MethodGet, "/", nil), tc.p))
@@ -27,3 +28,36 @@ func TestRedirectHomeFollowsTheReach(t *testing.T) {
}
}
}
// Everything under /server/ is the global role's, and the subtree is guarded
// where the routes are registered: a domain administrator — whatever they are
// assigned — and a request with no principal get 404 from the router itself,
// before any handler runs. The handlers here are nil; reaching one would panic.
func TestServerSubtreeIsGlobalOnly(t *testing.T) {
_, authed := (&Server{cfg: Config{InboundEnabled: true, DMARCEnabled: true}}).muxes()
everything := auth.Principal{Role: auth.RoleDomain, AllDomains: true, AllInbound: true}
checked := 0
for _, pattern := range routes.always {
method, target := concrete(pattern)
if !strings.HasPrefix(target, "/server/") {
continue
}
if got := answers(authed, method, target); got == "" {
continue // not built yet; TestRoutesFollowNavigation reports it
}
checked++
for who, req := range map[string]*http.Request{
"a domain administrator with All on both lists": auth.RequestWithPrincipal(httptest.NewRequest(method, target, nil), everything),
"no principal": httptest.NewRequest(method, target, nil),
} {
rec := httptest.NewRecorder()
authed.ServeHTTP(rec, req)
if rec.Code != http.StatusNotFound {
t.Errorf("%s %s as %s = %d, want 404", method, target, who, rec.Code)
}
}
}
if checked < 15 {
t.Fatalf("only %d /server/ routes were checked", checked)
}
}