From 2a528fceaa64b83886070f0515f2d89b18f58a76 Mon Sep 17 00:00:00 2001 From: Keloran Date: Sun, 22 Nov 2026 17:21:59 +0000 Subject: [PATCH] account deletion --- internal/intake/intake.go | 17 +++++++-- internal/intake/intake_test.go | 38 +++++++++++++++++++ .../000120_intake_account_deletion.down.sql | 3 ++ .../000120_intake_account_deletion.up.sql | 3 ++ openapi.yaml | 6 +-- 5 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 internal/migrations/000120_intake_account_deletion.down.sql create mode 100644 internal/migrations/000120_intake_account_deletion.up.sql diff --git a/internal/intake/intake.go b/internal/intake/intake.go index 6eaf254..1c10e8e 100644 --- a/internal/intake/intake.go +++ b/internal/intake/intake.go @@ -1,5 +1,5 @@ // Package intake is a project's shareable request form: anyone with its unlisted link can send a bug -// report or feature request, without an account. Submissions wait for the team to triage them: promoted +// report, feature request or account deletion request (GDPR), without an account. Submissions wait for the team to triage them: promoted // into an unassigned backlog ticket, or dismissed. Nothing about the project is shown to the sender. package intake @@ -24,11 +24,15 @@ const ( MaxContact = 200 PerSenderHour = 5 // one sender's submissions per hour, per form PerProjectDay = 200 // all submissions per project per day + + // AccountDeletion asks the team to erase the sender's account (GDPR Art. 17). It needs a contact so the + // team can find the account and confirm; promoted, it becomes a task (tickets have no such type). + AccountDeletion = "account_deletion" ) var ( ErrClosed = httpx.Code("form_closed", "this form isn't taking requests") - ErrInvalid = httpx.Code("bad_intake_request", "a title (up to 200 characters) and a type (bug or feature) are required") + ErrInvalid = httpx.Code("bad_intake_request", "a title (up to 200 characters) and a type (bug, feature or account_deletion) are required; account_deletion also needs a contact") ErrTooMany = httpx.Code("intake_rate_limited", "too many requests from you; please try again later") ErrNotFound = errors.New("not found") ErrDecided = httpx.Code("already_triaged", "this request has already been triaged") @@ -99,7 +103,7 @@ func (s Store) Open(ctx context.Context, token string) bool { // Submit records a request sent through form token by sender (their address; only its hash is kept). func (s Store) Submit(ctx context.Context, token, sender, typ, title, details, contact string) error { typ, title, details, contact = strings.TrimSpace(typ), strings.TrimSpace(title), strings.TrimSpace(details), strings.TrimSpace(contact) - if (typ != "bug" && typ != "feature") || title == "" || len([]rune(title)) > MaxTitle || len([]rune(details)) > MaxDetails || len([]rune(contact)) > MaxContact { + if (typ != "bug" && typ != "feature" && typ != AccountDeletion) || (typ == AccountDeletion && contact == "") || title == "" || len([]rune(title)) > MaxTitle || len([]rune(details)) > MaxDetails || len([]rune(contact)) > MaxContact { return ErrInvalid } sum := sha256.Sum256([]byte(token + "|" + sender)) @@ -192,7 +196,12 @@ func (s Store) Promote(ctx context.Context, owner, actor, id string) (Submission // ponytail: the ticket is made outside this tx (tickets.Store has no tx variant); the row lock still // stops a double promote, and a failure after it leaves a normal backlog ticket, not a lost request // made as the promoter, so its history starts with them (TL-75), not the organization - t, err := tickets.Store{DB: s.DB}.CreateBacklogAs(ctx, owner, actor, x.ProjectID, x.Type, x.Title, desc+note) + typ := x.Type + if typ == AccountDeletion { + typ = "task" + note = "_Account deletion request._ " + note + } + t, err := tickets.Store{DB: s.DB}.CreateBacklogAs(ctx, owner, actor, x.ProjectID, typ, x.Title, desc+note) if err != nil { return err } diff --git a/internal/intake/intake_test.go b/internal/intake/intake_test.go index 4ff9c58..4d75853 100644 --- a/internal/intake/intake_test.go +++ b/internal/intake/intake_test.go @@ -204,6 +204,44 @@ func TestIntake(t *testing.T) { } } +// GDPR: an account deletion request needs a contact, and is promoted as a task. +func TestIntakeAccountDeletion(t *testing.T) { + ctx := context.Background() + db, err := pgxpool.New(ctx, os.Getenv("TEST_DATABASE_URL")) + if err != nil { + t.Fatal(err) + } + defer db.Close() + if _, err := db.Exec(ctx, `DELETE FROM projects WHERE owner_clerk_id = 'ik4'`); err != nil { + t.Fatal(err) + } + var pid string + _ = db.QueryRow(ctx, `INSERT INTO projects (owner_clerk_id, name, key_prefix) VALUES ('ik4', 'Erase', 'ER') RETURNING id`).Scan(&pid) + s := Store{DB: db} + token, err := s.SetOpen(ctx, "ik4", pid, true, false) + if err != nil { + t.Fatal(err) + } + if err := s.Submit(ctx, *token, "198.51.100.1", AccountDeletion, "Delete my account", "", ""); !errors.Is(err, ErrInvalid) { + t.Fatalf("no contact: %v", err) + } + if err := s.Submit(ctx, *token, "198.51.100.1", AccountDeletion, "Delete my account", "", "sam@example.com"); err != nil { + t.Fatal(err) + } + list, err := s.List(ctx, "ik4", pid, "pending", 10) + if err != nil || len(list) != 1 || list[0].Type != AccountDeletion { + t.Fatalf("list: %+v %v", list, err) + } + x, err := s.Promote(ctx, "ik4", "user_ava", list[0].ID) + if err != nil { + t.Fatal(err) + } + tk, err := tickets.Store{DB: db}.Get(ctx, "ik4", *x.TicketID) + if err != nil || tk.Type != "task" || !strings.Contains(tk.Description, "Account deletion request") || !strings.Contains(tk.Description, "sam@example.com") { + t.Fatalf("ticket: %+v %v", tk, err) + } +} + // TL-162: a burst of simultaneous requests from one sender can't get past the cap. func TestIntakeBurst(t *testing.T) { ctx := context.Background() diff --git a/internal/migrations/000120_intake_account_deletion.down.sql b/internal/migrations/000120_intake_account_deletion.down.sql new file mode 100644 index 0000000..617dfec --- /dev/null +++ b/internal/migrations/000120_intake_account_deletion.down.sql @@ -0,0 +1,3 @@ +DELETE FROM intake_submissions WHERE type = 'account_deletion'; +ALTER TABLE intake_submissions DROP CONSTRAINT intake_submissions_type_check; +ALTER TABLE intake_submissions ADD CONSTRAINT intake_submissions_type_check CHECK (type IN ('bug', 'feature')); diff --git a/internal/migrations/000120_intake_account_deletion.up.sql b/internal/migrations/000120_intake_account_deletion.up.sql new file mode 100644 index 0000000..925975e --- /dev/null +++ b/internal/migrations/000120_intake_account_deletion.up.sql @@ -0,0 +1,3 @@ +-- Request forms also take account deletion requests (GDPR right to erasure). +ALTER TABLE intake_submissions DROP CONSTRAINT intake_submissions_type_check; +ALTER TABLE intake_submissions ADD CONSTRAINT intake_submissions_type_check CHECK (type IN ('bug', 'feature', 'account_deletion')); diff --git a/openapi.yaml b/openapi.yaml index a1ecf66..dd0fbae 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1759,7 +1759,7 @@ paths: type: object required: [type, title] properties: - type: { type: string, enum: [bug, feature] } + type: { type: string, enum: [bug, feature, account_deletion], description: "account_deletion (GDPR erasure) needs a contact; promoted it becomes a task." } title: { type: string, maxLength: 200 } details: { type: string, maxLength: 5000 } contact: { type: string, maxLength: 200, description: "Optional, e.g. an email; seen by the team only." } @@ -6770,7 +6770,7 @@ components: properties: id: { type: string, format: uuid } project_id: { type: string, format: uuid } - type: { type: string, enum: [bug, feature] } + type: { type: string, enum: [bug, feature, account_deletion], description: "account_deletion (GDPR erasure) needs a contact; promoted it becomes a task." } title: { type: string } details: { type: string } contact: { type: string } @@ -6962,7 +6962,7 @@ components: bad_estimate_scale: "estimate_scale must be none, fibonacci, tshirt, powers or linear" bad_external: "external needs source (bugfixes), project and id; url must be http(s)" bad_file: "file must be an upload in this service's file store, with a key and name" - bad_intake_request: "a title (up to 200 characters) and a type (bug or feature) are required" + bad_intake_request: "a title (up to 200 characters) and a type (bug, feature or account_deletion) are required; account_deletion also needs a contact" bad_intake_status: "status must be pending, promoted or dismissed" bad_invite_email: "email_address must be a valid email address" bad_invite_scope: "scope must be organization, team, or project"