feat(notify): name regions and link the console in alerts; consent to subscribe
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / lint (pull_request) Successful in 11m8s
ci / test (pull_request) Successful in 13m45s
ci / build (pull_request) In progress
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / image (pull_request) Waiting for needed jobs
ci / lint (pull_request) Successful in 11m8s
ci / test (pull_request) Successful in 13m45s
ci / build (pull_request) In progress
Alert mails and chat messages named regions by id. They now show the region's name and mails link the monitor in the console. Visitors of a status page accept the platform's terms and the page's privacy policy, where set, before they can subscribe to it; the status page server and the API both check it. 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
cca4e80e54
commit
2d4bd10c9b
16 files changed
+660
-479
No files matched your search
@@ -24,6 +24,9 @@ type SubscribeRequest struct {
|
||||
// uses it for the links in mails only where it does not know the
|
||||
// page's address itself.
|
||||
PageURL string `json:"page_url,omitempty"`
|
||||
// Accepted says the visitor accepted the terms and privacy policy the
|
||||
// page links in its form, if it links any.
|
||||
Accepted bool `json:"accepted"`
|
||||
}
|
||||
|
||||
// SubscriptionInfo describes a subscription that was confirmed or ended.
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/evaluate"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/notify"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
@@ -197,9 +198,40 @@ func eventOf(n store.NotificationDetailsRow) notify.Event {
|
||||
Monitor: notify.Monitor{ID: n.MonitorID, Name: n.MonitorName, Type: n.MonitorType, Target: n.MonitorTarget},
|
||||
}
|
||||
_ = json.Unmarshal(n.Cause, &ev.Cause)
|
||||
_ = json.Unmarshal(n.RegionNames, &ev.RegionNames)
|
||||
return ev
|
||||
}
|
||||
|
||||
// causeLines describes the errors of ev per region, sorted, naming each
|
||||
// region as people know it.
|
||||
func causeLines(ev notify.Event, l *i18n.Localizer) []string {
|
||||
var out []string
|
||||
for region, msg := range ev.Cause {
|
||||
name, ok := ev.RegionNames[region]
|
||||
switch {
|
||||
case ok:
|
||||
case region == heartbeatRegion:
|
||||
name = l.T("monitors.type_heartbeat", nil)
|
||||
case region == alertmanagerRegion:
|
||||
name = "Alertmanager"
|
||||
default:
|
||||
name = region
|
||||
}
|
||||
out = append(out, name+": "+msg)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// monitorLink is the address of ev's monitor in the console, or "" if
|
||||
// the platform's own address is unknown.
|
||||
func (s *Server) monitorLink(ev notify.Event) string {
|
||||
if ev.Monitor.ID == (uuid.UUID{}) || !absoluteURL(s.cfg.PublicURL) {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSuffix(s.cfg.PublicURL, "/") + "/monitors/" + ev.Monitor.ID.String()
|
||||
}
|
||||
|
||||
// webhookConfig is stored for webhook channels; Secret is sealed.
|
||||
type webhookConfig struct {
|
||||
URL string `json:"url"`
|
||||
@@ -257,18 +289,17 @@ func (s *Server) mailFor(ev notify.Event, to []string, locale string) notify.Mai
|
||||
"Target": ev.Monitor.Target,
|
||||
"Since": ev.StartedAt.UTC().Format("2006-01-02 15:04 MST"),
|
||||
}
|
||||
var cause []string
|
||||
for region, msg := range ev.Cause {
|
||||
cause = append(cause, region+": "+msg)
|
||||
}
|
||||
slices.Sort(cause)
|
||||
data["Cause"] = strings.Join(cause, "\n")
|
||||
data["Cause"] = strings.Join(causeLines(ev, l), "\n")
|
||||
if ev.ResolvedAt != nil {
|
||||
data["Duration"] = ev.ResolvedAt.Sub(ev.StartedAt).Round(time.Second).String()
|
||||
}
|
||||
body := l.T("email."+ev.Kind+".body", data)
|
||||
if link := s.monitorLink(ev); link != "" {
|
||||
body += "\n\n" + l.T("email.monitor_link", map[string]any{"Link": link})
|
||||
}
|
||||
return notify.Mail{
|
||||
To: to,
|
||||
Subject: l.T("email."+ev.Kind+".subject", data),
|
||||
Body: l.T("email."+ev.Kind+".body", data),
|
||||
Body: body,
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,8 @@ func TestAlerting(t *testing.T) {
|
||||
}
|
||||
if msg := mail.Messages()[0].Data; !strings.Contains(msg, "Subject: [DOWN] Shop") || !strings.Contains(msg, "ist in allen Regionen nicht erreichbar") {
|
||||
t.Errorf("down mail = %q, want German down notice", msg)
|
||||
} else if strings.Contains(msg, eu) || strings.Contains(msg, us) || !strings.Contains(msg, "/monitors/"+monitorID) {
|
||||
t.Errorf("down mail = %q, want region names instead of ids and a link to the monitor", msg)
|
||||
}
|
||||
|
||||
healthy.Store(true)
|
||||
|
||||
@@ -134,10 +134,7 @@ func (s *Server) messageFor(ev notify.Event, locale string) notify.Message {
|
||||
switch ev.Kind {
|
||||
case notify.Opened:
|
||||
m.Title = l.T("notify.title_opened", data)
|
||||
for region, msg := range ev.Cause {
|
||||
lines = append(lines, region+": "+msg)
|
||||
}
|
||||
slices.Sort(lines)
|
||||
lines = causeLines(ev, l)
|
||||
case notify.Resolved:
|
||||
m.Title = l.T("notify.title_resolved", data)
|
||||
if ev.ResolvedAt != nil {
|
||||
@@ -151,8 +148,6 @@ func (s *Server) messageFor(ev notify.Event, locale string) notify.Message {
|
||||
lines = append([]string{ev.Monitor.Type + " · " + ev.Monitor.Target}, lines...)
|
||||
}
|
||||
m.Body = strings.Join(lines, "\n")
|
||||
if ev.Monitor.ID != [16]byte{} {
|
||||
m.URL = strings.TrimSuffix(s.cfg.PublicURL, "/") + "/monitors/" + ev.Monitor.ID.String()
|
||||
}
|
||||
m.URL = s.monitorLink(ev)
|
||||
return m
|
||||
}
|
||||
@@ -128,8 +128,9 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
return err
|
||||
}
|
||||
docs, err := q.LegalDocuments(ctx, &page.OrgID)
|
||||
// Visitors of status pages accept no terms.
|
||||
snap.Legal = slices.DeleteFunc(mergeLegal(docs), func(d agentapi.LegalDoc) bool { return d.Kind == "terms" })
|
||||
// Visitors of status pages accept the platform's terms only when
|
||||
// they subscribe to it.
|
||||
snap.Legal = slices.DeleteFunc(mergeLegal(docs), func(d agentapi.LegalDoc) bool { return d.Kind == "terms" && !snap.Subscribe })
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -134,6 +134,10 @@ func (s *Server) agentSubscribe(c *gin.Context) {
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_email")
|
||||
return
|
||||
}
|
||||
if !req.Accepted {
|
||||
fail(c, http.StatusUnprocessableEntity, "consent_required")
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
a := agentOf(c)
|
||||
var host, slug *string
|
||||
|
||||
@@ -95,13 +95,28 @@ func TestStatusPageSubscriptions(t *testing.T) {
|
||||
return out
|
||||
}
|
||||
|
||||
if code, html, _ := visit("GET", "/"+slug, ""); code != 200 || !strings.Contains(html, `action="/`+slug+`/subscribe"`) || !strings.Contains(html, "feed.rss") {
|
||||
// Subscribers accept the page's privacy policy.
|
||||
if st, body := owner.do("PUT", "/api/v1/org/legal/privacy", map[string]any{"url": "https://shop.example/privacy"}); st != http.StatusNoContent {
|
||||
t.Fatalf("set privacy policy = %d %v", st, body)
|
||||
}
|
||||
t.Cleanup(func() { owner.do("PUT", "/api/v1/org/legal/privacy", map[string]any{}) })
|
||||
pages.Sync(ctx)
|
||||
code, html, _ := visit("GET", "/"+slug, "")
|
||||
if code != 200 || !strings.Contains(html, `action="/`+slug+`/subscribe"`) || !strings.Contains(html, "feed.rss") {
|
||||
t.Fatalf("page = %d, want the subscription form and the feed link", code)
|
||||
}
|
||||
if code, html, _ := visit("POST", "/"+slug+"/subscribe", "email=not-an-address"); code != http.StatusUnprocessableEntity {
|
||||
if !strings.Contains(html, `name="accept"`) || !strings.Contains(html, `href="https://shop.example/privacy"`) {
|
||||
t.Error("the subscription form does not ask to accept the privacy policy")
|
||||
}
|
||||
if code, html, _ := visit("POST", "/"+slug+"/subscribe", "email=not-an-address&accept=1"); code != http.StatusUnprocessableEntity {
|
||||
t.Errorf("subscribing an invalid address = %d %.200s", code, html)
|
||||
}
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=Visitor@Example.test"); code != 200 {
|
||||
visitor = "198.51.100.9:1234" // (not to use up the subscription requests of the first)
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=visitor@example.test"); code != http.StatusUnprocessableEntity {
|
||||
t.Errorf("subscribing without accepting the privacy policy = %d, want 422", code)
|
||||
}
|
||||
visitor = "198.51.100.7:1234"
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=Visitor@Example.test&accept=1"); code != 200 {
|
||||
t.Fatalf("subscribe = %d", code)
|
||||
}
|
||||
if c, p := subscribers(); c != 0 || p != 1 {
|
||||
@@ -134,7 +149,7 @@ func TestStatusPageSubscriptions(t *testing.T) {
|
||||
t.Errorf("subscribers after confirming = %d, %d; want 1, 0", c, p)
|
||||
}
|
||||
// Asking again for a confirmed address mails nothing.
|
||||
visit("POST", "/"+slug+"/subscribe", "email=visitor@example.test")
|
||||
visit("POST", "/"+slug+"/subscribe", "email=visitor@example.test&accept=1")
|
||||
if n := len(mailsTo("visitor@example.test")); n != 1 {
|
||||
t.Errorf("mails after subscribing a confirmed address again = %d, want 1", n)
|
||||
}
|
||||
@@ -199,10 +214,10 @@ func TestStatusPageSubscriptions(t *testing.T) {
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=second@example.test"); code != 200 {
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=second@example.test&accept=1"); code != 200 {
|
||||
t.Errorf("subscription within the weekly limit = %d", code)
|
||||
}
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=third@example.test"); code != http.StatusTooManyRequests {
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=third@example.test&accept=1"); code != http.StatusTooManyRequests {
|
||||
t.Errorf("subscription beyond the weekly limit = %d, want 429", code)
|
||||
}
|
||||
if n := len(mailsTo("third@example.test")); n != 0 {
|
||||
@@ -218,13 +233,13 @@ func TestStatusPageSubscriptions(t *testing.T) {
|
||||
if code, html, _ := visit("GET", "/"+slug, ""); code != 200 || strings.Contains(html, "/subscribe\"") {
|
||||
t.Errorf("page without subscriptions = %d, still offers the form", code)
|
||||
}
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=fourth@example.test"); code != http.StatusNotFound {
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=fourth@example.test&accept=1"); code != http.StatusNotFound {
|
||||
t.Errorf("subscribing where it is off = %d, want 404", code)
|
||||
}
|
||||
|
||||
// This visitor used up its subscription requests on the server.
|
||||
visitor = "198.51.100.7:1234"
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=fifth@example.test"); code != http.StatusTooManyRequests {
|
||||
if code, _, _ := visit("POST", "/"+slug+"/subscribe", "email=fifth@example.test&accept=1"); code != http.StatusTooManyRequests {
|
||||
t.Errorf("sixth subscription request of a visitor = %d, want 429", code)
|
||||
}
|
||||
|
||||
|
||||
@@ -519,6 +519,7 @@
|
||||
"email.domain_missing.subject": "Der DNS-Eintrag von {{.Domain}} fehlt",
|
||||
"email.domain_off.body": "Der DNS-Eintrag von {{.Domain}} fehlt seit einer Woche, deshalb wird die Statusseite {{.Page}} dort nicht mehr ausgeliefert.\n\nStelle den Eintrag wieder her und prüfe die Domain erneut:\n{{.Link}}",
|
||||
"email.domain_off.subject": "{{.Domain}} wurde abgeschaltet",
|
||||
"email.monitor_link": "In UptimeSebi öffnen: {{.Link}}",
|
||||
"email.opened.body": "{{.Monitor}} ({{.Target}}) ist in allen Regionen nicht erreichbar seit {{.Since}}.\n\nLetzte Fehler:\n{{.Cause}}\n\nDu erhältst diese Nachricht, weil ein Benachrichtigungskanal deiner Organisation diese Adresse nutzt.",
|
||||
"email.opened.subject": "[DOWN] {{.Monitor}}",
|
||||
"email.region_back.body": "Region {{.Region}} hat wieder einen aktiven Checker; seit {{.Since}} hatte sie keinen. Überfällige Prüfungen laufen sofort.\n\n{{.Link}}",
|
||||
@@ -571,6 +572,7 @@
|
||||
"error.invalid_credentials": "E-Mail oder Passwort falsch.",
|
||||
"error.invalid_cursor": "Dieser Seitenlink ist ungültig; beginne bei der ersten Seite.",
|
||||
"error.invalid_domain": "Eine der Domains ist ungültig.",
|
||||
"error.consent_required": "Bitte stimme den Bedingungen zu, um zu abonnieren.",
|
||||
"error.invalid_email": "Bitte eine gültige E-Mail-Adresse eingeben.",
|
||||
"error.invalid_expect_status": "Erwartete Statuscodes müssen Codes wie 200 oder Klassen wie 2xx sein.",
|
||||
"error.invalid_grace": "Die Toleranz muss zwischen 0 Sekunden und einem Tag liegen.",
|
||||
@@ -1573,6 +1575,10 @@
|
||||
"page.subscribe.email": "E-Mail-Adresse",
|
||||
"page.subscribe.submit": "Abonnieren",
|
||||
"page.subscribe.privacy": "Deine Adresse wird nur für diese E-Mails verwendet. Jede E-Mail enthält einen Link zum Abmelden.",
|
||||
"page.subscribe.accept_both": "Ich akzeptiere die AGB und habe die Datenschutzerklärung gelesen:",
|
||||
"page.subscribe.accept_terms": "Ich akzeptiere die AGB:",
|
||||
"page.subscribe.accept_privacy": "Ich habe die Datenschutzerklärung gelesen:",
|
||||
"page.subscribe.accept_required": "Bitte stimme den Bedingungen zu, um zu abonnieren.",
|
||||
"page.subscribe.sent_title": "Schau in dein Postfach",
|
||||
"page.subscribe.sent": "Wenn die Adresse abonniert werden kann, ist ein Link zum Bestätigen unterwegs. Er ist 48 Stunden gültig.",
|
||||
"page.subscribe.invalid": "Das ist keine gültige E-Mail-Adresse.",
|
||||
|
||||
@@ -519,6 +519,7 @@
|
||||
"email.domain_missing.subject": "The DNS record of {{.Domain}} is gone",
|
||||
"email.domain_off.body": "The DNS record of {{.Domain}} has been missing for a week, so the status page {{.Page}} is no longer served there.\n\nRestore the record and verify the domain again:\n{{.Link}}",
|
||||
"email.domain_off.subject": "{{.Domain}} has been switched off",
|
||||
"email.monitor_link": "Open in UptimeSebi: {{.Link}}",
|
||||
"email.opened.body": "{{.Monitor}} ({{.Target}}) is down in all of its regions since {{.Since}}.\n\nLast errors:\n{{.Cause}}\n\nYou receive this because a notification channel of your organization is set up for this address.",
|
||||
"email.opened.subject": "[DOWN] {{.Monitor}}",
|
||||
"email.region_back.body": "Region {{.Region}} has an active checker again; it had none since {{.Since}}. Overdue checks run right away.\n\n{{.Link}}",
|
||||
@@ -571,6 +572,7 @@
|
||||
"error.invalid_credentials": "Wrong email or password.",
|
||||
"error.invalid_cursor": "This page link is invalid; start from the first page.",
|
||||
"error.invalid_domain": "One of the domains is not valid.",
|
||||
"error.consent_required": "Please accept the terms to subscribe.",
|
||||
"error.invalid_email": "Please enter a valid email address.",
|
||||
"error.invalid_expect_status": "Expected status codes must be codes like 200 or classes like 2xx.",
|
||||
"error.invalid_grace": "The grace period must be between 0 seconds and one day.",
|
||||
@@ -1573,6 +1575,10 @@
|
||||
"page.subscribe.email": "Email address",
|
||||
"page.subscribe.submit": "Subscribe",
|
||||
"page.subscribe.privacy": "Your address is used for these emails only. Every email contains a link to unsubscribe.",
|
||||
"page.subscribe.accept_both": "I accept the terms of service and have read the privacy policy:",
|
||||
"page.subscribe.accept_terms": "I accept the terms of service:",
|
||||
"page.subscribe.accept_privacy": "I have read the privacy policy:",
|
||||
"page.subscribe.accept_required": "Please accept the terms to subscribe.",
|
||||
"page.subscribe.sent_title": "Check your inbox",
|
||||
"page.subscribe.sent": "If the address can be subscribed, a link to confirm it is on its way. The link is valid for 48 hours.",
|
||||
"page.subscribe.invalid": "That is not a valid email address.",
|
||||
|
||||
@@ -55,6 +55,9 @@ type Event struct {
|
||||
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
|
||||
Cause map[string]string `json:"cause,omitempty"`
|
||||
Monitor Monitor `json:"monitor"`
|
||||
// RegionNames names the regions Cause has by id, for messages to
|
||||
// people.
|
||||
RegionNames map[string]string `json:"-"`
|
||||
}
|
||||
|
||||
// Webhook signs requests so receivers can verify they came from us: the
|
||||
|
||||
@@ -367,10 +367,12 @@ func (s *Server) serveSubscription(c *gin.Context, e entry, kind routeKind, host
|
||||
switch {
|
||||
case kind == routeSubscribe && c.Request.Method != http.MethodPost:
|
||||
c.Redirect(http.StatusSeeOther, base+"#subscribe")
|
||||
case kind == routeSubscribe && c.PostForm("accept") == "" && len(web.SubscribeConsent(snap, base)) > 0:
|
||||
notice(http.StatusUnprocessableEntity, i18n.T(ctx, "page.subscribe.title"), i18n.T(ctx, "page.subscribe.accept_required"), nil)
|
||||
case kind == routeSubscribe:
|
||||
err := subs.Subscribe(ctx, agentapi.SubscribeRequest{
|
||||
Host: host, Slug: slug, Email: c.PostForm("email"), IP: c.ClientIP(),
|
||||
Locale: c.GetHeader("Accept-Language"), PageURL: pageURL(c, base),
|
||||
Locale: c.GetHeader("Accept-Language"), PageURL: pageURL(c, base), Accepted: true,
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
|
||||
@@ -578,7 +578,10 @@ const notificationDetails = `-- name: NotificationDetails :many
|
||||
SELECT n.id, n.org_id, n.event, n.attempts,
|
||||
c.type AS channel_type, c.config AS channel_config, c.id AS channel_id,
|
||||
i.id AS incident_id, i.started_at, i.resolved_at, i.cause,
|
||||
m.id AS monitor_id, m.name AS monitor_name, m.target AS monitor_target, m.type AS monitor_type
|
||||
m.id AS monitor_id, m.name AS monitor_name, m.target AS monitor_target, m.type AS monitor_type,
|
||||
-- The names of the regions the cause names by id.
|
||||
coalesce((SELECT jsonb_object_agg(r.id::text, r.name) FROM regions r
|
||||
WHERE jsonb_typeof(i.cause) = 'object' AND i.cause ? r.id::text), '{}')::jsonb AS region_names
|
||||
FROM notifications n
|
||||
JOIN notification_channels c ON c.id = n.channel_id
|
||||
JOIN incidents i ON i.id = n.incident_id
|
||||
@@ -602,6 +605,7 @@ type NotificationDetailsRow struct {
|
||||
MonitorName string
|
||||
MonitorTarget string
|
||||
MonitorType string
|
||||
RegionNames []byte
|
||||
}
|
||||
|
||||
// System scope.
|
||||
@@ -630,6 +634,7 @@ func (q *Queries) NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]N
|
||||
&i.MonitorName,
|
||||
&i.MonitorTarget,
|
||||
&i.MonitorType,
|
||||
&i.RegionNames,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -47,7 +47,10 @@ RETURNING id;
|
||||
SELECT n.id, n.org_id, n.event, n.attempts,
|
||||
c.type AS channel_type, c.config AS channel_config, c.id AS channel_id,
|
||||
i.id AS incident_id, i.started_at, i.resolved_at, i.cause,
|
||||
m.id AS monitor_id, m.name AS monitor_name, m.target AS monitor_target, m.type AS monitor_type
|
||||
m.id AS monitor_id, m.name AS monitor_name, m.target AS monitor_target, m.type AS monitor_type,
|
||||
-- The names of the regions the cause names by id.
|
||||
coalesce((SELECT jsonb_object_agg(r.id::text, r.name) FROM regions r
|
||||
WHERE jsonb_typeof(i.cause) = 'object' AND i.cause ? r.id::text), '{}')::jsonb AS region_names
|
||||
FROM notifications n
|
||||
JOIN notification_channels c ON c.id = n.channel_id
|
||||
JOIN incidents i ON i.id = n.incident_id
|
||||
|
||||
+26
-2
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"slices"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/ast"
|
||||
@@ -80,7 +81,30 @@ func LegalLinks(docs []agentapi.LegalDoc, base string) []LegalLink {
|
||||
return out
|
||||
}
|
||||
|
||||
// PageLegalLinks returns the legal links of a status page.
|
||||
// PageLegalLinks returns the legal links of a status page's footer. The
|
||||
// terms are not among them: visitors accept them only when subscribing.
|
||||
func PageLegalLinks(s agentapi.PageSnapshot, base string) []LegalLink {
|
||||
return LegalLinks(s.Legal, base)
|
||||
return slices.DeleteFunc(LegalLinks(s.Legal, base), func(l LegalLink) bool { return l.Kind == "terms" })
|
||||
}
|
||||
|
||||
// SubscribeConsent returns the documents a visitor of a status page
|
||||
// accepts by subscribing: the terms and the privacy policy, where set.
|
||||
func SubscribeConsent(s agentapi.PageSnapshot, base string) []LegalLink {
|
||||
return slices.DeleteFunc(LegalLinks(s.Legal, base), func(l LegalLink) bool { return l.Kind == "imprint" })
|
||||
}
|
||||
|
||||
// ConsentLabelID names the message of the subscription checkbox for links.
|
||||
func ConsentLabelID(links []LegalLink) string {
|
||||
var terms, privacy bool
|
||||
for _, l := range links {
|
||||
terms = terms || l.Kind == "terms"
|
||||
privacy = privacy || l.Kind == "privacy"
|
||||
}
|
||||
switch {
|
||||
case terms && privacy:
|
||||
return "page.subscribe.accept_both"
|
||||
case terms:
|
||||
return "page.subscribe.accept_terms"
|
||||
}
|
||||
return "page.subscribe.accept_privacy"
|
||||
}
|
||||
@@ -114,10 +114,26 @@ templ publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) {
|
||||
<section id="subscribe" class="mb-12 border-t border-rule pt-6">
|
||||
<h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.subscribe.title") }</h2>
|
||||
<p class="mb-3 text-sm">{ i18n.T(ctx, "page.subscribe.intro") }</p>
|
||||
<form method="post" action={ templ.SafeURL(a.ComponentBase + "subscribe") } class="flex max-w-md flex-wrap gap-2">
|
||||
<label class="sr-only" for="subscribe-email">{ i18n.T(ctx, "page.subscribe.email") }</label>
|
||||
<input id="subscribe-email" type="email" name="email" required maxlength="254" autocomplete="email" placeholder={ i18n.T(ctx, "page.subscribe.email") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5 text-sm"/>
|
||||
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "page.subscribe.submit") }</button>
|
||||
<form method="post" action={ templ.SafeURL(a.ComponentBase + "subscribe") } class="max-w-md">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<label class="sr-only" for="subscribe-email">{ i18n.T(ctx, "page.subscribe.email") }</label>
|
||||
<input id="subscribe-email" type="email" name="email" required maxlength="254" autocomplete="email" placeholder={ i18n.T(ctx, "page.subscribe.email") } class="min-w-0 flex-1 border border-rule bg-transparent px-2 py-1.5 text-sm"/>
|
||||
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "page.subscribe.submit") }</button>
|
||||
</div>
|
||||
if consent := SubscribeConsent(s, a.LegalBase); len(consent) > 0 {
|
||||
<label class="mt-3 flex items-start gap-2 text-sm">
|
||||
<input type="checkbox" name="accept" value="1" required class="mt-1"/>
|
||||
<span>
|
||||
{ i18n.T(ctx, ConsentLabelID(consent)) }
|
||||
for i, l := range consent {
|
||||
if i > 0 {
|
||||
<span aria-hidden="true">·</span>
|
||||
}
|
||||
<a href={ templ.SafeURL(l.Href) } target="_blank" rel="noopener" class="underline underline-offset-2">{ i18n.T(ctx, LegalTitleID(l.Kind)) }</a>
|
||||
}
|
||||
</span>
|
||||
</label>
|
||||
}
|
||||
</form>
|
||||
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "page.subscribe.privacy") }</p>
|
||||
</section>
|
||||
|
||||
+511
-446
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user