Deliver forum posting entitlements through managed group membership with identity linkage, periodic reconciliation, webhook handling, and an operator mapping surface. Include fake and live test environments, setup documentation, migrations, and end-to-end coverage.
213 lines
5.6 KiB
Go
213 lines
5.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: group_mappings.sql
|
|
|
|
package discourse
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const createGroupMapping = `-- name: CreateGroupMapping :one
|
|
INSERT INTO discourse.group_mappings (resource_key, group_name, discourse_group_id)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING mapping_id, resource_key, group_name, discourse_group_id, created_at, updated_at
|
|
`
|
|
|
|
type CreateGroupMappingParams struct {
|
|
ResourceKey string `json:"resource_key"`
|
|
GroupName string `json:"group_name"`
|
|
DiscourseGroupID int64 `json:"discourse_group_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateGroupMapping(ctx context.Context, arg CreateGroupMappingParams) (GroupMapping, error) {
|
|
row := q.db.QueryRowContext(ctx, createGroupMapping, arg.ResourceKey, arg.GroupName, arg.DiscourseGroupID)
|
|
var i GroupMapping
|
|
err := row.Scan(
|
|
&i.MappingID,
|
|
&i.ResourceKey,
|
|
&i.GroupName,
|
|
&i.DiscourseGroupID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteGroupMapping = `-- name: DeleteGroupMapping :execrows
|
|
DELETE FROM discourse.group_mappings
|
|
WHERE mapping_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteGroupMapping(ctx context.Context, mappingID string) (int64, error) {
|
|
result, err := q.db.ExecContext(ctx, deleteGroupMapping, mappingID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected()
|
|
}
|
|
|
|
const getGroupMappingByDiscourseGroupID = `-- name: GetGroupMappingByDiscourseGroupID :one
|
|
SELECT mapping_id, resource_key, group_name, discourse_group_id, created_at, updated_at FROM discourse.group_mappings
|
|
WHERE discourse_group_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetGroupMappingByDiscourseGroupID(ctx context.Context, discourseGroupID int64) (GroupMapping, error) {
|
|
row := q.db.QueryRowContext(ctx, getGroupMappingByDiscourseGroupID, discourseGroupID)
|
|
var i GroupMapping
|
|
err := row.Scan(
|
|
&i.MappingID,
|
|
&i.ResourceKey,
|
|
&i.GroupName,
|
|
&i.DiscourseGroupID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getGroupMappingByGroupName = `-- name: GetGroupMappingByGroupName :one
|
|
SELECT mapping_id, resource_key, group_name, discourse_group_id, created_at, updated_at FROM discourse.group_mappings
|
|
WHERE group_name = $1
|
|
`
|
|
|
|
func (q *Queries) GetGroupMappingByGroupName(ctx context.Context, groupName string) (GroupMapping, error) {
|
|
row := q.db.QueryRowContext(ctx, getGroupMappingByGroupName, groupName)
|
|
var i GroupMapping
|
|
err := row.Scan(
|
|
&i.MappingID,
|
|
&i.ResourceKey,
|
|
&i.GroupName,
|
|
&i.DiscourseGroupID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getGroupMappingByID = `-- name: GetGroupMappingByID :one
|
|
SELECT mapping_id, resource_key, group_name, discourse_group_id, created_at, updated_at FROM discourse.group_mappings
|
|
WHERE mapping_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetGroupMappingByID(ctx context.Context, mappingID string) (GroupMapping, error) {
|
|
row := q.db.QueryRowContext(ctx, getGroupMappingByID, mappingID)
|
|
var i GroupMapping
|
|
err := row.Scan(
|
|
&i.MappingID,
|
|
&i.ResourceKey,
|
|
&i.GroupName,
|
|
&i.DiscourseGroupID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listGroupMappings = `-- name: ListGroupMappings :many
|
|
SELECT mapping_id, resource_key, group_name, discourse_group_id, created_at, updated_at FROM discourse.group_mappings
|
|
ORDER BY group_name ASC
|
|
`
|
|
|
|
func (q *Queries) ListGroupMappings(ctx context.Context) ([]GroupMapping, error) {
|
|
rows, err := q.db.QueryContext(ctx, listGroupMappings)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GroupMapping{}
|
|
for rows.Next() {
|
|
var i GroupMapping
|
|
if err := rows.Scan(
|
|
&i.MappingID,
|
|
&i.ResourceKey,
|
|
&i.GroupName,
|
|
&i.DiscourseGroupID,
|
|
&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 listGroupMappingsByResourceKey = `-- name: ListGroupMappingsByResourceKey :many
|
|
SELECT mapping_id, resource_key, group_name, discourse_group_id, created_at, updated_at FROM discourse.group_mappings
|
|
WHERE resource_key = $1
|
|
ORDER BY group_name ASC
|
|
`
|
|
|
|
func (q *Queries) ListGroupMappingsByResourceKey(ctx context.Context, resourceKey string) ([]GroupMapping, error) {
|
|
rows, err := q.db.QueryContext(ctx, listGroupMappingsByResourceKey, resourceKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GroupMapping{}
|
|
for rows.Next() {
|
|
var i GroupMapping
|
|
if err := rows.Scan(
|
|
&i.MappingID,
|
|
&i.ResourceKey,
|
|
&i.GroupName,
|
|
&i.DiscourseGroupID,
|
|
&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 listOwnedResourceKeys = `-- name: ListOwnedResourceKeys :many
|
|
SELECT resource_key, display_name FROM core.resource_keys
|
|
WHERE provider = 'discourse'
|
|
ORDER BY resource_key ASC
|
|
`
|
|
|
|
type ListOwnedResourceKeysRow struct {
|
|
ResourceKey string `json:"resource_key"`
|
|
DisplayName string `json:"display_name"`
|
|
}
|
|
|
|
// The discourse-owned resource keys an operator can map (select options).
|
|
func (q *Queries) ListOwnedResourceKeys(ctx context.Context) ([]ListOwnedResourceKeysRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listOwnedResourceKeys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListOwnedResourceKeysRow{}
|
|
for rows.Next() {
|
|
var i ListOwnedResourceKeysRow
|
|
if err := rows.Scan(&i.ResourceKey, &i.DisplayName); 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
|
|
}
|