feat: admins suspend or delete status pages, organizations and accounts
ci / image (pull_request) Successful in 3m20s
ci / build (pull_request) Successful in 8m34s
ci / test (pull_request) Successful in 11m41s
ci / lint (pull_request) Successful in 13m0s

The admin panel lists every published status page, and every suspended
page, organization or account, with the organization and owner behind
it, searchable by title, address, organization or email. Each can be
suspended with a reason, reinstated, or deleted.

A suspended page is not served; status page servers drop it when they
next ask. A suspended organization's monitors leave the schedule, its
pages go offline, heartbeat pings and Alertmanager webhooks are no
longer recorded, and its members and API tokens get 403 org_suspended;
the console explains why. Reinstating restarts heartbeat waits so they
do not fire at once. A suspended account is signed out everywhere and
can neither sign in nor use its tokens; only someone who knows the
password learns of the suspension. Platform admins cannot be suspended
or deleted. Account deletion shares its logic with the GDPR erasure,
including the refusal while the account owns shared organizations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 20:46:46 +01:00
1 parent db37060c70
commit 90e74d091a
37 files changed
+3109 -1140

No files matched your search

+201
View File
@@ -0,0 +1,201 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: moderation.sql
package store
import (
"context"
"time"
"github.com/google/uuid"
)
const adminListStatusPages = `-- name: AdminListStatusPages :many
SELECT p.id, p.slug, p.title, p.published, p.custom_domain, p.domain_verified_at,
p.suspended_at, p.suspended_reason, p.created_at,
o.id AS org_id, o.slug AS org_slug, o.name AS org_name, o.suspended_at AS org_suspended_at, o.suspended_reason AS org_suspended_reason,
coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id,
coalesce(ow.email::text, '')::text AS owner_email, ow.disabled_at AS owner_disabled_at,
coalesce(ow.disabled_reason, '')::text AS owner_disabled_reason, coalesce(ow.is_admin, false)::boolean AS owner_is_admin
FROM status_pages p
JOIN orgs o ON o.id = p.org_id
LEFT JOIN LATERAL (
SELECT u.id, u.email, u.disabled_at, u.disabled_reason, u.is_admin FROM memberships m JOIN users u ON u.id = m.user_id
WHERE m.org_id = o.id AND m.is_owner ORDER BY m.created_at LIMIT 1
) ow ON true
WHERE (p.published OR p.suspended_at IS NOT NULL OR o.suspended_at IS NOT NULL)
AND ($1::text = ''
OR p.title ILIKE '%' || $1 || '%' OR p.slug::text ILIKE '%' || $1 || '%'
OR coalesce(p.custom_domain::text, '') ILIKE '%' || $1 || '%'
OR o.name ILIKE '%' || $1 || '%' OR o.slug::text ILIKE '%' || $1 || '%'
OR coalesce(ow.email::text, '') ILIKE '%' || $1 || '%')
ORDER BY p.created_at DESC
LIMIT $2
`
type AdminListStatusPagesParams struct {
Search string
MaxRows int32
}
type AdminListStatusPagesRow struct {
ID uuid.UUID
Slug string
Title string
Published bool
CustomDomain *string
DomainVerifiedAt *time.Time
SuspendedAt *time.Time
SuspendedReason string
CreatedAt time.Time
OrgID uuid.UUID
OrgSlug string
OrgName string
OrgSuspendedAt *time.Time
OrgSuspendedReason string
OwnerID uuid.UUID
OwnerEmail string
OwnerDisabledAt *time.Time
OwnerDisabledReason string
OwnerIsAdmin bool
}
// System scope: public status pages and suspended ones, with their
// organization and its owner, newest first, matching search in title,
// slug, domain, organization or owner email.
func (q *Queries) AdminListStatusPages(ctx context.Context, arg AdminListStatusPagesParams) ([]AdminListStatusPagesRow, error) {
rows, err := q.db.Query(ctx, adminListStatusPages, arg.Search, arg.MaxRows)
if err != nil {
return nil, err
}
defer rows.Close()
items := []AdminListStatusPagesRow{}
for rows.Next() {
var i AdminListStatusPagesRow
if err := rows.Scan(
&i.ID,
&i.Slug,
&i.Title,
&i.Published,
&i.CustomDomain,
&i.DomainVerifiedAt,
&i.SuspendedAt,
&i.SuspendedReason,
&i.CreatedAt,
&i.OrgID,
&i.OrgSlug,
&i.OrgName,
&i.OrgSuspendedAt,
&i.OrgSuspendedReason,
&i.OwnerID,
&i.OwnerEmail,
&i.OwnerDisabledAt,
&i.OwnerDisabledReason,
&i.OwnerIsAdmin,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const restartHeartbeatWait = `-- name: RestartHeartbeatWait :exec
UPDATE monitors SET updated_at = now() WHERE org_id = $1 AND type = 'heartbeat'
`
// Heartbeats of an organization wait afresh after its suspension, during
// which pings were refused.
func (q *Queries) RestartHeartbeatWait(ctx context.Context, orgID uuid.UUID) error {
_, err := q.db.Exec(ctx, restartHeartbeatWait, orgID)
return err
}
const suspendOrg = `-- name: SuspendOrg :one
UPDATE orgs SET suspended_at = CASE WHEN $1::boolean THEN coalesce(suspended_at, now()) END,
suspended_reason = CASE WHEN $1::boolean THEN $2::text ELSE '' END
WHERE id = $3
RETURNING id, slug, name
`
type SuspendOrgParams struct {
Suspend bool
Reason string
ID uuid.UUID
}
type SuspendOrgRow struct {
ID uuid.UUID
Slug string
Name string
}
func (q *Queries) SuspendOrg(ctx context.Context, arg SuspendOrgParams) (SuspendOrgRow, error) {
row := q.db.QueryRow(ctx, suspendOrg, arg.Suspend, arg.Reason, arg.ID)
var i SuspendOrgRow
err := row.Scan(&i.ID, &i.Slug, &i.Name)
return i, err
}
const suspendStatusPage = `-- name: SuspendStatusPage :one
UPDATE status_pages SET suspended_at = CASE WHEN $1::boolean THEN coalesce(suspended_at, now()) END,
suspended_reason = CASE WHEN $1::boolean THEN $2::text ELSE '' END
WHERE id = $3
RETURNING id, org_id, slug, custom_domain
`
type SuspendStatusPageParams struct {
Suspend bool
Reason string
ID uuid.UUID
}
type SuspendStatusPageRow struct {
ID uuid.UUID
OrgID uuid.UUID
Slug string
CustomDomain *string
}
func (q *Queries) SuspendStatusPage(ctx context.Context, arg SuspendStatusPageParams) (SuspendStatusPageRow, error) {
row := q.db.QueryRow(ctx, suspendStatusPage, arg.Suspend, arg.Reason, arg.ID)
var i SuspendStatusPageRow
err := row.Scan(
&i.ID,
&i.OrgID,
&i.Slug,
&i.CustomDomain,
)
return i, err
}
const suspendUser = `-- name: SuspendUser :one
UPDATE users SET disabled_at = CASE WHEN $1::boolean THEN coalesce(disabled_at, now()) END,
disabled_reason = CASE WHEN $1::boolean THEN $2::text ELSE '' END
WHERE id = $3
RETURNING id, email, is_admin
`
type SuspendUserParams struct {
Suspend bool
Reason string
ID uuid.UUID
}
type SuspendUserRow struct {
ID uuid.UUID
Email string
IsAdmin bool
}
func (q *Queries) SuspendUser(ctx context.Context, arg SuspendUserParams) (SuspendUserRow, error) {
row := q.db.QueryRow(ctx, suspendUser, arg.Suspend, arg.Reason, arg.ID)
var i SuspendUserRow
err := row.Scan(&i.ID, &i.Email, &i.IsAdmin)
return i, err
}