erasure

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package erasure is the registry of where ReputeCast keeps a contact's personal data, so erasing a contact and exporting what is stored about one reach every table (review 2026-11 DP-1, DP-2).

Each package that stores personal data about contacts declares a Source: the tables and columns it holds, how to erase them, and what to export. internal/app collects the sources (wire_audience.go) and a test there fails when a table with personal-data columns is in no source and not exempted with a reason. The package imports nothing from ReputeCast but authz and i18n, so any package can register without an import cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(ctx context.Context, tx pgx.Tx, b *Batch, stmts ...string) error

Exec runs each statement with $1 the batch's ids, $2 its addresses, $3 its phone numbers and $4 the workspace: the shape most sources need. A CTE names the four parameters' types, so a statement needn't use them all.

Types

type Batch

type Batch struct {
	WorkspaceID uuid.UUID
	Subjects    []Subject
	Reason      Reason
	At          time.Time
}

Batch is the contacts of one workspace erased together.

func (*Batch) Emails

func (b *Batch) Emails() []string

Emails are the batch's addresses, lower-cased, without blanks.

func (*Batch) IDs

func (b *Batch) IDs() []uuid.UUID

IDs are the batch's contact ids.

func (*Batch) Phones

func (b *Batch) Phones() []string

Phones are the batch's phone numbers (E.164), without blanks.

type Export

type Export struct {
	Section string
	SQL     string
	Needs   authz.Permission
}

Export is one section of a contact's data export: a query whose rows are written as JSON objects, column by column. It gets $1 the contact id, $2 the workspace id, $3 the contact's address (lower-cased) and $4 the phone number. Needs, when set, is the permission a section also needs (paid membership needs earn:view); without it the section says so.

type Reason

type Reason string

Reason says why contacts are erased; it travels with contact.erased.

const (
	// ReasonTeam: a person (or an API key) erased them.
	ReasonTeam Reason = "team"
	// ReasonPolicy: the sunset policy's "delete after N months".
	ReasonPolicy Reason = "policy"
	// ReasonUnconfirmed: a double opt-in signup never confirmed in time.
	ReasonUnconfirmed Reason = "unconfirmed"
)

type Refusal

type Refusal struct {
	IDs     []uuid.UUID
	Code    string
	Message i18n.Msg
}

Refusal is contacts a source won't let go: a live paid subscription in Stripe, say. Message takes {n}, the number refused.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is every source, in a fixed order: sources by name, then the core source (the contacts table itself) last.

func New

func New(core Source, sources ...Source) *Registry

New builds the registry. Duplicate names are a programming error.

func (*Registry) Erase

func (r *Registry) Erase(ctx context.Context, tx pgx.Tx, b *Batch) error

Erase runs every source's Erase, the core source last.

func (*Registry) Guard

func (r *Registry) Guard(ctx context.Context, tx pgx.Tx, b *Batch) ([]Refusal, error)

Guard asks every source's guard; the refusals of all sources come back together.

func (*Registry) Sources

func (r *Registry) Sources() []Source

Sources are all sources in the order they run, the core source last.

type Source

type Source struct {
	Name   string
	Tables []Table
	// Guard, optional, names contacts that can't be erased now.
	Guard func(ctx context.Context, tx pgx.Tx, b *Batch) (*Refusal, error)
	// Erase removes the source's personal data for the batch. It runs before
	// the contacts themselves are scrubbed, so the address still matches.
	Erase   func(ctx context.Context, tx pgx.Tx, b *Batch) error
	Exports []Export
}

Source is one package's personal data about contacts.

type Subject

type Subject struct {
	ID    uuid.UUID
	Email string
	Phone string
}

Subject is one contact being erased, read before anything is changed so sources can still match rows by the address or phone number.

type Table

type Table struct {
	Name string
	// Action: "delete" (the rows go), "clear" (the columns are emptied),
	// "anonymize" (identifying columns go, the rest stays for statistics).
	Action string
	// Columns are the personal-data columns the action removes.
	Columns []string
	// Kept are personal-data-looking columns left as they are, with why
	// ("contact_id": "counts distinct clickers; the contact is scrubbed").
	Kept map[string]string
}

Table is one table a source covers: the personal-data columns it clears (or the rows it deletes) and the ones it keeps on purpose, with why.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL