Phase 9, part 1: editions and their settings

SUPERMARKET_MODE picks local (the default), server or multi. internal/config
reads and checks every setting the editions need (database, secret key,
storage, the app's own mail, an https address), reporting all problems at
once. supermarket config prints them without passwords; supermarket
secret-key makes a key. Settings -> About shows the edition. Server and
multi-tenant are checked but refuse to start until they're built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 06:55:30 -07:00
co-authored by Claude Opus 5.5
parent 338eaa2c79
commit 7a857c7346
12 changed files with 671 additions and 9 deletions
+44
View File
@@ -0,0 +1,44 @@
package web
import (
"net/http"
"os"
"supermarket/internal/config"
"supermarket/internal/db"
)
// config is how this Supermarket is run: the local edition's defaults when
// none was given (tests).
func (s *Server) config() *config.Config {
if s.Config != nil {
return s.Config
}
c, _ := config.Load(func(k string) string {
switch k {
case config.EnvData, config.EnvHostData:
return s.DataDir
case config.EnvPublicURL:
return s.PublicURL
case config.EnvMode:
return ""
}
return os.Getenv(k)
})
return c
}
type aboutData struct {
Edition config.Edition
Version string
Schema int
Items []config.Item
}
// aboutPage shows the edition and how it's run (Settings → About).
func (s *Server) aboutPage(w http.ResponseWriter, r *http.Request) {
c := s.config()
s.render(w, r, "about", page{Title: "About", Nav: "settings/about", Data: aboutData{
Edition: c.Edition, Version: s.Version, Schema: db.Schema(), Items: c.Summary(),
}})
}
+3
View File
@@ -14,6 +14,7 @@ import (
"regexp"
"strconv"
"strings"
"supermarket/internal/config"
"sync"
"time"
"unicode"
@@ -42,6 +43,7 @@ var staticFS embed.FS
// Server holds what the handlers need.
type Server struct {
Config *config.Config // how it's run; nil in tests: the local edition
DB *db.DB
Secrets *secrets.Store
Core *core.Core // nil without a Core
@@ -259,6 +261,7 @@ func (s *Server) Handler() (http.Handler, error) {
mux.HandleFunc("POST /settings/backups/{action}", s.backupsAction)
mux.HandleFunc("GET /settings/backups/file/{name}", s.backupDownload)
mux.HandleFunc("POST /settings/backups/upload", s.backupUpload)
mux.HandleFunc("GET /settings/about", s.aboutPage)
mux.HandleFunc("GET /settings/core", s.corePage)
mux.HandleFunc("GET /settings/core/checks", s.coreChecks)
+16
View File
@@ -739,3 +739,19 @@ func TestRedirectKeepsFragmentLast(t *testing.T) {
}
}
}
// Settings → About shows the edition, and where the local edition keeps
// its database.
func TestAboutPage(t *testing.T) {
s, h := newTestServer(t, nil)
rec := do(h, "GET", "/settings/about", nil, nil)
if rec.Code != 200 {
t.Fatal(rec.Code)
}
body := rec.Body.String()
for _, want := range []string{"Local edition", "SQLite: " + s.DataDir + "/app.db", "SUPERMARKET_MODE", `href="/settings/about" aria-current="page"`} {
if !strings.Contains(body, want) {
t.Errorf("no %q", want)
}
}
}
+5
View File
@@ -481,3 +481,8 @@ svg.line-chart line.axis { stroke: hsl(var(--border)); }
.next-item .next-head h3 { margin: 0; }
.next-item .next-head p { margin: 0 0 0.15rem; }
.next-rank { flex: none; width: 1.9rem; height: 1.9rem; border-radius: 999px; display: grid; place-items: center; font-weight: 600; background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
/* Settings → About: name and value pairs */
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.6rem 1.2rem; margin: 0.5rem 0 0.8rem; }
dl.facts dt { font-weight: 600; color: hsl(var(--muted-foreground)); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
+16
View File
@@ -0,0 +1,16 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}
<h2>About</h2>
<p class="lede">This Supermarket: its edition, its version, and where it keeps things.</p>
<section class="card">
<h2>{{.Edition.Name}} edition</h2>
<dl class="facts">
<dt>Version</dt><dd>{{.Version}} <span class="muted">· database schema {{.Schema}}</span></dd>
{{range .Items}}<dt>{{.Name}}</dt><dd>{{.Value}}{{if .Help}} <span class="help">{{.Help}}</span>{{end}}</dd>
{{end}}
</dl>
{{if eq (print .Edition) "local"}}
<p class="help">Supermarket also comes as a <strong>server</strong> edition, for a team signing in on a server, and a <strong>multi-tenant</strong> one, for many teams at one address. The edition is chosen with <code>SUPERMARKET_MODE</code> when it starts; <code>supermarket config</code> checks the settings.</p>
{{end}}
</section>
{{end}}{{template "settings-end"}}{{end}}
+2
View File
@@ -136,6 +136,7 @@
<a href="/settings/ai" {{if eq .Nav "settings/ai"}}aria-current="page"{{end}}>{{template "icon" "ai"}}AI</a>
<div class="nav-label">Data</div>
<a href="/settings/backups" {{if eq .Nav "settings/backups"}}aria-current="page"{{end}}>{{template "icon" "backups"}}Backups</a>
<a href="/settings/about" {{if eq .Nav "settings/about"}}aria-current="page"{{end}}>{{template "icon" "info"}}About</a>
</nav>
<div class="settings-body">
{{end}}
@@ -183,6 +184,7 @@
{{- else if eq . "accounts"}}<circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><path d="m8.59 13.51 6.83 3.98"/><path d="m15.41 6.51-6.82 3.98"/>
{{- else if eq . "ai"}}<path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2"/><path d="M20 14h2"/><path d="M15 13v2"/><path d="M9 13v2"/>
{{- else if eq . "core"}}<path d="M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z"/><path d="m2 22 3-3"/><path d="M7.5 13.5 10 11"/><path d="M10.5 16.5 13 14"/><path d="m18 3-4 4h6l-4 4"/>
{{- else if eq . "info"}}<circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/>
{{- else if eq . "backups"}}<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>
{{- else if eq . "chevron"}}<path d="m6 9 6 6 6-6"/>
{{- else if eq . "menu"}}<path d="M4 12h16"/><path d="M4 6h16"/><path d="M4 18h16"/>