portal: member_aliases — credit a purchase made from a member's second OC profile
ci/woodpecker/push/woodpecker Pipeline was canceled
ci/woodpecker/push/woodpecker Pipeline was canceled
A person can hold two Open Collective profiles, one hiding its email. Purchases from the hidden one have no email to match and no primary slug, so they land in held credits. member_aliases maps extra slugs to a member email; the sweep's held-credit pass resolves email -> slug -> alias before holding anything. Admin GET/POST /admin/aliases manages rows; test covers grant and idempotency.
This commit is contained in:
1 parent
d51fa55a1d
commit
ea0f728af2
2 files changed
+87
-1
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import asyncio, os, sys, tempfile
|
||||
os.environ["DB_PATH"] = os.path.join(tempfile.mkdtemp(), "aliases.db")
|
||||
os.environ.setdefault("ADMIN_TOKEN", "admin-test")
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import app.main as m
|
||||
m.DB_PATH = os.environ["DB_PATH"]; m.ADMIN_TOKEN = "admin-test"
|
||||
|
||||
conn = m.get_db(); m._ensure_allowance_tables(conn)
|
||||
conn.execute("INSERT OR REPLACE INTO members (email, slug, active, credit_balance, source) VALUES (?,?,?,?,?)",
|
||||
("a@example.org", "main-slug", 1, 0.0, "oc"))
|
||||
conn.execute("INSERT INTO held_credits (slug, email, name, amount, oc_reference) VALUES (?,?,?,?,?)",
|
||||
("hidden-abc", "", "A", 10.0, "oc:hidden-abc:ref1"))
|
||||
conn.commit(); conn.close()
|
||||
|
||||
import httpx
|
||||
async def add():
|
||||
async with httpx.AsyncClient(transport=httpx.ASGITransport(app=m.app), base_url="http://p", timeout=60) as c:
|
||||
r = await c.post("/admin/aliases", headers={"x-admin-token": "admin-test"},
|
||||
json={"slug": "hidden-abc", "email": "a@example.org"})
|
||||
return r.status_code, r.json()
|
||||
st, d = asyncio.run(add())
|
||||
assert st == 200, (st, d)
|
||||
r1 = asyncio.run(m.settle_held_credits(send=False))
|
||||
conn = m.get_db(); bal = conn.execute("SELECT credit_balance FROM members WHERE email='a@example.org'").fetchone()[0]; conn.close()
|
||||
print(" alias add:", st, "| granted:", r1["granted"], "| balance:", bal)
|
||||
assert bal == 10.0, "a purchase from the aliased hidden profile must credit the member"
|
||||
assert len(r1["granted"]) == 1
|
||||
r2 = asyncio.run(m.settle_held_credits(send=False))
|
||||
assert len(r2["granted"]) == 0 and bal == 10.0
|
||||
print("ALIAS TABLE OK: hidden-profile hold credits the member; no double-apply")
|
||||
Reference in new issue
Block a user