feat: admins suspend or delete status pages, organizations and accounts
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:
1 parent
db37060c70
commit
90e74d091a
37 files changed
+3109
-1140
No files matched your search
@@ -17,6 +17,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 ($1::uuid IS NULL OR m.org_id = $1)
|
||||
`
|
||||
|
||||
@@ -65,6 +66,7 @@ func (q *Queries) AlertmanagerMonitors(ctx context.Context, orgID *uuid.UUID) ([
|
||||
const alertmanagerReceiverByHash = `-- name: AlertmanagerReceiverByHash :one
|
||||
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
|
||||
`
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@ import (
|
||||
)
|
||||
|
||||
const heartbeatMonitor = `-- name: HeartbeatMonitor :one
|
||||
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
|
||||
`
|
||||
|
||||
type HeartbeatMonitorRow struct {
|
||||
@@ -45,6 +46,7 @@ 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
|
||||
`
|
||||
|
||||
|
||||
+16
-11
@@ -284,6 +284,8 @@ type Org struct {
|
||||
RequireSso bool
|
||||
ApiTokenMaxDays *int32
|
||||
DisabledCheckTypes []string
|
||||
SuspendedAt *time.Time
|
||||
SuspendedReason string
|
||||
}
|
||||
|
||||
type PlatformSetting struct {
|
||||
@@ -357,6 +359,8 @@ type StatusPage struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ShowComponentDetails bool
|
||||
SuspendedAt *time.Time
|
||||
SuspendedReason string
|
||||
}
|
||||
|
||||
type StatusPageGroup struct {
|
||||
@@ -381,17 +385,18 @@ type StatusPageMonitor struct {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID
|
||||
Email string
|
||||
DisplayName string
|
||||
PasswordHash *string
|
||||
DisabledAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
TotpSecret []byte
|
||||
TotpEnabledAt *time.Time
|
||||
Locale *string
|
||||
IsAdmin bool
|
||||
ID uuid.UUID
|
||||
Email string
|
||||
DisplayName string
|
||||
PasswordHash *string
|
||||
DisabledAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
TotpSecret []byte
|
||||
TotpEnabledAt *time.Time
|
||||
Locale *string
|
||||
IsAdmin bool
|
||||
DisabledReason string
|
||||
}
|
||||
|
||||
type UserIdentity struct {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -156,6 +156,7 @@ const listEnabledMonitorsForSchedule = `-- name: ListEnabledMonitorsForSchedule
|
||||
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
|
||||
`
|
||||
@@ -253,6 +254,7 @@ func (q *Queries) MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uu
|
||||
const monitorsForJobs = `-- name: MonitorsForJobs :many
|
||||
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations, m.group_id FROM monitors m
|
||||
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = $1
|
||||
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
|
||||
WHERE m.id = ANY ($2::uuid[]) AND m.enabled
|
||||
AND ($3::uuid IS NULL OR m.org_id = $3)
|
||||
`
|
||||
@@ -305,6 +307,7 @@ 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 = $1
|
||||
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
|
||||
WHERE m.id = ANY ($2::uuid[]) AND m.enabled
|
||||
AND ($3::uuid IS NULL OR m.org_id = $3)
|
||||
`
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const createOrg = `-- name: CreateOrg :one
|
||||
INSERT INTO orgs (id, slug, name) VALUES ($1, $2, $3)
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason
|
||||
`
|
||||
|
||||
type CreateOrgParams struct {
|
||||
@@ -35,6 +35,8 @@ func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, erro
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -52,7 +54,7 @@ func (q *Queries) DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error) {
|
||||
}
|
||||
|
||||
const getOrg = `-- name: GetOrg :one
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types FROM orgs WHERE id = $1
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason FROM orgs WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||
@@ -68,12 +70,14 @@ func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getOrgBySlug = `-- name: GetOrgBySlug :one
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types FROM orgs WHERE slug = $1
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason FROM orgs WHERE slug = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||
@@ -89,12 +93,14 @@ func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listOrgs = `-- name: ListOrgs :many
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types FROM orgs ORDER BY name
|
||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason FROM orgs ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
@@ -116,6 +122,8 @@ func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,7 +152,7 @@ func (q *Queries) SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabl
|
||||
const updateOrgPolicy = `-- name: UpdateOrgPolicy :one
|
||||
UPDATE orgs SET require_totp = $2, require_sso = $3, api_token_max_days = $4, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason
|
||||
`
|
||||
|
||||
type UpdateOrgPolicyParams struct {
|
||||
@@ -172,6 +180,8 @@ func (q *Queries) UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams
|
||||
&i.RequireSso,
|
||||
&i.ApiTokenMaxDays,
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -19,6 +19,10 @@ type Querier interface {
|
||||
AddMonitorAlertGroup(ctx context.Context, arg AddMonitorAlertGroupParams) (int64, error)
|
||||
AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error
|
||||
AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error
|
||||
// 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.
|
||||
AdminListStatusPages(ctx context.Context, arg AdminListStatusPagesParams) ([]AdminListStatusPagesRow, error)
|
||||
AgentInstancesByID(ctx context.Context, ids []uuid.UUID) ([]AgentInstancesByIDRow, error)
|
||||
// System scope: enabled alertmanager monitors of org, with when they last
|
||||
// recorded a result.
|
||||
@@ -251,6 +255,9 @@ type Querier interface {
|
||||
ReparentStatusPageGroupChildren(ctx context.Context, arg ReparentStatusPageGroupChildrenParams) error
|
||||
ReparentStatusPageGroupMonitors(ctx context.Context, arg ReparentStatusPageGroupMonitorsParams) error
|
||||
ResolveIncident(ctx context.Context, arg ResolveIncidentParams) (Incident, error)
|
||||
// Heartbeats of an organization wait afresh after its suspension, during
|
||||
// which pings were refused.
|
||||
RestartHeartbeatWait(ctx context.Context, orgID uuid.UUID) error
|
||||
// The organization's latest results run by one checker instance.
|
||||
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
|
||||
ScrubAuditEmail(ctx context.Context, email string) error
|
||||
@@ -271,6 +278,9 @@ type Querier interface {
|
||||
StorageGet(ctx context.Context, arg StorageGetParams) (StorageGetRow, error)
|
||||
StorageList(ctx context.Context, arg StorageListParams) ([]StorageListRow, error)
|
||||
StoragePut(ctx context.Context, arg StoragePutParams) error
|
||||
SuspendOrg(ctx context.Context, arg SuspendOrgParams) (SuspendOrgRow, error)
|
||||
SuspendStatusPage(ctx context.Context, arg SuspendStatusPageParams) (SuspendStatusPageRow, error)
|
||||
SuspendUser(ctx context.Context, arg SuspendUserParams) (SuspendUserRow, error)
|
||||
TouchAPIToken(ctx context.Context, id uuid.UUID) error
|
||||
TouchAgent(ctx context.Context, arg TouchAgentParams) error
|
||||
// Writes at most once a minute per instance; agents poll far more often.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
|
||||
@@ -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));
|
||||
@@ -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)));
|
||||
@@ -60,7 +60,7 @@ func (q *Queries) ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID)
|
||||
const createStatusPage = `-- name: CreateStatusPage :one
|
||||
INSERT INTO status_pages (org_id, slug, title, description, published, show_component_details, domain_token, theme)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason
|
||||
`
|
||||
|
||||
type CreateStatusPageParams struct {
|
||||
@@ -100,6 +100,8 @@ func (q *Queries) CreateStatusPage(ctx context.Context, arg CreateStatusPagePara
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -170,8 +172,9 @@ func (q *Queries) DeleteStatusPageGroup(ctx context.Context, arg DeleteStatusPag
|
||||
}
|
||||
|
||||
const findPublishedPage = `-- name: FindPublishedPage :one
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details FROM status_pages
|
||||
WHERE published
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason FROM status_pages
|
||||
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 (($1::citext IS NOT NULL AND custom_domain = $1 AND domain_verified_at IS NOT NULL)
|
||||
OR ($2::citext IS NOT NULL AND slug = $2))
|
||||
`
|
||||
@@ -200,12 +203,14 @@ func (q *Queries) FindPublishedPage(ctx context.Context, arg FindPublishedPagePa
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getStatusPage = `-- name: GetStatusPage :one
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details FROM status_pages WHERE id = $1
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason FROM status_pages WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error) {
|
||||
@@ -225,6 +230,8 @@ func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -265,7 +272,7 @@ func (q *Queries) ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([
|
||||
}
|
||||
|
||||
const listStatusPages = `-- name: ListStatusPages :many
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details FROM status_pages ORDER BY title
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason FROM status_pages ORDER BY title
|
||||
`
|
||||
|
||||
func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
|
||||
@@ -291,6 +298,8 @@ func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -349,7 +358,7 @@ UPDATE status_pages SET
|
||||
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verified_at END,
|
||||
updated_at = now()
|
||||
WHERE id = $2
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason
|
||||
`
|
||||
|
||||
type SetStatusPageDomainParams struct {
|
||||
@@ -375,6 +384,8 @@ func (q *Queries) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDoma
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -460,7 +471,7 @@ SET slug = $2,
|
||||
theme = $7,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason
|
||||
`
|
||||
|
||||
type UpdateStatusPageParams struct {
|
||||
@@ -498,6 +509,8 @@ func (q *Queries) UpdateStatusPage(ctx context.Context, arg UpdateStatusPagePara
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ShowComponentDetails,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func (q *Queries) AnyUserExists(ctx context.Context) (bool, error) {
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin
|
||||
RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
@@ -54,6 +54,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
||||
&i.TotpEnabledAt,
|
||||
&i.Locale,
|
||||
&i.IsAdmin,
|
||||
&i.DisabledReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -94,7 +95,7 @@ func (q *Queries) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error {
|
||||
}
|
||||
|
||||
const getUser = `-- name: GetUser :one
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin FROM users WHERE id = $1
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
@@ -112,12 +113,13 @@ func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
&i.TotpEnabledAt,
|
||||
&i.Locale,
|
||||
&i.IsAdmin,
|
||||
&i.DisabledReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin FROM users WHERE email = $1
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason FROM users WHERE email = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
||||
@@ -135,6 +137,7 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error
|
||||
&i.TotpEnabledAt,
|
||||
&i.Locale,
|
||||
&i.IsAdmin,
|
||||
&i.DisabledReason,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user