Files
uptimesebi/internal/web/console.templ
T
Sebastian UnterschützandClaude Opus 5.5 f3d402705e
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m0s
ci / test (pull_request) Successful in 12m1s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m9s
feat: support tickets between accounts and platform admins
Accounts open tickets under Support and admins answer them under Admin →
Support tickets.

- A ticket is open while it waits for the admins and answered while it
  waits for the account. Either side can close or reopen it, and a reply
  reopens it.
- The admins are mailed about new tickets and replies, and the account
  about answers.
- A ticket can name the active organization and point at a monitor,
  notification channel, alert group, status page or incident in it.
  Each must be something the account can read.
- Next to the conversation, admins see the account at a glance: state,
  sign-in, organizations with their limits and usage, and open tickets.
- Admins switch support off and limit how many tickets an account has
  open at once.
- Suspended accounts and those yet to accept the terms reach support too;
  a suspended account opens one ticket.
- Tickets are part of the account export and are deleted with the
  account.

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

296 lines
12 KiB
Templ

package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
// Me is the signed-in user as the console templates see it.
type Me struct {
// IsOwner refers to the active organization.
IsOwner bool
ActiveSlug string
Email string
DisplayName string
TOTP bool
ActiveOrg string
Orgs []Org
// Can holds the permissions in the active organization.
Can map[string]bool
// Policy is the error code of an unmet sign-in policy of the active
// organization, or empty.
Policy string
// RecoveryCodesLeft counts unused TOTP recovery codes.
RecoveryCodesLeft int
// IsAdmin marks platform admins.
IsAdmin bool
// HasPassword is false for accounts that only sign in through SSO.
HasPassword bool
// OrgSuspended is set when platform admins suspended the active
// organization, with SuspendedReason as they gave it.
OrgSuspended bool
SuspendedReason string
// DeletesOrgs names the organizations the account is the last owner
// of; deleting it deletes them, with all their monitors.
DeletesOrgs []string
// Support is set while accounts can open support tickets.
Support bool
}
// Org is one entry of the organization switcher.
type Org struct {
ID string
Name string
Slug string
IsOwner bool
}
templ consoleShell(p Page, me Me) {
@Layout(p) {
<header class="border-b border-rule">
<div class="mx-auto flex max-w-5xl flex-wrap items-center gap-x-4 gap-y-3 px-4 py-3 text-sm sm:gap-x-6 sm:px-6">
@brandLockup("/")
<span class="flex min-w-0 items-center gap-2">
if len(me.Orgs) > 1 {
<select data-switch-org class="max-w-[10rem] min-w-0 border border-rule bg-transparent px-1.5 py-0.5 text-sm sm:max-w-none">
for _, o := range me.Orgs {
<option value={ o.ID } selected?={ o.ID == me.ActiveOrg }>{ o.Name }</option>
}
</select>
} else if len(me.Orgs) == 1 {
<span class="truncate text-muted">{ me.Orgs[0].Name }</span>
}
<a href="/orgs/new" class="px-1 text-muted hover:text-ink" title={ i18n.T(ctx, "orgs.new_title") } aria-label={ i18n.T(ctx, "orgs.new_title") }>+</a>
</span>
<button
type="button"
data-nav-toggle="console-nav"
aria-controls="console-nav"
aria-expanded="false"
aria-label={ i18n.T(ctx, "console.nav.menu") }
class="ml-auto -my-1 border border-rule px-2.5 py-1 text-muted hover:text-ink lg:hidden"
>
<span aria-hidden="true">☰</span> <span class="hidden sm:inline">{ i18n.T(ctx, "console.nav.menu") }</span>
</button>
<div id="console-nav" class="hidden w-full flex-col gap-4 border-t border-rule pt-3 lg:flex lg:w-auto lg:flex-1 lg:flex-row lg:items-center lg:gap-5 lg:border-0 lg:pt-0">
<nav class="flex flex-col gap-3 lg:flex-row lg:items-center lg:gap-5 lg:whitespace-nowrap">
<a href="/" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.monitors.title") }</a>
if me.Can["statuspages.read"] {
<a href="/statuspages" class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.title") }</a>
}
if me.Can["incidents.read"] {
<a href="/incidents" class="text-muted hover:text-ink">{ i18n.T(ctx, "incidents.title") }</a>
<a href="/maintenance" class="text-muted hover:text-ink">{ i18n.T(ctx, "maintenance.title") }</a>
}
</nav>
<nav class="flex flex-col gap-3 border-t border-rule pt-3 lg:ml-auto lg:flex-row lg:items-center lg:gap-5 lg:whitespace-nowrap lg:border-0 lg:pt-0">
if me.Support {
<a href="/support" class="text-muted hover:text-ink">{ i18n.T(ctx, "support.title") }</a>
}
<a href="/settings" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.settings") }</a>
if me.IsAdmin {
<a href="/admin" class="font-medium hover:underline">{ i18n.T(ctx, "console.nav.admin") }</a>
}
<button data-logout class="text-left text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.logout") }</button>
@languageSwitch(p.Languages)
</nav>
</div>
</div>
</header>
if me.OrgSuspended {
<div class="border-b border-down bg-down/10" role="alert">
<p class="mx-auto max-w-5xl px-4 sm:px-6 py-3 text-sm">
<strong>{ i18n.T(ctx, "console.org_suspended") }</strong>
if me.SuspendedReason != "" {
{ " " + i18n.T(ctx, "console.suspended_reason", "Reason", me.SuspendedReason) }
}
</p>
</div>
}
switch me.Policy {
case "totp_required_by_org":
@policyBanner("error.totp_required_by_org", "console.totp_missing_action", "/settings/security")
case "sso_required_by_org":
@policyBanner("error.sso_required_by_org", "console.sso_required_action", "/sso/"+me.ActiveSlug)
}
<main class="mx-auto max-w-5xl px-4 py-6 sm:px-6 sm:py-10">
@flash(p)
{ children... }
</main>
}
}
// Identity is an SSO sign-in linked to the user in the active organization.
type Identity struct {
Provider string
Email string
}
// PlatformIdentities are the platform providers an account signs in with
// and those it could link.
type PlatformIdentities struct {
Linked []LinkedIdentity
Available []IDPButton
}
// LinkedIdentity is a platform provider linked to the account.
type LinkedIdentity struct {
ProviderID, Name, Email string
}
templ Security(p Page, me Me, identities []Identity, canLink bool, activity []AuditEntry, platform PlatformIdentities) {
@consoleShell(p, me) {
<h1 class="mb-8 text-lg font-semibold">{ i18n.T(ctx, "security.title") }</h1>
<section class="max-w-md">
<h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "security.totp.heading") }</h2>
if me.TOTP {
<p class="mb-1 text-sm"><span class="text-up">●</span> { i18n.T(ctx, "security.totp.active") }</p>
<p class={ "mb-6 text-sm", templ.KV("text-down", me.RecoveryCodesLeft < 3), templ.KV("text-muted", me.RecoveryCodesLeft >= 3) }>
{ i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft) }
</p>
<details class="mb-6">
<summary class="cursor-pointer text-sm text-muted hover:text-ink">{ i18n.T(ctx, "security.recovery.regenerate") }</summary>
<form data-api="/me/totp/recovery-codes" data-show-codes class="mt-4">
@formError()
@field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
@field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true)
@submit(i18n.T(ctx, "security.recovery.regenerate"))
@recoveryOutput()
</form>
</details>
<details>
<summary class="cursor-pointer text-sm text-muted hover:text-ink">{ i18n.T(ctx, "security.totp.disable") }</summary>
<form data-api="/me/totp/disable" data-next="/settings/security" class="mt-4">
@formError()
@field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
@field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true)
@submit(i18n.T(ctx, "security.totp.disable"))
</form>
</details>
} else {
<p class="mb-6 text-sm"><span class="text-unknown">●</span> { i18n.T(ctx, "security.totp.inactive") }</p>
<div data-totp-setup>
<button data-totp-start class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "security.totp.start") }</button>
<div data-totp-panel hidden>
<img data-totp-qr alt={ i18n.T(ctx, "security.totp.qr_alt") } class="mb-3 h-48 w-48 border border-rule bg-white p-2"/>
<p class="mb-6 break-all font-mono text-xs text-muted" data-totp-secret></p>
<form data-api="/me/totp/enable" data-show-codes>
@formError()
@field(i18n.T(ctx, "security.totp.app_code"), "code", "text", "one-time-code", true)
@submit(i18n.T(ctx, "security.totp.confirm"))
@recoveryOutput()
</form>
</div>
</div>
}
</section>
<section class="mt-12 max-w-md">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "security.sso.heading") }</h2>
if len(identities) == 0 {
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "security.sso.none") }</p>
} else {
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
for _, id := range identities {
<li class="flex justify-between gap-4 py-2"><span>{ id.Provider }</span><span class="font-mono text-xs text-muted">{ id.Email }</span></li>
}
</ul>
}
if canLink {
<a href={ templ.SafeURL("/sso/" + me.ActiveSlug + "?link=1") } class="inline-block border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "security.sso.link") }</a>
}
</section>
if len(platform.Linked)+len(platform.Available) > 0 {
<section class="mt-12 max-w-md">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "security.platform_sso.heading") }</h2>
if len(platform.Linked) > 0 {
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
for _, l := range platform.Linked {
<li class="flex items-center justify-between gap-4 py-2">
<span>
{ l.Name }
<span class="block font-mono text-xs text-muted">{ l.Email }</span>
</span>
<button
type="button"
data-delete={ "/me/identities/" + l.ProviderID }
data-confirm={ i18n.T(ctx, "security.platform_sso.unlink_confirm", "Name", l.Name) }
class="text-muted hover:text-down"
>{ i18n.T(ctx, "security.platform_sso.unlink") }</button>
</li>
}
</ul>
}
<div class="flex flex-wrap gap-2">
for _, a := range platform.Available {
<a href={ templ.SafeURL(a.URL) } class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "security.platform_sso.link", "Name", a.Name) }</a>
}
</div>
</section>
}
<section class="mt-12">
@sectionHeading("security.activity")
<p class="mb-4 max-w-2xl text-sm text-muted">{ i18n.T(ctx, "security.activity_intro") }</p>
@auditList(activity)
</section>
@accountDataSection(me)
}
}
// recoveryOutput is filled by app.js with codes returned by the API; they
// are shown once and never rendered by the server.
templ recoveryOutput() {
<div data-recovery-output hidden class="mt-6 border border-ink p-4">
<p class="mb-3 text-sm">{ i18n.T(ctx, "security.recovery.save_now") }</p>
<ol data-recovery-list class="mb-4 grid grid-cols-2 gap-x-6 gap-y-1 font-mono text-sm"></ol>
<a href="/settings/security" class="text-sm underline underline-offset-2">{ i18n.T(ctx, "security.recovery.saved") }</a>
</div>
}
templ policyBanner(msgID, actionID, href string) {
<div class="border-b border-degraded/40 bg-degraded/10">
<p class="mx-auto max-w-5xl px-4 sm:px-6 py-2 text-sm">
{ i18n.T(ctx, msgID) }
<a href={ templ.SafeURL(href) } class="underline underline-offset-2">{ i18n.T(ctx, actionID) }</a>
</p>
</div>
}
templ settingsLink(href, titleID, hintID string) {
<a href={ templ.SafeURL(href) } class="block border border-rule p-4 hover:border-ink">
<span class="block font-medium">{ i18n.T(ctx, titleID) }</span>
<span class="mt-1 block text-sm text-muted">{ i18n.T(ctx, hintID) }</span>
</a>
}
// SettingsIndex lists the settings the user may open.
templ SettingsIndex(p Page, me Me) {
@consoleShell(p, me) {
@settingsHeading("console.nav.settings", "")
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
if me.Can["notifications.read"] {
@settingsLink("/settings/channels", "channels.title", "settings.channels")
}
@settingsLink("/groups", "groups.title", "settings.groups")
if me.Can["incidents.read"] {
@settingsLink("/settings/incident-statuses", "incident_statuses.title", "settings.incident_statuses")
}
if me.Can["members.read"] {
@settingsLink("/settings/members", "console.nav.members", "settings.members")
@settingsLink("/settings/roles", "console.nav.roles", "settings.roles")
}
if len(me.Orgs) > 0 {
@settingsLink("/settings/tokens", "console.nav.tokens", "settings.tokens")
@settingsLink("/api/docs", "apidocs.title", "settings.apidocs")
}
if me.Can["org.manage"] {
@settingsLink("/settings/regions", "console.nav.regions", "settings.regions")
@settingsLink("/settings/org", "console.nav.org", "settings.org")
@settingsLink("/settings/sso", "console.nav.sso", "settings.sso")
@settingsLink("/settings/legal", "legal.org_title", "settings.legal")
@settingsLink("/settings/alertmanager", "alertmanager.title", "settings.alertmanager")
}
if me.Can["audit.read"] {
@settingsLink("/settings/audit", "audit.title", "settings.audit")
}
@settingsLink("/settings/security", "console.nav.security", "settings.security")
</div>
}
}