Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
105 lines
3.4 KiB
Go
105 lines
3.4 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
// 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
|
|
}
|