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

+2
View File
@@ -13,6 +13,7 @@ DELETE FROM alertmanager_receivers WHERE id = $1;
-- System scope: the receiver a webhook token belongs to.
UPDATE alertmanager_receivers SET last_received_at = now()
WHERE token_hash = $1
AND NOT EXISTS (SELECT 1 FROM orgs o WHERE o.id = alertmanager_receivers.org_id AND o.suspended_at IS NOT NULL)
RETURNING id, org_id;
-- name: UpsertAlertmanagerAlert :exec
@@ -41,6 +42,7 @@ SELECT m.id, m.org_id, m.name, m.group_id, m.interval_seconds, m.confirmations,
coalesce((SELECT max(r.time) FROM check_results r
WHERE r.org_id = m.org_id AND r.monitor_id = m.id AND r.time > now() - interval '2 days'), 'epoch')::timestamptz AS last_result
FROM monitors m
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
WHERE m.type = 'alertmanager' AND m.enabled AND (sqlc.narg(org_id)::uuid IS NULL OR m.org_id = sqlc.narg(org_id));
-- name: LatestResultForMonitor :one
+4 -2
View File
@@ -1,7 +1,8 @@
-- name: HeartbeatMonitor :one
-- System scope: the monitor a ping token belongs to.
SELECT id, org_id, interval_seconds, confirmations, enabled
FROM monitors WHERE type = 'heartbeat' AND target = $1;
SELECT m.id, m.org_id, m.interval_seconds, m.confirmations, coalesce(m.enabled AND o.suspended_at IS NULL, false)::boolean AS enabled
FROM monitors m JOIN orgs o ON o.id = m.org_id
WHERE m.type = 'heartbeat' AND m.target = $1;
-- name: HeartbeatsDue :many
-- System scope: enabled heartbeat monitors with their grace period and
@@ -13,4 +14,5 @@ SELECT m.id, m.org_id, m.interval_seconds, m.confirmations,
greatest(m.updated_at, coalesce((SELECT max(r.time) FROM check_results r
WHERE r.org_id = m.org_id AND r.monitor_id = m.id AND r.time > now() - interval '3 days'), m.updated_at))::timestamptz AS waiting_since
FROM monitors m
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
WHERE m.type = 'heartbeat' AND m.enabled;
+48
View File
@@ -0,0 +1,48 @@
-- name: AdminListStatusPages :many
-- 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.
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 (sqlc.arg(search)::text = ''
OR p.title ILIKE '%' || sqlc.arg(search) || '%' OR p.slug::text ILIKE '%' || sqlc.arg(search) || '%'
OR coalesce(p.custom_domain::text, '') ILIKE '%' || sqlc.arg(search) || '%'
OR o.name ILIKE '%' || sqlc.arg(search) || '%' OR o.slug::text ILIKE '%' || sqlc.arg(search) || '%'
OR coalesce(ow.email::text, '') ILIKE '%' || sqlc.arg(search) || '%')
ORDER BY p.created_at DESC
LIMIT sqlc.arg(max_rows);
-- name: SuspendStatusPage :one
UPDATE status_pages SET suspended_at = CASE WHEN sqlc.arg(suspend)::boolean THEN coalesce(suspended_at, now()) END,
suspended_reason = CASE WHEN sqlc.arg(suspend)::boolean THEN sqlc.arg(reason)::text ELSE '' END
WHERE id = sqlc.arg(id)
RETURNING id, org_id, slug, custom_domain;
-- name: SuspendOrg :one
UPDATE orgs SET suspended_at = CASE WHEN sqlc.arg(suspend)::boolean THEN coalesce(suspended_at, now()) END,
suspended_reason = CASE WHEN sqlc.arg(suspend)::boolean THEN sqlc.arg(reason)::text ELSE '' END
WHERE id = sqlc.arg(id)
RETURNING id, slug, name;
-- name: SuspendUser :one
UPDATE users SET disabled_at = CASE WHEN sqlc.arg(suspend)::boolean THEN coalesce(disabled_at, now()) END,
disabled_reason = CASE WHEN sqlc.arg(suspend)::boolean THEN sqlc.arg(reason)::text ELSE '' END
WHERE id = sqlc.arg(id)
RETURNING id, email, is_admin;
-- name: RestartHeartbeatWait :exec
-- Heartbeats of an organization wait afresh after its suspension, during
-- which pings were refused.
UPDATE monitors SET updated_at = now() WHERE org_id = $1 AND type = 'heartbeat';
+3
View File
@@ -36,6 +36,7 @@ INSERT INTO monitor_regions (monitor_id, org_id, region_id) VALUES ($1, $2, $3);
SELECT m.id, m.interval_seconds, array_agg(r.region_id::text ORDER BY r.region_id)::text[] AS regions
FROM monitors m
JOIN monitor_regions r ON r.monitor_id = m.id
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
WHERE m.enabled
GROUP BY m.id, m.interval_seconds;
@@ -45,6 +46,7 @@ GROUP BY m.id, m.interval_seconds;
-- org-owned checker only ever sees its org's monitors.
SELECT m.* FROM monitors m
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = sqlc.arg(region_id)
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
WHERE m.id = ANY (sqlc.arg(ids)::uuid[]) AND m.enabled
AND (sqlc.narg(agent_org)::uuid IS NULL OR m.org_id = sqlc.narg(agent_org));
@@ -55,5 +57,6 @@ SELECT m.id, m.org_id, m.name, m.target, m.interval_seconds, m.confirmations,
(SELECT array_agg(r2.region_id::text ORDER BY r2.region_id) FROM monitor_regions r2 WHERE r2.monitor_id = m.id)::text[] AS regions
FROM monitors m
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = sqlc.arg(region_id)
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
WHERE m.id = ANY (sqlc.arg(ids)::uuid[]) AND m.enabled
AND (sqlc.narg(agent_org)::uuid IS NULL OR m.org_id = sqlc.narg(agent_org));
+2 -1
View File
@@ -89,6 +89,7 @@ DELETE FROM status_page_groups WHERE page_id = $1;
-- System scope: resolves a request to a page by verified custom domain or
-- by slug.
SELECT * FROM status_pages
WHERE published
WHERE published AND suspended_at IS NULL
AND NOT EXISTS (SELECT 1 FROM orgs o WHERE o.id = status_pages.org_id AND o.suspended_at IS NOT NULL)
AND ((sqlc.narg(host)::citext IS NOT NULL AND custom_domain = sqlc.narg(host) AND domain_verified_at IS NOT NULL)
OR (sqlc.narg(slug)::citext IS NOT NULL AND slug = sqlc.narg(slug)));