Files
uptimesebi/internal/web/admin_orgs.templ
T
Sebastian UnterschützandClaude Opus 5.5 cca4e80e54
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m5s
ci / lint (pull_request) Successful in 10m24s
ci / build (pull_request) Successful in 18m10s
ci / image (pull_request) Successful in 5m16s
feat(statuspages): email subscriptions, RSS feed and a JSON API
Visitors can subscribe to a page's incidents by email where the
organization allows it. They confirm their address first; confirmation
and unsubscribe links only show a button, so mail scanners do not act on
them, and mails carry RFC 8058 one-click unsubscribe headers. Subscribers
get a mail when an incident opens or resolves and for every public
update.

Every page also has an RSS feed of incidents and planned maintenance and
a read-only JSON API (status, summary, components, incidents), both
served from the cached snapshot.

Abuse protection: status page servers limit feed and API reads,
subscription requests and link actions per visitor; the API limits
subscription requests per visitor, mailbox and page, and a new limit caps
the subscriptions an organization's pages gain in seven days (platform
default and per-organization override, 1000 in the cloud). Unconfirmed
subscriptions count towards it and are deleted after a week.

The fixed cap of 200 monitors per status page is gone; the configurable
limit alone decides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-26 18:18:08 +01:00

228 lines
10 KiB
Templ
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"context"
"strconv"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// LimitsView holds limits; 0 means unlimited.
type LimitsView struct {
Monitors int
StatusPages int
RegionsPerMonitor int
OwnRegionsCount bool
OrgsPerAccount int
MonitorsPerPage int
SubscribersPerWeek int
}
// OrgsView lists organizations for platform admins.
type OrgsView struct {
Search string
Orgs []OrgRow
Pager Pager
Defaults LimitsView
// Next is the page to return to after an action.
Next string
}
// OrgRow is an organization with its usage and limits. Overrides are form
// values: empty follows the default.
type OrgRow struct {
ID, Name, Slug, Created, Suspended string
Monitors, StatusPages int
Limits LimitsView
MonitorsOverride string
StatusPagesOverride string
RegionsOverride string
OwnRegionsOverride string
PerPageOverride string
SubscribersOverride string
Owner *ModeratedTarget
OwnerOrgs int
OwnerOrgLimit string
}
func (v OrgsView) next() string { return v.Next }
// limitText shows a limit, or "unlimited".
func limitText(ctx context.Context, n int) string {
if n == 0 {
return i18n.T(ctx, "limits.unlimited")
}
return strconv.Itoa(n)
}
templ limitsSection(d LimitsView) {
<section id="limits" class="mb-12 max-w-3xl">
@sectionHeading("limits.title")
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "limits.intro") }</p>
<form data-api="/admin/limits" data-method="put" data-next="/admin#limits">
@formError()
<div class="grid gap-x-6 sm:grid-cols-2">
@numberField(i18n.T(ctx, "limits.monitors"), "monitors", d.Monitors, 0, 1000000, "")
@numberField(i18n.T(ctx, "limits.status_pages"), "status_pages", d.StatusPages, 0, 1000000, "")
@numberField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", d.RegionsPerMonitor, 0, 1000, "")
@numberField(i18n.T(ctx, "limits.orgs_per_account"), "orgs_per_account", d.OrgsPerAccount, 0, 100000, "")
@numberField(i18n.T(ctx, "limits.monitors_per_page"), "monitors_per_page", d.MonitorsPerPage, 0, 1000000, "")
@numberField(i18n.T(ctx, "limits.subscribers_per_week"), "subscribers_per_week", d.SubscribersPerWeek, 0, 100000000, "")
</div>
@checkbox(i18n.T(ctx, "limits.own_regions_count"), "own_regions_count", d.OwnRegionsCount)
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_count_hint") }</p>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
</form>
</section>
}
// overrideField is a limit an organization may override: empty follows
// the default, shown as placeholder.
templ overrideField(label, name, value string, def int, max int) {
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ label }</span>
<input
type="number"
name={ name }
data-number
data-nullable
min="0"
max={ strconv.Itoa(max) }
value={ value }
placeholder={ i18n.T(ctx, "limits.default", "Value", limitText(ctx, def)) }
class="w-full border border-rule bg-transparent px-2 py-1 font-mono text-sm outline-none focus:border-ink"
/>
</label>
}
templ orgsSection(v OrgsView) {
<section id="orgs" class="mb-12">
@sectionHeading("orgs.title")
<p class="mb-4 max-w-3xl text-sm text-muted">{ i18n.T(ctx, "orgs.intro") }</p>
<form method="get" action="/admin/orgs" class="mb-4 flex max-w-xl gap-2">
<input
type="search"
name="q"
value={ v.Search }
placeholder={ i18n.T(ctx, "orgs.search") }
aria-label={ i18n.T(ctx, "orgs.search") }
class="w-full border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"
/>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "moderation.search_button") }</button>
</form>
if len(v.Orgs) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "orgs.none") }</p>
} else {
<div class="overflow-x-auto">
<table class="w-full min-w-[42rem] text-left text-sm">
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
<tr>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "moderation.org") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "moderation.owner") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "limits.monitors") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "limits.status_pages") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "moderation.created") }</th>
</tr>
</thead>
<tbody class="divide-y divide-rule">
for _, o := range v.Orgs {
<tr class="align-top">
<td class="py-2.5 pr-4">
{ o.Name }
<span class="block font-mono text-xs text-muted">{ o.Slug }</span>
@moderationState(o.Suspended, false)
</td>
<td class="py-2.5 pr-4">
if o.Owner != nil {
<span class="break-all">{ o.Owner.Name }</span>
@moderationState(o.Owner.Suspended, false)
} else {
<span class="text-muted">–</span>
}
</td>
<td class="py-2.5 pr-4 font-mono text-xs">@usage(o.Monitors, o.Limits.Monitors)</td>
<td class="py-2.5 pr-4 font-mono text-xs">@usage(o.StatusPages, o.Limits.StatusPages)</td>
<td class="py-2.5 pr-4 font-mono text-xs text-muted">{ o.Created }</td>
</tr>
<tr>
<td colspan="5" class="pb-3">
<details class="text-sm">
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "orgs.manage") }</summary>
<div class="mt-3 grid gap-6 md:grid-cols-3">
<form data-api={ "/admin/orgs/" + o.ID + "/limits" } data-method="put" data-next={ v.next() }>
<h4 class="mb-2 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "orgs.limits") }</h4>
@formError()
@overrideField(i18n.T(ctx, "limits.monitors"), "monitors", o.MonitorsOverride, v.Defaults.Monitors, 1000000)
@overrideField(i18n.T(ctx, "limits.status_pages"), "status_pages", o.StatusPagesOverride, v.Defaults.StatusPages, 1000000)
@overrideField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", o.RegionsOverride, v.Defaults.RegionsPerMonitor, 1000)
@overrideField(i18n.T(ctx, "limits.monitors_per_page"), "monitors_per_page", o.PerPageOverride, v.Defaults.MonitorsPerPage, 1000000)
@overrideField(i18n.T(ctx, "limits.subscribers_per_week"), "subscribers_per_week", o.SubscribersOverride, v.Defaults.SubscribersPerWeek, 100000000)
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "limits.own_regions_count") }</span>
<select name="own_regions_count" class="w-full border border-rule bg-transparent px-2 py-1 text-sm">
<option value="" selected?={ o.OwnRegionsOverride == "" }>{ i18n.T(ctx, "limits.default", "Value", i18n.T(ctx, "limits.own_"+strconv.FormatBool(v.Defaults.OwnRegionsCount))) }</option>
<option value="true" selected?={ o.OwnRegionsOverride == "true" }>{ i18n.T(ctx, "limits.own_true") }</option>
<option value="false" selected?={ o.OwnRegionsOverride == "false" }>{ i18n.T(ctx, "limits.own_false") }</option>
</select>
</label>
<button type="submit" class="border border-ink px-2.5 py-1 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
</form>
@moderationActions("org", "/admin/orgs/"+o.ID, o.Suspended, o.Name, v.next())
if o.Owner != nil && o.Owner.Admin {
<p class="text-xs text-muted">{ i18n.T(ctx, "moderation.owner_is_admin") }</p>
} else if o.Owner != nil {
<div>
<form data-api={ "/admin/users/" + o.Owner.ID + "/limits" } data-method="put" data-next={ v.next() } class="mb-4">
<h4 class="mb-2 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "moderation.target_owner") }</h4>
@formError()
@overrideField(i18n.T(ctx, "orgs.owner_orgs", "Count", o.OwnerOrgs), "orgs", o.OwnerOrgLimit, v.Defaults.OrgsPerAccount, 100000)
<button type="submit" class="border border-ink px-2.5 py-1 hover:bg-ink hover:text-paper">{ i18n.T(ctx, "common.save") }</button>
</form>
@moderationActions("owner", "/admin/users/"+o.Owner.ID, o.Owner.Suspended, o.Owner.Name, v.next())
</div>
}
</div>
</details>
</td>
</tr>
}
</tbody>
</table>
</div>
}
@pager(v.Pager, "newer", "older")
</section>
}
// usage shows "used / limit", marking a reached limit.
templ usage(used, max int) {
<span class={ templ.KV("text-down", max > 0 && used >= max) }>{ strconv.Itoa(used) } / { limitText(ctx, max) }</span>
}
// UsageView is an organization's usage of its limits.
type UsageView struct {
Limits LimitsView
Monitors, StatusPages int
}
templ usageSection(u UsageView) {
<section class="mb-12 max-w-xl">
@sectionHeading("limits.org_title")
<dl class="grid grid-cols-[1fr_auto] gap-x-6 gap-y-1.5 text-sm">
<dt>{ i18n.T(ctx, "limits.monitors") }</dt>
<dd class="font-mono text-xs">@usage(u.Monitors, u.Limits.Monitors)</dd>
<dt>{ i18n.T(ctx, "limits.status_pages") }</dt>
<dd class="font-mono text-xs">@usage(u.StatusPages, u.Limits.StatusPages)</dd>
<dt>{ i18n.T(ctx, "limits.regions_per_monitor") }</dt>
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.RegionsPerMonitor) }</dd>
<dt>{ i18n.T(ctx, "limits.monitors_per_page") }</dt>
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.MonitorsPerPage) }</dd>
<dt>{ i18n.T(ctx, "limits.subscribers_per_week") }</dt>
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.SubscribersPerWeek) }</dd>
</dl>
if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount {
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_free") }</p>
}
</section>
}