Admins set default limits for monitors (all types), status pages and regions per monitor, whether an organization's own checker regions count towards the region limit, and how many organizations an account may own, and override them per organization or account. Defaults are not copied: changing one applies at once to everyone without an override. 0 means unlimited; self-hosted defaults are unlimited, the cloud allows three organizations per account. Creations count under a per-organization advisory lock, so concurrent requests cannot overshoot. A lowered limit keeps everything that exists: monitors already beyond the region limit stay editable but may not grow. Organizations see their usage in their settings and GET /org/limits; the admin panel lists organizations with owner, usage and limits next to their suspend and delete actions. Empty numeric form fields marked data-nullable are sent as null. Refs #111 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
201 lines
4.8 KiB
Go
201 lines
4.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: users.sql
|
|
|
|
package store
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const anyUserExists = `-- name: AnyUserExists :one
|
|
SELECT EXISTS (SELECT 1 FROM users)
|
|
`
|
|
|
|
func (q *Queries) AnyUserExists(ctx context.Context) (bool, error) {
|
|
row := q.db.QueryRow(ctx, anyUserExists)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
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, disabled_reason, limit_orgs
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Email string
|
|
DisplayName string
|
|
PasswordHash *string
|
|
Locale *string
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
row := q.db.QueryRow(ctx, createUser,
|
|
arg.Email,
|
|
arg.DisplayName,
|
|
arg.PasswordHash,
|
|
arg.Locale,
|
|
)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.DisplayName,
|
|
&i.PasswordHash,
|
|
&i.DisabledAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.TotpSecret,
|
|
&i.TotpEnabledAt,
|
|
&i.Locale,
|
|
&i.IsAdmin,
|
|
&i.DisabledReason,
|
|
&i.LimitOrgs,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteUser = `-- name: DeleteUser :execrows
|
|
DELETE FROM users WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteUser(ctx context.Context, id uuid.UUID) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteUser, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const disableTOTP = `-- name: DisableTOTP :exec
|
|
UPDATE users SET totp_secret = NULL, totp_enabled_at = NULL, updated_at = now() WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DisableTOTP(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, disableTOTP, id)
|
|
return err
|
|
}
|
|
|
|
const enableTOTP = `-- name: EnableTOTP :exec
|
|
UPDATE users SET totp_secret = $2, totp_enabled_at = now(), updated_at = now() WHERE id = $1
|
|
`
|
|
|
|
type EnableTOTPParams struct {
|
|
ID uuid.UUID
|
|
TotpSecret []byte
|
|
}
|
|
|
|
func (q *Queries) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error {
|
|
_, err := q.db.Exec(ctx, enableTOTP, arg.ID, arg.TotpSecret)
|
|
return err
|
|
}
|
|
|
|
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, disabled_reason, limit_orgs FROM users WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUser, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.DisplayName,
|
|
&i.PasswordHash,
|
|
&i.DisabledAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.TotpSecret,
|
|
&i.TotpEnabledAt,
|
|
&i.Locale,
|
|
&i.IsAdmin,
|
|
&i.DisabledReason,
|
|
&i.LimitOrgs,
|
|
)
|
|
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, disabled_reason, limit_orgs FROM users WHERE email = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByEmail, email)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.DisplayName,
|
|
&i.PasswordHash,
|
|
&i.DisabledAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.TotpSecret,
|
|
&i.TotpEnabledAt,
|
|
&i.Locale,
|
|
&i.IsAdmin,
|
|
&i.DisabledReason,
|
|
&i.LimitOrgs,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const makeAdmin = `-- name: MakeAdmin :exec
|
|
UPDATE users SET is_admin = true, updated_at = now() WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) MakeAdmin(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, makeAdmin, id)
|
|
return err
|
|
}
|
|
|
|
const setPasswordHash = `-- name: SetPasswordHash :exec
|
|
UPDATE users SET password_hash = $2, updated_at = now() WHERE id = $1
|
|
`
|
|
|
|
type SetPasswordHashParams struct {
|
|
ID uuid.UUID
|
|
PasswordHash *string
|
|
}
|
|
|
|
func (q *Queries) SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error {
|
|
_, err := q.db.Exec(ctx, setPasswordHash, arg.ID, arg.PasswordHash)
|
|
return err
|
|
}
|
|
|
|
const setUserAdmin = `-- name: SetUserAdmin :execrows
|
|
UPDATE users SET is_admin = $2, updated_at = now() WHERE email = $1
|
|
`
|
|
|
|
type SetUserAdminParams struct {
|
|
Email string
|
|
IsAdmin bool
|
|
}
|
|
|
|
func (q *Queries) SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, setUserAdmin, arg.Email, arg.IsAdmin)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const setUserLocale = `-- name: SetUserLocale :exec
|
|
UPDATE users SET locale = $2, updated_at = now() WHERE id = $1
|
|
`
|
|
|
|
type SetUserLocaleParams struct {
|
|
ID uuid.UUID
|
|
Locale *string
|
|
}
|
|
|
|
func (q *Queries) SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error {
|
|
_, err := q.db.Exec(ctx, setUserLocale, arg.ID, arg.Locale)
|
|
return err
|
|
}
|