feat(accounts): add consent settings and organization management

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 13:00:39 +03:00
1 parent 24638d46d2
commit 391af7a1ef
83 files changed
+10198 -613

No files matched your search

+30
View File
@@ -417,3 +417,33 @@ WHERE
)
ORDER BY ledger.granted_at DESC, ledger.id DESC
LIMIT sqlc.arg(row_limit);
-- Creates one durable deletion request per subject until a worker completes it.
-- The caller appends the matching outbox intent in the same transaction only
-- when this insert returns a row.
-- name: CreateAccountDeletionRequest :one
INSERT INTO account_deletion_requests (
id,
subject_id,
status,
requested_at
) VALUES (
sqlc.arg(id),
sqlc.arg(subject_id),
'requested',
sqlc.arg(requested_at)
)
ON CONFLICT (subject_id)
WHERE subject_id IS NOT NULL AND status IN ('requested', 'processing')
DO NOTHING
RETURNING id, subject_id, status, requested_at;
-- Reads the durable active deletion request when an earlier request already
-- exists. A completed request does not suppress a later explicit request.
-- name: GetActiveAccountDeletionRequest :one
SELECT id, subject_id, status, requested_at
FROM account_deletion_requests
WHERE subject_id = sqlc.arg(subject_id)
AND status IN ('requested', 'processing')
ORDER BY requested_at, id
LIMIT 1;
+17
View File
@@ -222,3 +222,20 @@ FROM memberships
WHERE
organization_id = sqlc.arg(organization_id)
AND user_id = sqlc.arg(user_id);
-- Stores the immutable domain snapshot of a successful create command. The
-- generic idempotency row and this result are committed with the organization
-- and owner membership. A reused expired scope replaces the snapshot in the
-- same transaction as the new organization.
-- name: SaveOrganizationCreationResult :exec
INSERT INTO organization_creation_results (scope_hash, snapshot)
VALUES (sqlc.arg(scope_hash), sqlc.arg(snapshot))
ON CONFLICT (scope_hash) DO UPDATE
SET snapshot = excluded.snapshot;
-- Reads only the historical result. It intentionally does not join the live
-- organization or membership, whose profile and state may have since changed.
-- name: GetOrganizationCreationResult :one
SELECT snapshot
FROM organization_creation_results
WHERE scope_hash = sqlc.arg(scope_hash);
+19
View File
@@ -280,6 +280,25 @@ ORDER BY granted_at DESC, id DESC
LIMIT 1
FOR SHARE;
-- Locks the candidate's published row only when it refers to a C2 record
-- revoked by this transaction. The setting remains linked to that immutable
-- record; ReadCandidatePublication computes the effective closed state and
-- keeps the consent-revoked reason after later grants. The returned time is
-- the effective close time used by the privacy history event.
-- name: LockCandidatePublicationForConsentRevocation :one
SELECT greatest(candidate_publications.published_at, consent_records.revoked_at)::timestamptz AS closed_at
FROM candidate_publications
INNER JOIN consent_records
ON consent_records.id = candidate_publications.consent_record_id
WHERE
candidate_publications.user_id = sqlc.arg(user_id)
AND candidate_publications.state = 'published'
AND consent_records.id = ANY(sqlc.arg(consent_record_ids)::uuid [])
AND consent_records.subject_id = candidate_publications.user_id
AND consent_records.purpose = 'c2'
AND consent_records.revoked_at IS NOT NULL
FOR UPDATE OF candidate_publications;
-- The organization-facing read of a candidate's publication: the effective
-- view (published and backed by an unrevoked C2) and no hiding of the reading
-- organization. No row means the organization reads nothing, whichever of