Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions internal/intake/intake.go
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down
38 changes: 38 additions & 0 deletions internal/intake/intake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions internal/migrations/000120_intake_account_deletion.down.sql
Original file line number Diff line number Diff line change
@@ -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'));
3 changes: 3 additions & 0 deletions internal/migrations/000120_intake_account_deletion.up.sql
Original file line number Diff line number Diff line change
@@ -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'));
6 changes: 3 additions & 3 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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." }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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"
Expand Down