feat: per-organization limits set by platform admins
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
This commit is contained in:
1 parent
90e74d091a
commit
e4ce619fbe
26 files changed
+2386
-82
No files matched your search
@@ -0,0 +1,194 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: limits.sql
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const adminListOrgs = `-- name: AdminListOrgs :many
|
||||
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
||||
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
||||
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
||||
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
||||
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,
|
||||
ow.limit_orgs AS owner_limit_orgs,
|
||||
coalesce(ow.owned, 0)::integer AS owner_orgs
|
||||
FROM orgs o
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT u.id, u.email, u.disabled_at, u.disabled_reason, u.is_admin, u.limit_orgs,
|
||||
(SELECT count(*) FROM memberships m2 WHERE m2.user_id = u.id AND m2.is_owner) AS owned
|
||||
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 $1::text = ''
|
||||
OR o.name ILIKE '%' || $1 || '%' OR o.slug::text ILIKE '%' || $1 || '%'
|
||||
OR coalesce(ow.email::text, '') ILIKE '%' || $1 || '%'
|
||||
ORDER BY o.created_at DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
type AdminListOrgsParams struct {
|
||||
Search string
|
||||
MaxRows int32
|
||||
}
|
||||
|
||||
type AdminListOrgsRow struct {
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Name string
|
||||
CreatedAt time.Time
|
||||
SuspendedAt *time.Time
|
||||
SuspendedReason string
|
||||
LimitMonitors *int32
|
||||
LimitStatusPages *int32
|
||||
LimitRegionsPerMonitor *int32
|
||||
LimitOwnRegionsCount *bool
|
||||
Monitors int32
|
||||
StatusPages int32
|
||||
OwnerID uuid.UUID
|
||||
OwnerEmail string
|
||||
OwnerDisabledAt *time.Time
|
||||
OwnerDisabledReason string
|
||||
OwnerIsAdmin bool
|
||||
OwnerLimitOrgs *int32
|
||||
OwnerOrgs int32
|
||||
}
|
||||
|
||||
// System scope: organizations with their usage, limit overrides and owner,
|
||||
// newest first, matching search in name, slug or owner email.
|
||||
func (q *Queries) AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([]AdminListOrgsRow, error) {
|
||||
rows, err := q.db.Query(ctx, adminListOrgs, arg.Search, arg.MaxRows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []AdminListOrgsRow{}
|
||||
for rows.Next() {
|
||||
var i AdminListOrgsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Slug,
|
||||
&i.Name,
|
||||
&i.CreatedAt,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
&i.LimitMonitors,
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
&i.Monitors,
|
||||
&i.StatusPages,
|
||||
&i.OwnerID,
|
||||
&i.OwnerEmail,
|
||||
&i.OwnerDisabledAt,
|
||||
&i.OwnerDisabledReason,
|
||||
&i.OwnerIsAdmin,
|
||||
&i.OwnerLimitOrgs,
|
||||
&i.OwnerOrgs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const countMonitors = `-- name: CountMonitors :one
|
||||
SELECT count(*) FROM monitors WHERE org_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countMonitors, orgID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const countStatusPages = `-- name: CountStatusPages :one
|
||||
SELECT count(*) FROM status_pages WHERE org_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countStatusPages, orgID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const lockOrgUsage = `-- name: LockOrgUsage :exec
|
||||
SELECT pg_advisory_xact_lock(hashtextextended('usage:' || $1::uuid::text, 0))
|
||||
`
|
||||
|
||||
// Serializes creations counted against org's limits until the transaction
|
||||
// ends.
|
||||
func (q *Queries) LockOrgUsage(ctx context.Context, orgID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, lockOrgUsage, orgID)
|
||||
return err
|
||||
}
|
||||
|
||||
const setOrgLimits = `-- name: SetOrgLimits :one
|
||||
UPDATE orgs SET limit_monitors = $1, limit_status_pages = $2,
|
||||
limit_regions_per_monitor = $3, limit_own_regions_count = $4
|
||||
WHERE id = $5
|
||||
RETURNING id, slug
|
||||
`
|
||||
|
||||
type SetOrgLimitsParams struct {
|
||||
Monitors *int32
|
||||
StatusPages *int32
|
||||
RegionsPerMonitor *int32
|
||||
OwnRegionsCount *bool
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
type SetOrgLimitsRow struct {
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
}
|
||||
|
||||
func (q *Queries) SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error) {
|
||||
row := q.db.QueryRow(ctx, setOrgLimits,
|
||||
arg.Monitors,
|
||||
arg.StatusPages,
|
||||
arg.RegionsPerMonitor,
|
||||
arg.OwnRegionsCount,
|
||||
arg.ID,
|
||||
)
|
||||
var i SetOrgLimitsRow
|
||||
err := row.Scan(&i.ID, &i.Slug)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setUserOrgLimit = `-- name: SetUserOrgLimit :one
|
||||
UPDATE users SET limit_orgs = $1 WHERE id = $2
|
||||
RETURNING id, email
|
||||
`
|
||||
|
||||
type SetUserOrgLimitParams struct {
|
||||
Orgs *int32
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
type SetUserOrgLimitRow struct {
|
||||
ID uuid.UUID
|
||||
Email string
|
||||
}
|
||||
|
||||
func (q *Queries) SetUserOrgLimit(ctx context.Context, arg SetUserOrgLimitParams) (SetUserOrgLimitRow, error) {
|
||||
row := q.db.QueryRow(ctx, setUserOrgLimit, arg.Orgs, arg.ID)
|
||||
var i SetUserOrgLimitRow
|
||||
err := row.Scan(&i.ID, &i.Email)
|
||||
return i, err
|
||||
}
|
||||
+16
-11
@@ -275,17 +275,21 @@ type NotificationChannel struct {
|
||||
}
|
||||
|
||||
type Org struct {
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Name string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
RequireTotp bool
|
||||
RequireSso bool
|
||||
ApiTokenMaxDays *int32
|
||||
DisabledCheckTypes []string
|
||||
SuspendedAt *time.Time
|
||||
SuspendedReason string
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Name string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
RequireTotp bool
|
||||
RequireSso bool
|
||||
ApiTokenMaxDays *int32
|
||||
DisabledCheckTypes []string
|
||||
SuspendedAt *time.Time
|
||||
SuspendedReason string
|
||||
LimitMonitors *int32
|
||||
LimitStatusPages *int32
|
||||
LimitRegionsPerMonitor *int32
|
||||
LimitOwnRegionsCount *bool
|
||||
}
|
||||
|
||||
type PlatformSetting struct {
|
||||
@@ -397,6 +401,7 @@ type User struct {
|
||||
Locale *string
|
||||
IsAdmin bool
|
||||
DisabledReason string
|
||||
LimitOrgs *int32
|
||||
}
|
||||
|
||||
type UserIdentity struct {
|
||||
|
||||
@@ -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, suspended_at, suspended_reason
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count
|
||||
`
|
||||
|
||||
type CreateOrgParams struct {
|
||||
@@ -37,6 +37,10 @@ func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, erro
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
&i.LimitMonitors,
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -54,7 +58,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, suspended_at, suspended_reason 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, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||
@@ -72,12 +76,16 @@ func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
&i.LimitMonitors,
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
)
|
||||
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, suspended_at, suspended_reason 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, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs WHERE slug = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||
@@ -95,12 +103,16 @@ func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
&i.LimitMonitors,
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
)
|
||||
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, suspended_at, suspended_reason 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, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
@@ -124,6 +136,10 @@ func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
&i.LimitMonitors,
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -152,7 +168,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, suspended_at, suspended_reason
|
||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count
|
||||
`
|
||||
|
||||
type UpdateOrgPolicyParams struct {
|
||||
@@ -182,6 +198,10 @@ func (q *Queries) UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams
|
||||
&i.DisabledCheckTypes,
|
||||
&i.SuspendedAt,
|
||||
&i.SuspendedReason,
|
||||
&i.LimitMonitors,
|
||||
&i.LimitStatusPages,
|
||||
&i.LimitRegionsPerMonitor,
|
||||
&i.LimitOwnRegionsCount,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -19,6 +19,9 @@ 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: organizations with their usage, limit overrides and owner,
|
||||
// newest first, matching search in name, slug or owner email.
|
||||
AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([]AdminListOrgsRow, 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.
|
||||
@@ -42,7 +45,9 @@ type Querier interface {
|
||||
ClearMaintenanceTargets(ctx context.Context, windowID uuid.UUID) error
|
||||
ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error
|
||||
ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error
|
||||
CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error)
|
||||
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
|
||||
CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error)
|
||||
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||
CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) (ApiToken, error)
|
||||
CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent, error)
|
||||
@@ -193,6 +198,9 @@ type Querier interface {
|
||||
// Row-level security limits this to platform regions and the scope's org;
|
||||
// the org's own regions come first.
|
||||
ListVisibleRegions(ctx context.Context) ([]Region, error)
|
||||
// Serializes creations counted against org's limits until the transaction
|
||||
// ends.
|
||||
LockOrgUsage(ctx context.Context, orgID uuid.UUID) error
|
||||
// System scope: windows covering any of the monitors, directly or through
|
||||
// their group or one of its ancestors.
|
||||
MaintenanceForMonitors(ctx context.Context, ids []uuid.UUID) ([]MaintenanceForMonitorsRow, error)
|
||||
@@ -263,6 +271,7 @@ type Querier interface {
|
||||
ScrubAuditEmail(ctx context.Context, email string) error
|
||||
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
|
||||
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
|
||||
SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error)
|
||||
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
|
||||
SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error
|
||||
// Changing the domain drops a previous verification.
|
||||
@@ -270,6 +279,7 @@ type Querier interface {
|
||||
SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error
|
||||
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
|
||||
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
|
||||
SetUserOrgLimit(ctx context.Context, arg SetUserOrgLimitParams) (SetUserOrgLimitRow, error)
|
||||
// Other instances of the same agent seen in the last day.
|
||||
SiblingInstances(ctx context.Context, agentID uuid.UUID) ([]SiblingInstancesRow, error)
|
||||
StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]StatusPageMonitorsRow, error)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
-- name: LockOrgUsage :exec
|
||||
-- Serializes creations counted against org's limits until the transaction
|
||||
-- ends.
|
||||
SELECT pg_advisory_xact_lock(hashtextextended('usage:' || sqlc.arg(org_id)::uuid::text, 0));
|
||||
|
||||
-- name: CountMonitors :one
|
||||
SELECT count(*) FROM monitors WHERE org_id = $1;
|
||||
|
||||
-- name: CountStatusPages :one
|
||||
SELECT count(*) FROM status_pages WHERE org_id = $1;
|
||||
|
||||
-- name: SetOrgLimits :one
|
||||
UPDATE orgs SET limit_monitors = sqlc.narg(monitors), limit_status_pages = sqlc.narg(status_pages),
|
||||
limit_regions_per_monitor = sqlc.narg(regions_per_monitor), limit_own_regions_count = sqlc.narg(own_regions_count)
|
||||
WHERE id = sqlc.arg(id)
|
||||
RETURNING id, slug;
|
||||
|
||||
-- name: SetUserOrgLimit :one
|
||||
UPDATE users SET limit_orgs = sqlc.narg(orgs) WHERE id = sqlc.arg(id)
|
||||
RETURNING id, email;
|
||||
|
||||
-- name: AdminListOrgs :many
|
||||
-- System scope: organizations with their usage, limit overrides and owner,
|
||||
-- newest first, matching search in name, slug or owner email.
|
||||
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
||||
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
||||
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
||||
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
||||
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,
|
||||
ow.limit_orgs AS owner_limit_orgs,
|
||||
coalesce(ow.owned, 0)::integer AS owner_orgs
|
||||
FROM orgs o
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT u.id, u.email, u.disabled_at, u.disabled_reason, u.is_admin, u.limit_orgs,
|
||||
(SELECT count(*) FROM memberships m2 WHERE m2.user_id = u.id AND m2.is_owner) AS owned
|
||||
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 sqlc.arg(search)::text = ''
|
||||
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 o.created_at DESC
|
||||
LIMIT sqlc.arg(max_rows);
|
||||
@@ -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, disabled_reason
|
||||
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 {
|
||||
@@ -55,6 +55,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
||||
&i.Locale,
|
||||
&i.IsAdmin,
|
||||
&i.DisabledReason,
|
||||
&i.LimitOrgs,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -95,7 +96,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, disabled_reason 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, limit_orgs FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
@@ -114,12 +115,13 @@ func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
&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 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, limit_orgs FROM users WHERE email = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
||||
@@ -138,6 +140,7 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error
|
||||
&i.Locale,
|
||||
&i.IsAdmin,
|
||||
&i.DisabledReason,
|
||||
&i.LimitOrgs,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user