portal: converge all compliance orders on the single ERPNext portal

Root cause of customers being unable to log in: ERPNext (portal.performancewest.net)
is the intended single portal and already surfaces compliance/trucking orders
(performancewest_erpnext/www/orders.py reads compliance_orders by email). But
only the Stripe checkout path provisioned the ERPNext Website User up-front
(findOrCreateCustomer). PayPal / crypto / remediation-pipeline orders go straight
to handlePaymentComplete, which created NO portal user and never set
portal_user_created -> no login + no set-password invite (exactly what happened
to the Paul Wilson / Compound Technologies PayPal order).

- handlePaymentComplete: add ensureCompliancePortalUser() in the shared
  post-payment path so EVERY paid compliance order (any payment method) gets an
  ERPNext portal account + the set-password invite. Idempotent.
- Guard against placeholder emails (synthetic@/pipeline.com etc): skip portal
  provisioning and the set-password invite for non-deliverable addresses.
- compliance-orders API: validate email format AND reject placeholder addresses
  at order creation (was: presence-only, so synthetic@pipeline.com passed).
- delivery_worker: never email a set-password invite to a placeholder address.

Note: the legacy PG-customers login (api/routes/portal-auth.ts, /account/*) is
CRTC/formation-era and only backfills canada_crtc_orders/orders, never
compliance_orders. ERPNext is now the consistent portal for compliance.
This commit is contained in:
justin 2026-06-02 22:44:34 -05:00
parent 2b13c36c93
commit f6419759e6
3 changed files with 115 additions and 1 deletions

View file

@ -338,6 +338,11 @@ def _build_portal_onboard_html(pg_order: dict | None) -> str:
order_number = pg_order.get("order_number", "")
if not email:
return ""
# Never send a set-password invite to a known placeholder address (e.g. the
# FMCSA-census "synthetic@pipeline.com" used when no real email was found).
em = email.strip().lower()
if em.startswith("synthetic@") or em.split("@")[-1] in {"pipeline.com", "example.com", "test.com"}:
return ""
token = _generate_set_password_token(email, order_number)
url = f"{PORTAL_URL.rstrip('/')}/set-password?token={token}"
return _ONBOARD_TEMPLATE.format(url=url, ttl_hours=SET_PASSWORD_TTL_HOURS)