feat: legal notice and privacy policy as Markdown or link

Admins set the platform's documents, linked in the footer of the console
and sign-in pages and served at /legal/<kind>. Organizations set their
own for their status pages, falling back to the platform's. Documents
travel in the status page snapshot, so status page servers serve them at
/<slug>/imprint and /imprint on custom domains during API outages too.
Markdown is rendered with goldmark, which drops raw HTML and unsafe
links; stored links must be http or https.

Closes #67

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 10:17:39 +01:00
1 parent 4134af4aef
commit 73eb0f8bcd
26 files changed
+1278 -64

No files matched your search

+46 -9
View File
@@ -192,36 +192,73 @@ func (s *Server) serve(c *gin.Context) {
return
}
host := hostOnly(c.Request.Host)
var key, slug string
parts := strings.Split(strings.Trim(c.Request.URL.Path, "/"), "/")
var key, slug, base, legal string
custom := s.IsCustomDomain(host)
switch {
case s.IsCustomDomain(host):
if c.Request.URL.Path != "/" {
case custom:
key, base = "host:"+host, "/"
if len(parts) > 1 {
c.Status(http.StatusNotFound)
return
}
key = "host:" + host
default:
slug = strings.Trim(c.Request.URL.Path, "/")
if slug == "" || strings.Contains(slug, "/") {
slug = parts[0]
if len(parts) == 2 {
legal = parts[1]
}
if slug == "" || len(parts) > 2 {
c.Status(http.StatusNotFound)
return
}
key, host = "slug:"+slug, ""
key, host, base = "slug:"+slug, "", "/"+slug+"/"
}
if custom {
legal = parts[0]
}
e, ok := s.lookup(c.Request.Context(), key, host, slug)
if !ok {
c.Status(http.StatusNotFound)
return
}
if legal != "" {
s.serveLegal(c, e, legal, base)
return
}
var staleSince time.Time
if s.now().Sub(e.Fetched) > staleNoticeAfter {
staleSince = e.Fetched
}
s.localizeRequest(c)
c.Header("Cache-Control", "public, max-age=30")
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap, web.PublicAssets{CSSHref: "/static/dist/app.css", StaleSince: staleSince, LegalBase: base}))
}
// serveLegal shows a legal document of the page from the cached snapshot,
// so it stays reachable while the API is down.
func (s *Server) serveLegal(c *gin.Context, e entry, kind, base string) {
d, ok := e.Snap.LegalDocByKind(kind)
switch {
case !ok:
c.Status(http.StatusNotFound)
case d.URL != "":
c.Redirect(http.StatusFound, d.URL)
default:
html, err := web.RenderMarkdown(d.Markdown)
if err != nil {
c.Status(http.StatusInternalServerError)
return
}
s.localizeRequest(c)
c.Header("Cache-Control", "public, max-age=300")
web.Render(c, http.StatusOK, web.PublicLegalPage(e.Snap, web.PublicAssets{CSSHref: "/static/dist/app.css"}, kind, html, base))
}
}
func (s *Server) localizeRequest(c *gin.Context) {
l := s.catalog.Match(c.GetHeader("Accept-Language"))
c.Request = c.Request.WithContext(i18n.NewContext(c.Request.Context(), l))
c.Header("Cache-Control", "public, max-age=30")
c.Header("Content-Language", l.Lang())
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap, web.PublicAssets{CSSHref: "/static/dist/app.css", StaleSince: staleSince}))
}
// lookup answers from the cache whenever possible and refreshes in the