portal: answer for a lapsed membership instead of leaving the dashboard blank
ci/woodpecker/push/woodpecker Pipeline was canceled
ci/woodpecker/push/woodpecker Pipeline was canceled
New read-only /broker/membership-status, authenticated by the broker secret with a verifier that admits a member row in ANY state (usage and keys still require active). Returns active/state, the latest allowance_log decision with its evidence, the OC minimum contribution (MIN_CONTRIBUTION, copy-only — OC stays the authority), credits, allowance and the contribute URL. MIN_CONTRIBUTION is deliberately NOT wired into deactivation: a number we half-know should not cost anyone access.
This commit is contained in:
1 parent
6041c0cdb2
commit
27b0ea564a
2 files changed
+88
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import asyncio, os, sys, tempfile
|
||||
os.environ["DB_PATH"] = os.path.join(tempfile.mkdtemp(), "status.db")
|
||||
os.environ.setdefault("BROKER_SECRET", "test-secret")
|
||||
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.BROKER_SECRET = "test-secret"
|
||||
|
||||
conn = m.get_db()
|
||||
m._ensure_allowance_tables(conn)
|
||||
conn.execute("INSERT OR REPLACE INTO members (email, slug, active, credit_balance, balance, source) VALUES (?,?,?,?,?,?)",
|
||||
("lapsed@example.org", "lapsed", 0, 3.0, 0.0, "oc"))
|
||||
conn.execute("INSERT INTO allowance_log (email, cycle, decision, evidence, anchor_day) VALUES (?,?,?,?,?)",
|
||||
("lapsed@example.org", "2026-11-05", "awaiting_contribution", "no live recurring contribution in this cycle", 5))
|
||||
conn.commit(); conn.close()
|
||||
|
||||
import httpx
|
||||
async def run():
|
||||
async with httpx.AsyncClient(transport=httpx.ASGITransport(app=m.app), base_url="http://p", timeout=60) as c:
|
||||
r = await c.get("/broker/membership-status", headers={"x-broker-secret": "test-secret", "x-member-email": "lapsed@example.org"})
|
||||
return r.status_code, r.json()
|
||||
st, d = asyncio.run(run())
|
||||
print(" route:", st, "| active:", d.get("active"), "| state:", d.get("state"), "| min:", d.get("minimum_contribution"), "| decision:", (d.get("last_decision") or {}).get("decision"))
|
||||
assert st == 200 and d["active"] is False and d["minimum_contribution"] == 5.0
|
||||
assert (d.get("last_decision") or {}).get("decision") == "awaiting_contribution"
|
||||
assert d.get("contribute_url")
|
||||
print("MEMBERSHIP STATUS ROUTE OK: answers for a lapsed member, states minimum and last decision")
|
||||
Reference in new issue
Block a user