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.
102 lines
3.3 KiB
Go
102 lines
3.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: identity.sql
|
|
|
|
package discourse
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const findPersonByOIDCSubject = `-- name: FindPersonByOIDCSubject :one
|
|
SELECT p.person_id, p.display_name, p.primary_email, p.primary_email_verified, u.oidc_subject
|
|
FROM core.persons p
|
|
JOIN core.users u ON u.user_id = p.user_id
|
|
WHERE u.oidc_subject = $1
|
|
`
|
|
|
|
type FindPersonByOIDCSubjectRow struct {
|
|
PersonID string `json:"person_id"`
|
|
DisplayName string `json:"display_name"`
|
|
PrimaryEmail string `json:"primary_email"`
|
|
PrimaryEmailVerified bool `json:"primary_email_verified"`
|
|
OidcSubject string `json:"oidc_subject"`
|
|
}
|
|
|
|
// Reverse resolution for oidc/discourseconnect-mode webhook linking.
|
|
func (q *Queries) FindPersonByOIDCSubject(ctx context.Context, oidcSubject string) (FindPersonByOIDCSubjectRow, error) {
|
|
row := q.db.QueryRowContext(ctx, findPersonByOIDCSubject, oidcSubject)
|
|
var i FindPersonByOIDCSubjectRow
|
|
err := row.Scan(
|
|
&i.PersonID,
|
|
&i.DisplayName,
|
|
&i.PrimaryEmail,
|
|
&i.PrimaryEmailVerified,
|
|
&i.OidcSubject,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const findPersonByVerifiedEmail = `-- name: FindPersonByVerifiedEmail :one
|
|
SELECT p.person_id, p.display_name, p.primary_email, p.primary_email_verified, u.oidc_subject
|
|
FROM core.persons p
|
|
JOIN core.users u ON u.user_id = p.user_id
|
|
WHERE lower(p.primary_email) = lower($1) AND p.primary_email_verified = TRUE
|
|
`
|
|
|
|
type FindPersonByVerifiedEmailRow struct {
|
|
PersonID string `json:"person_id"`
|
|
DisplayName string `json:"display_name"`
|
|
PrimaryEmail string `json:"primary_email"`
|
|
PrimaryEmailVerified bool `json:"primary_email_verified"`
|
|
OidcSubject string `json:"oidc_subject"`
|
|
}
|
|
|
|
// Reverse resolution for email-mode webhook linking: which person owns this
|
|
// verified primary email. Case-insensitive to match Discourse's own
|
|
// email comparison semantics.
|
|
func (q *Queries) FindPersonByVerifiedEmail(ctx context.Context, lower string) (FindPersonByVerifiedEmailRow, error) {
|
|
row := q.db.QueryRowContext(ctx, findPersonByVerifiedEmail, lower)
|
|
var i FindPersonByVerifiedEmailRow
|
|
err := row.Scan(
|
|
&i.PersonID,
|
|
&i.DisplayName,
|
|
&i.PrimaryEmail,
|
|
&i.PrimaryEmailVerified,
|
|
&i.OidcSubject,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPersonIdentity = `-- name: GetPersonIdentity :one
|
|
SELECT p.person_id, p.display_name, p.primary_email, p.primary_email_verified, u.oidc_subject
|
|
FROM core.persons p
|
|
JOIN core.users u ON u.user_id = p.user_id
|
|
WHERE p.person_id = $1
|
|
`
|
|
|
|
type GetPersonIdentityRow struct {
|
|
PersonID string `json:"person_id"`
|
|
DisplayName string `json:"display_name"`
|
|
PrimaryEmail string `json:"primary_email"`
|
|
PrimaryEmailVerified bool `json:"primary_email_verified"`
|
|
OidcSubject string `json:"oidc_subject"`
|
|
}
|
|
|
|
// Identity attributes linkage resolves against: the OIDC subject (oidc /
|
|
// discourseconnect modes) and the verified primary email (email mode).
|
|
// Reads core via the stream's core_reader grant.
|
|
func (q *Queries) GetPersonIdentity(ctx context.Context, personID string) (GetPersonIdentityRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getPersonIdentity, personID)
|
|
var i GetPersonIdentityRow
|
|
err := row.Scan(
|
|
&i.PersonID,
|
|
&i.DisplayName,
|
|
&i.PrimaryEmail,
|
|
&i.PrimaryEmailVerified,
|
|
&i.OidcSubject,
|
|
)
|
|
return i, err
|
|
}
|