Persist pool-scoped grants using OR semantics across active provisions, retaining lapsed rows for transition visibility. Add consumer queries, DB-backed coverage, and plans for the dependent Discourse integration.
153 lines
4.4 KiB
Go
153 lines
4.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: boolean_entitlements.sql
|
|
|
|
package entitlements
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const getBooleanEntitlementByPoolAndResource = `-- name: GetBooleanEntitlementByPoolAndResource :one
|
|
SELECT pool_id, resource_key, granted, created_at, updated_at FROM core.boolean_entitlements
|
|
WHERE pool_id = $1 AND resource_key = $2
|
|
`
|
|
|
|
type GetBooleanEntitlementByPoolAndResourceParams struct {
|
|
PoolID string `json:"pool_id"`
|
|
ResourceKey string `json:"resource_key"`
|
|
}
|
|
|
|
func (q *Queries) GetBooleanEntitlementByPoolAndResource(ctx context.Context, arg GetBooleanEntitlementByPoolAndResourceParams) (BooleanEntitlement, error) {
|
|
row := q.db.QueryRowContext(ctx, getBooleanEntitlementByPoolAndResource, arg.PoolID, arg.ResourceKey)
|
|
var i BooleanEntitlement
|
|
err := row.Scan(
|
|
&i.PoolID,
|
|
&i.ResourceKey,
|
|
&i.Granted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const lapseBooleanEntitlement = `-- name: LapseBooleanEntitlement :execrows
|
|
UPDATE core.boolean_entitlements
|
|
SET granted = FALSE
|
|
WHERE pool_id = $1 AND resource_key = $2
|
|
`
|
|
|
|
type LapseBooleanEntitlementParams struct {
|
|
PoolID string `json:"pool_id"`
|
|
ResourceKey string `json:"resource_key"`
|
|
}
|
|
|
|
// Update-only by design: a lapse never creates a row. Absence of a row means
|
|
// the key was never conferred; granted = FALSE means conferred, then lapsed.
|
|
func (q *Queries) LapseBooleanEntitlement(ctx context.Context, arg LapseBooleanEntitlementParams) (int64, error) {
|
|
result, err := q.db.ExecContext(ctx, lapseBooleanEntitlement, arg.PoolID, arg.ResourceKey)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected()
|
|
}
|
|
|
|
const listBooleanEntitlementsByPoolID = `-- name: ListBooleanEntitlementsByPoolID :many
|
|
SELECT pool_id, resource_key, granted, created_at, updated_at FROM core.boolean_entitlements
|
|
WHERE pool_id = $1
|
|
ORDER BY resource_key ASC
|
|
`
|
|
|
|
func (q *Queries) ListBooleanEntitlementsByPoolID(ctx context.Context, poolID string) ([]BooleanEntitlement, error) {
|
|
rows, err := q.db.QueryContext(ctx, listBooleanEntitlementsByPoolID, poolID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []BooleanEntitlement{}
|
|
for rows.Next() {
|
|
var i BooleanEntitlement
|
|
if err := rows.Scan(
|
|
&i.PoolID,
|
|
&i.ResourceKey,
|
|
&i.Granted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPoolsGrantedBooleanKey = `-- name: ListPoolsGrantedBooleanKey :many
|
|
SELECT be.pool_id, rp.org_id, o.name AS org_name
|
|
FROM core.boolean_entitlements be
|
|
JOIN core.resource_pools rp ON rp.pool_id = be.pool_id
|
|
JOIN core.organizations o ON o.org_id = rp.org_id
|
|
WHERE be.resource_key = $1 AND be.granted = TRUE
|
|
ORDER BY o.name ASC, be.pool_id ASC
|
|
`
|
|
|
|
type ListPoolsGrantedBooleanKeyRow struct {
|
|
PoolID string `json:"pool_id"`
|
|
OrgID string `json:"org_id"`
|
|
OrgName string `json:"org_name"`
|
|
}
|
|
|
|
func (q *Queries) ListPoolsGrantedBooleanKey(ctx context.Context, resourceKey string) ([]ListPoolsGrantedBooleanKeyRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPoolsGrantedBooleanKey, resourceKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListPoolsGrantedBooleanKeyRow{}
|
|
for rows.Next() {
|
|
var i ListPoolsGrantedBooleanKeyRow
|
|
if err := rows.Scan(&i.PoolID, &i.OrgID, &i.OrgName); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const upsertBooleanEntitlementGranted = `-- name: UpsertBooleanEntitlementGranted :one
|
|
INSERT INTO core.boolean_entitlements (pool_id, resource_key, granted)
|
|
VALUES ($1, $2, TRUE)
|
|
ON CONFLICT (pool_id, resource_key) DO UPDATE SET granted = TRUE
|
|
RETURNING pool_id, resource_key, granted, created_at, updated_at
|
|
`
|
|
|
|
type UpsertBooleanEntitlementGrantedParams struct {
|
|
PoolID string `json:"pool_id"`
|
|
ResourceKey string `json:"resource_key"`
|
|
}
|
|
|
|
func (q *Queries) UpsertBooleanEntitlementGranted(ctx context.Context, arg UpsertBooleanEntitlementGrantedParams) (BooleanEntitlement, error) {
|
|
row := q.db.QueryRowContext(ctx, upsertBooleanEntitlementGranted, arg.PoolID, arg.ResourceKey)
|
|
var i BooleanEntitlement
|
|
err := row.Scan(
|
|
&i.PoolID,
|
|
&i.ResourceKey,
|
|
&i.Granted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|