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:
1 parent
4134af4aef
commit
73eb0f8bcd
26 files changed
+1278
-64
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
)
|
||||
|
||||
// LegalKinds are the legal documents, in footer order.
|
||||
var LegalKinds = []string{"imprint", "privacy"}
|
||||
|
||||
// LegalTitleID names the catalog message of a document kind.
|
||||
func LegalTitleID(kind string) string { return "legal." + kind }
|
||||
|
||||
// LegalLink points to a legal document, ours or elsewhere.
|
||||
type LegalLink struct {
|
||||
Kind string
|
||||
Href string
|
||||
External bool
|
||||
}
|
||||
|
||||
// markdown renders untrusted input: goldmark drops raw HTML and links with
|
||||
// dangerous schemes such as javascript: unless told otherwise.
|
||||
var markdown = goldmark.New(goldmark.WithExtensions(extension.Table, extension.Linkify, extension.Strikethrough))
|
||||
|
||||
// RenderMarkdown converts src to HTML that is safe to embed.
|
||||
func RenderMarkdown(src string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := markdown.Convert([]byte(src), &buf); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
// LegalLinks turns documents into links: external URLs as they are,
|
||||
// Markdown documents to base+kind.
|
||||
func LegalLinks(docs []agentapi.LegalDoc, base string) []LegalLink {
|
||||
var out []LegalLink
|
||||
for _, kind := range LegalKinds {
|
||||
for _, d := range docs {
|
||||
if d.Kind != kind {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case d.URL != "":
|
||||
out = append(out, LegalLink{Kind: kind, Href: d.URL, External: true})
|
||||
case d.Markdown != "" && base != "":
|
||||
out = append(out, LegalLink{Kind: kind, Href: base + kind})
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PageLegalLinks returns the legal links of a status page.
|
||||
func PageLegalLinks(s agentapi.PageSnapshot, base string) []LegalLink {
|
||||
return LegalLinks(s.Legal, base)
|
||||
}
|
||||
Reference in new issue
Block a user