ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 9m21s
ci / test (pull_request) Successful in 13m53s
ci / build (pull_request) Successful in 11m22s
ci / image (pull_request) Successful in 4m36s
Terms of service join the legal notice and privacy policy, for the platform only. Every account accepts the platform's privacy policy and terms: on sign-up (also through an invitation) by ticking a box for the versions shown, and after a sign-in through a provider right away. When an admin saves a material change with "everyone has to accept again", the document gets a new version and each account is asked at its next request; corrections ask nobody. Acceptances are kept per version with their time, as proof, and are part of the data export. Until an account accepted, and while it is suspended, it can read the documents, export its data, delete itself and sign out, nothing else: pages lead to /consent or /account/suspended, other API calls answer 403 consent_required or account_suspended. Suspended accounts therefore sign in again, by password or provider; their API tokens stay blocked. Deleting an account deletes the organizations it owns, monitors and all, also when they have other members (each organization has one owner); it no longer refuses. The account settings name those organizations first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
87 lines
2.7 KiB
Go
87 lines
2.7 KiB
Go
package web
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/yuin/goldmark"
|
|
"github.com/yuin/goldmark/ast"
|
|
"github.com/yuin/goldmark/extension"
|
|
"github.com/yuin/goldmark/renderer"
|
|
"github.com/yuin/goldmark/util"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
|
)
|
|
|
|
// LegalKinds are the platform's legal documents, in footer order.
|
|
var LegalKinds = []string{"imprint", "privacy", "terms"}
|
|
|
|
// OrgLegalKinds are the documents an organization sets for its status
|
|
// pages; their visitors accept no terms.
|
|
var OrgLegalKinds = []string{"imprint", "privacy"}
|
|
|
|
// ConsentKinds are the platform documents every account accepts.
|
|
var ConsentKinds = []string{"privacy", "terms"}
|
|
|
|
// 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. Images are
|
|
// shown as their alt text: on a status page an external image would hand
|
|
// every visitor's address to its host.
|
|
var markdown = goldmark.New(
|
|
goldmark.WithExtensions(extension.Table, extension.Linkify, extension.Strikethrough),
|
|
goldmark.WithRendererOptions(renderer.WithNodeRenderers(util.Prioritized(altTextImages{}, 100))),
|
|
)
|
|
|
|
type altTextImages struct{}
|
|
|
|
// RegisterFuncs implements renderer.NodeRenderer.
|
|
func (altTextImages) RegisterFuncs(r renderer.NodeRendererFuncRegisterer) {
|
|
r.Register(ast.KindImage, func(w util.BufWriter, src []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
// The children are the alt text and render as usual.
|
|
return ast.WalkContinue, nil
|
|
})
|
|
}
|
|
|
|
// 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)
|
|
}
|