portal: derive source from OC email visibility instead of trusting a stale flag
ci/woodpecker/push/woodpecker Pipeline was canceled

oc-incognito disables email matching by design, so a profile that later shows an
email leaves the member silently unmatched. The sweep now flips those to oc and
records oc_email; profiles still hiding an email are untouched. Test covers both.
This commit is contained in:
inference-admin committed 2026-11-17 05:04:50 +00:00
1 parent 35735d67a5
commit ffe62d3c78
2 files changed
+69

No files matched your search

+46
View File
@@ -14,6 +14,7 @@ Three responsibilities:
"""
import os
import inspect
import json
import logging
import re
@@ -9168,6 +9169,46 @@ async def settle_held_credits(send: bool = True) -> dict:
"stale": stale, "notified": notified}
async def derive_member_sources() -> dict:
"""Keep `source` honest: a profile that now shows an email is not incognito.
`oc-incognito` exists because a member's OC profile hid its email; reconciliation
then matches on the stored slug and skips email matching. When that profile gains
a visible email the flag goes stale and keeps email matching switched off — which
is exactly how a credit pack ends up held for a member we could have matched.
This pass flips the flag back and records the email.
"""
try:
rows = fetch_member_index()
if inspect.isawaitable(rows):
rows = await rows
except Exception as exc: # noqa: BLE001
return {"error": f"index unavailable: {str(exc)[:120]}"}
slug2email = {(r[1] or "").strip().lower(): (r[0] or "").strip().lower()
for r in rows if len(r) > 1 and r[0]}
flipped: list[dict] = []
conn = get_db()
try:
stale = conn.execute(
"SELECT email, slug FROM members WHERE source = 'oc-incognito'").fetchall()
finally:
conn.close()
for email, slug in stale:
visible = slug2email.get((slug or "").strip().lower())
if not visible:
continue
set_member_source(email, "oc")
conn = get_db()
try:
conn.execute("UPDATE members SET oc_email = ? WHERE lower(email) = ?",
(visible, email.lower()))
conn.commit()
finally:
conn.close()
flipped.append({"email": email, "oc_email": visible})
return {"checked": len(stale), "flipped": flipped}
@app.post("/admin/sweep")
@limiter.limit("20/minute")
async def admin_sweep(request: Request):
@@ -9221,6 +9262,11 @@ async def admin_sweep(request: Request):
except Exception as exc: # noqa: BLE001
result["held_credits"] = {"error": str(exc)[:200]}
try:
result["member_sources"] = await derive_member_sources()
except Exception as exc: # noqa: BLE001
result["member_sources"] = {"error": str(exc)[:200]}
# Paid Open Collective contributors with no portal row — the net for members
# the sweep cannot see (hidden email, org account). Emails info@ only when it
# finds something, and only when the set changes. Was a daily script on the