Lists that were cut off by a fixed LIMIT, or could grow without bound, are paged by keyset: the cursor holds the sort key and an ID, so pages neither skip nor repeat items as others are added. The audit logs had a timestamp-only cursor that could skip entries with equal times. The API returns at most 100 items per list (limit takes up to 500) with next_cursor and prev_cursor, passed back as after and before. The console shows Newer/Older (or Previous/Next) links and To the start, without JavaScript. Paged: incidents (optionally of one monitor), a monitor's results and evidence, a checker's results, the audit logs, members, maintenance windows, firing Alertmanager alerts, the monitors API and the admin lists of status pages and organizations, which move to their own admin pages. A monitor's page shows its latest incidents and results and links to all of them. The dashboard caps every group at 50 of its own monitors with a link to a paged view of the group, and gains a search by name or target. Lists filtered by permission after reading may show fewer items on a page. Closes #116 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
218 lines
6.1 KiB
Go
218 lines
6.1 KiB
Go
// 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 || '%')
|
|
AND ($2::timestamptz IS NULL OR (p.created_at, p.id) < ($2, $3::uuid))
|
|
AND ($4::timestamptz IS NULL OR (p.created_at, p.id) > ($4, $5::uuid))
|
|
ORDER BY
|
|
CASE WHEN $4::timestamptz IS NULL THEN p.created_at END DESC,
|
|
CASE WHEN $4::timestamptz IS NULL THEN p.id END DESC,
|
|
p.created_at, p.id
|
|
LIMIT $6
|
|
`
|
|
|
|
type AdminListStatusPagesParams struct {
|
|
Search string
|
|
AfterT *time.Time
|
|
AfterID *uuid.UUID
|
|
BeforeT *time.Time
|
|
BeforeID *uuid.UUID
|
|
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, matching search in title, slug, domain,
|
|
// organization or owner email; newest first, a page from a keyset cursor.
|
|
func (q *Queries) AdminListStatusPages(ctx context.Context, arg AdminListStatusPagesParams) ([]AdminListStatusPagesRow, error) {
|
|
rows, err := q.db.Query(ctx, adminListStatusPages,
|
|
arg.Search,
|
|
arg.AfterT,
|
|
arg.AfterID,
|
|
arg.BeforeT,
|
|
arg.BeforeID,
|
|
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
|
|
}
|