feat: add assessment, privacy and support flows

This commit is contained in:
TakuyaYagam1 committed 2026-10-08 08:08:25 +03:00
1 parent ee3738ee73
commit e4f24fa202
339 files changed
+56454 -1126

No files matched your search

@@ -11,6 +11,44 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
const candidateCanSeeOrganization = `-- name: CandidateCanSeeOrganization :one
SELECT organizations.id, organizations.name
FROM organizations
WHERE organizations.id = $1
AND (
EXISTS (
SELECT 1 FROM candidate_card_access_events
WHERE candidate_card_access_events.candidate_id = $2
AND candidate_card_access_events.organization_id = organizations.id
)
OR EXISTS (
SELECT 1 FROM candidate_hidden_organizations
WHERE candidate_hidden_organizations.user_id = $2
AND candidate_hidden_organizations.organization_id = organizations.id
)
)
`
type CandidateCanSeeOrganizationParams struct {
OrganizationID pgtype.UUID
UserID pgtype.UUID
}
type CandidateCanSeeOrganizationRow struct {
ID pgtype.UUID
Name string
}
// The candidate may name an organization in privacy settings only if that
// organization already appears in their own access history or is already
// hidden. Unknown and unseen organizations produce the same no-row result.
func (q *Queries) CandidateCanSeeOrganization(ctx context.Context, arg CandidateCanSeeOrganizationParams) (CandidateCanSeeOrganizationRow, error) {
row := q.db.QueryRow(ctx, candidateCanSeeOrganization, arg.OrganizationID, arg.UserID)
var i CandidateCanSeeOrganizationRow
err := row.Scan(&i.ID, &i.Name)
return i, err
}
const countCandidateHiddenOrganizations = `-- name: CountCandidateHiddenOrganizations :one
SELECT count(*) AS total
FROM candidate_hidden_organizations
@@ -79,6 +117,52 @@ func (q *Queries) GetCandidateHiddenOrganization(ctx context.Context, arg GetCan
return i, err
}
const insertCandidateCardAccessEvent = `-- name: InsertCandidateCardAccessEvent :exec
INSERT INTO candidate_card_access_events (
id,
candidate_id,
organization_id,
actor_id,
kind,
field_codes,
occurred_at
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
)
`
type InsertCandidateCardAccessEventParams struct {
ID pgtype.UUID
CandidateID pgtype.UUID
OrganizationID pgtype.UUID
ActorID pgtype.UUID
Kind string
FieldCodes []string
OccurredAt pgtype.Timestamptz
}
// Records a successfully authorized view after visibility and quota checks.
// The audit contains only identities, the access kind, published field codes,
// and time; it never receives the projection content, ranking, or filters.
func (q *Queries) InsertCandidateCardAccessEvent(ctx context.Context, arg InsertCandidateCardAccessEventParams) error {
_, err := q.db.Exec(ctx, insertCandidateCardAccessEvent,
arg.ID,
arg.CandidateID,
arg.OrganizationID,
arg.ActorID,
arg.Kind,
arg.FieldCodes,
arg.OccurredAt,
)
return err
}
const insertCandidateHiddenOrganization = `-- name: InsertCandidateHiddenOrganization :one
INSERT INTO candidate_hidden_organizations (
user_id,
@@ -272,6 +356,88 @@ func (q *Queries) InsertCandidateSearchStatus(ctx context.Context, arg InsertCan
return i, err
}
const listCandidateCardAccessEvents = `-- name: ListCandidateCardAccessEvents :many
SELECT
candidate_card_access_events.id,
candidate_card_access_events.candidate_id,
candidate_card_access_events.organization_id,
candidate_card_access_events.actor_id,
candidate_card_access_events.kind,
candidate_card_access_events.field_codes,
candidate_card_access_events.occurred_at,
organizations.name AS organization_name
FROM candidate_card_access_events
INNER JOIN organizations
ON organizations.id = candidate_card_access_events.organization_id
WHERE
candidate_card_access_events.candidate_id = $1
AND (
$2::timestamptz IS NULL
OR (candidate_card_access_events.occurred_at, candidate_card_access_events.id) < (
$2::timestamptz,
$3::uuid
)
)
ORDER BY candidate_card_access_events.occurred_at DESC, candidate_card_access_events.id DESC
LIMIT $4
`
type ListCandidateCardAccessEventsParams struct {
CandidateID pgtype.UUID
AfterOccurredAt pgtype.Timestamptz
AfterID pgtype.UUID
RowLimit int32
}
type ListCandidateCardAccessEventsRow struct {
ID pgtype.UUID
CandidateID pgtype.UUID
OrganizationID pgtype.UUID
ActorID pgtype.UUID
Kind string
FieldCodes []string
OccurredAt pgtype.Timestamptz
OrganizationName string
}
// Lists only the current candidate's own access history. It deliberately
// omits the employee, requested card fields, and search context. The privacy
// read adapter resolves an organization name only through this recorded
// access relation, which is already visible to the candidate.
func (q *Queries) ListCandidateCardAccessEvents(ctx context.Context, arg ListCandidateCardAccessEventsParams) ([]ListCandidateCardAccessEventsRow, error) {
rows, err := q.db.Query(ctx, listCandidateCardAccessEvents,
arg.CandidateID,
arg.AfterOccurredAt,
arg.AfterID,
arg.RowLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListCandidateCardAccessEventsRow
for rows.Next() {
var i ListCandidateCardAccessEventsRow
if err := rows.Scan(
&i.ID,
&i.CandidateID,
&i.OrganizationID,
&i.ActorID,
&i.Kind,
&i.FieldCodes,
&i.OccurredAt,
&i.OrganizationName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listCandidateHiddenOrganizations = `-- name: ListCandidateHiddenOrganizations :many
SELECT
candidate_hidden_organizations.organization_id,
@@ -480,8 +646,88 @@ func (q *Queries) LockCurrentC2Record(ctx context.Context, subjectID pgtype.UUID
return id, err
}
const readCandidatePublication = `-- name: ReadCandidatePublication :one
const readCandidatePrivacySettings = `-- name: ReadCandidatePrivacySettings :one
SELECT
users.id AS user_id,
candidate_publications.state AS publication_state,
candidate_publications.fields AS publication_fields,
candidate_publications.consent_record_id AS publication_consent_record_id,
candidate_publications.published_at AS publication_published_at,
candidate_publications.closed_at AS publication_closed_at,
candidate_publications.version AS publication_version,
consent_records.revoked_at AS publication_consent_revoked_at,
candidate_search_statuses.status AS search_status,
candidate_search_statuses.confirmed_at AS search_confirmed_at,
candidate_search_statuses.lapses_at AS search_lapses_at,
candidate_search_statuses.policy_version_id AS search_policy_version_id,
candidate_search_statuses.version AS search_version,
(
SELECT count(*)
FROM candidate_hidden_organizations
WHERE candidate_hidden_organizations.user_id = users.id
) AS hidden_count
FROM users
LEFT JOIN candidate_publications
ON candidate_publications.user_id = users.id
LEFT JOIN consent_records
ON consent_records.id = candidate_publications.consent_record_id
LEFT JOIN candidate_search_statuses
ON candidate_search_statuses.user_id = users.id
WHERE users.id = $1
`
type ReadCandidatePrivacySettingsRow struct {
UserID pgtype.UUID
PublicationState pgtype.Text
PublicationFields []string
PublicationConsentRecordID pgtype.UUID
PublicationPublishedAt pgtype.Timestamptz
PublicationClosedAt pgtype.Timestamptz
PublicationVersion pgtype.Int8
PublicationConsentRevokedAt pgtype.Timestamptz
SearchStatus pgtype.Text
SearchConfirmedAt pgtype.Timestamptz
SearchLapsesAt pgtype.Timestamptz
SearchPolicyVersionID pgtype.UUID
SearchVersion pgtype.Int8
HiddenCount int64
}
// Queries of the candidate visibility settings: the publication of
// the card, the search status, the hidden organizations, and the history of
// these settings. Every statement is scoped by the candidate's user_id, and
// no statement selects another account's row. No statement reads or writes a
// profile value, a name, or a contact. A candidate with no row is closed, not
// looking, and hides nobody; no statement creates a row except an explicit
// act of the candidate.
// Reads the candidate-owned settings and hidden count from one statement
// snapshot. Missing setting rows are restored as the closed/not-looking
// defaults in the adapter. The account row scopes the result but does not
// expose private profile values.
func (q *Queries) ReadCandidatePrivacySettings(ctx context.Context, userID pgtype.UUID) (ReadCandidatePrivacySettingsRow, error) {
row := q.db.QueryRow(ctx, readCandidatePrivacySettings, userID)
var i ReadCandidatePrivacySettingsRow
err := row.Scan(
&i.UserID,
&i.PublicationState,
&i.PublicationFields,
&i.PublicationConsentRecordID,
&i.PublicationPublishedAt,
&i.PublicationClosedAt,
&i.PublicationVersion,
&i.PublicationConsentRevokedAt,
&i.SearchStatus,
&i.SearchConfirmedAt,
&i.SearchLapsesAt,
&i.SearchPolicyVersionID,
&i.SearchVersion,
&i.HiddenCount,
)
return i, err
}
const readCandidatePublication = `-- name: ReadCandidatePublication :one
SELECT
candidate_publications.user_id,
candidate_publications.state,
@@ -512,13 +758,6 @@ type ReadCandidatePublicationRow struct {
ConsentRevokedAt pgtype.Timestamptz
}
// Queries of the candidate visibility settings: the publication of
// the card, the search status, the hidden organizations, and the history of
// these settings. Every statement is scoped by the candidate's user_id, and
// no statement selects another account's row. No statement reads or writes a
// profile value, a name, or a contact. A candidate with no row is closed, not
// looking, and hides nobody; no statement creates a row except an explicit
// act of the candidate.
// Reads the publication with the revocation state of the C2 record behind it
// in one statement, so the stored setting and the ledger come from one
// snapshot. The effective state is computed from them: published only while