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

@@ -49,6 +49,36 @@ type ConsentRepositories interface {
ConsentLedger() ConsentLedger
}
// AccountDeletionRequests stores the durable request created when a subject
// revokes C1. The active request is independent of later consent grants.
type AccountDeletionRequests interface {
// CreateOrGet returns the current requested record when one exists, or
// stores request as the subject's active deletion request.
CreateOrGet(ctx context.Context, request domain.AccountDeletionRequest) (record domain.AccountDeletionRequest, created bool, err error)
}
// ConsentRevocationEffects applies every currently available local privacy
// change and records downstream revocation intents in the same transaction as
// the ledger stamps. Future C2 and C4 grant adapters must bind each downstream
// grant to its source consent record ID and synchronously close grants for
// revoked record IDs before returning; a later consent record may create a
// new grant, but must never reactivate an older record's grant. Future C5
// readers and importers must check the current consent ledger before reading
// or synchronizing data and fail closed on a missing grant or ledger error.
// An outbox event communicates a committed change; it is never an
// authorization check and cannot make a revoked grant current again. This
// release has no external FSP or downstream contact-grant adapter, so those
// external effects are not claimed as complete.
type ConsentRevocationEffects interface {
// Apply synchronously closes and records a C2 publication when present,
// then appends one bounded durable outbox intent per affected consent record
// with its stored scope. It must not truncate or omit affected records. A
// future local C2/C4 grant adapter must implement record-bound closure in
// this same UnitOfWork before the outbox intent is appended. An empty record
// set is not a valid call.
Apply(ctx context.Context, revocation domain.ConsentRevocation, records []domain.ConsentRecord) error
}
// ConsentTextRepository reads the immutable published consent texts. It has
// no write method: texts are published by migrations.
type ConsentTextRepository interface {
@@ -33,6 +33,10 @@ var (
// ErrMembershipNotFound reports that the account has no membership in the
// organization, in any state.
ErrMembershipNotFound = errors.New("membership not found")
// ErrOrganizationCreationResultNotFound reports a missing immutable result
// snapshot for a live organization creation idempotency record.
ErrOrganizationCreationResultNotFound = errors.New("organization creation result not found")
)
// MaxOrganizationPageSize matches the largest page of the contract.
@@ -65,6 +69,16 @@ type OrganizationRepository interface {
// ErrUserNotFound, and the caller's transaction is aborted.
CreateWithOwner(ctx context.Context, organization domain.Organization, owner domain.Membership) error
// SaveCreationResult stores the immutable domain snapshot returned by the
// original create command. The scope is the HMAC key of a live generic
// idempotency record. The snapshot is bounded and expires with that record;
// it does not follow later profile edits or membership changes.
SaveCreationResult(ctx context.Context, scope [IdempotencyDigestSize]byte, result OrganizationCreationResult) error
// GetCreationResult returns the original snapshot for a live idempotency
// scope. It never reads the current organization or membership rows.
GetCreationResult(ctx context.Context, scope [IdempotencyDigestSize]byte) (OrganizationCreationResult, error)
// GetForMember returns the organization with its representatives and the
// active membership of the account in it, read from one snapshot in one
// statement, so the profile and the list never come from two states. It
@@ -100,6 +114,14 @@ type OrganizationRepository interface {
UpdateProfile(ctx context.Context, actorID uuid.UUID, organization domain.Organization) (domain.Organization, error)
}
// OrganizationCreationResult is the original business result of creating an
// organization. Keeping the domain values lets storage replay the response
// without depending on generated HTTP types or a later profile state.
type OrganizationCreationResult struct {
Organization domain.Organization
Owner domain.Membership
}
// MembershipRepository stores memberships. A membership is unique per account
// and organization.
type MembershipRepository interface {
@@ -50,6 +50,8 @@ type Transactor interface {
type UnitOfWork interface {
IdentityRepositories
ConsentRepositories
AccountDeletionRequests() AccountDeletionRequests
ConsentRevocationEffects() ConsentRevocationEffects
OrganizationRepositories
AssessmentBankRepositories
Policies() PolicyRepository