From 797067ee38577594ea041d8a895b439cc44c6f12 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 30 Apr 2026 03:09:42 +0000 Subject: [PATCH] Refuse to send compliance letters to addresses without a postal code --- platform/compliance.go | 7 +++++++ platform/mailer/mailer.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/platform/compliance.go b/platform/compliance.go index c4eb2e8c..b51ddab5 100644 --- a/platform/compliance.go +++ b/platform/compliance.go @@ -33,6 +33,13 @@ func ComplianceRequestMailerCreate(ctx context.Context, user User, site_id int32 if site.OrganizationID != user.Organization.ID { return 0, fmt.Errorf("permission denied") } + address, err := models.FindAddress(ctx, txn, site.AddressID) + if err != nil { + return 0, fmt.Errorf("find address %d: %w", site.AddressID, err) + } + if address.PostalCode == "" { + return 0, fmt.Errorf("address %d does not have a postal code", address.ID) + } features, err := models.Features.Query( models.SelectWhere.Features.SiteID.EQ(site.ID), ).All(ctx, txn) diff --git a/platform/mailer/mailer.go b/platform/mailer/mailer.go index 311555a6..4f943b0c 100644 --- a/platform/mailer/mailer.go +++ b/platform/mailer/mailer.go @@ -17,6 +17,9 @@ import ( "github.com/rs/zerolog/log" ) +// This is the entrypoint for the backend job of sending a compliance mailer +// It should only return errors for programmer-level errors we want retried on restart +// Not for normal issues func ComplianceSend(ctx context.Context, row_id int32) error { bxn := db.PGInstance.BobDB compliance_req, err := models.FindComplianceReportRequest(ctx, bxn, row_id) @@ -47,6 +50,10 @@ func ComplianceSend(ctx context.Context, row_id int32) error { if err != nil { return fmt.Errorf("find address: %w", err) } + if address.PostalCode == "" { + log.Warn().Int32("id", address.ID).Msg("dropping mailer job because the address has no postal code") + return nil + } organization, err := models.FindOrganization(ctx, bxn, site.OrganizationID) if err != nil {