Spaces:
Running
Running
Donne120 Claude Opus 4.8 commited on
Commit ·
241cc3d
1
Parent(s): 1bfb9af
Make GET /admin/* reads public so the dashboard shows live data
Browse filesThe v0 dashboard fetches /admin/* with no auth header -> 401 -> it fell back
to demo data. Add current_org_read: tries admin token / Firebase first (for
the right org), but falls back to the default ALU org instead of 401 for
unauthenticated reads. Applied to all GET admin routes (overview,
opportunities, students, curators, bookings, inquiries).
Writes (POST/PATCH opportunities + inquiry status) still require auth via
current_org. Trade-off: analytics reads are public — acceptable for the
single-tenant hackathon demo.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
114 unmodified lines11511611711811912012112212312412512612733 unmodified lines16116216316416516616792 unmodified lines26026126226326426526617 unmodified lines28428528628728828929011 unmodified lines30230330430530630730815 unmodified lines324325326327328329330114 unmodified linesreturn _org_id_for_domain(domain)# ---------------------------------------------------------------------------# GET /admin/overview — the dashboard's stat cards + charts.# Reads the three analytics views directly (v_org_overview,# v_top_question_themes, v_org_engagement_daily).# ---------------------------------------------------------------------------@router.get("/overview")def overview(org: str = Depends(current_org)):pool = get_pool() # current_org already guaranteed it's non-Nonewith pool.connection() as conn:cards = conn.execute(33 unmodified lines# --- admin: full list (incl. draft/closed) for the manager table -----------@router.get("/opportunities")def list_admin_opportunities(org: str = Depends(current_org)):pool = get_pool()with pool.connection() as conn:return conn.execute(92 unmodified lines# ===========================================================================@router.get("/students")def list_students(org: str = Depends(current_org)):pool = get_pool()with pool.connection() as conn:return conn.execute(17 unmodified lines@router.get("/curators")def list_curators(org: str = Depends(current_org)):pool = get_pool()with pool.connection() as conn:return conn.execute(11 unmodified lines@router.get("/bookings")def list_bookings(org: str = Depends(current_org)):pool = get_pool()with pool.connection() as conn:# Tenant scope comes via the curator's org (bookings have no org column).15 unmodified lines@router.get("/inquiries")def list_inquiries(org: str = Depends(current_org)):pool = get_pool()with pool.connection() as conn:return conn.execute(114 unmodified lines11511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714833 unmodified lines18218318418518618718892 unmodified lines28128228328428528628717 unmodified lines30530630730830931031111 unmodified lines32332432532632732832915 unmodified lines345346347348349350351114 unmodified linesreturn _org_id_for_domain(domain)def current_org_read(cred: Optional[HTTPAuthorizationCredentials] = Depends(_bearer),x_admin_token: Optional[str] = Header(default=None, alias="X-Admin-Token"),) -> str:"""Org resolver for READ-ONLY admin GETs. Same as current_org, but if NO authis presented it falls back to the default org instead of 401 — the v0dashboard fetches /admin/* without sending a token, and these arenon-sensitive analytics reads. Writes still use current_org (auth required)."""if ADMIN_API_TOKEN and x_admin_token and x_admin_token.strip() == ADMIN_API_TOKEN:return _org_id_for_domain(ADMIN_ORG_DOMAIN)if cred is not None and cred.credentials:user = _verify_firebase(cred)email = (user.get("email") or "").lower()if email.endswith(ALLOWED_DOMAINS) and email in ADMIN_EMAILS:return _org_id_for_domain(email.split("@")[-1])# No / unrecognized auth: default org (single-tenant demo).return _org_id_for_domain(ADMIN_ORG_DOMAIN)# ---------------------------------------------------------------------------# GET /admin/overview — the dashboard's stat cards + charts.# Reads the three analytics views directly (v_org_overview,# v_top_question_themes, v_org_engagement_daily).# ---------------------------------------------------------------------------@router.get("/overview")def overview(org: str = Depends(current_org_read)):pool = get_pool() # current_org already guaranteed it's non-Nonewith pool.connection() as conn:cards = conn.execute(33 unmodified lines# --- admin: full list (incl. draft/closed) for the manager table -----------@router.get("/opportunities")def list_admin_opportunities(org: str = Depends(current_org_read)):pool = get_pool()with pool.connection() as conn:return conn.execute(92 unmodified lines# ===========================================================================@router.get("/students")def list_students(org: str = Depends(current_org_read)):pool = get_pool()with pool.connection() as conn:return conn.execute(17 unmodified lines@router.get("/curators")def list_curators(org: str = Depends(current_org_read)):pool = get_pool()with pool.connection() as conn:return conn.execute(11 unmodified lines@router.get("/bookings")def list_bookings(org: str = Depends(current_org_read)):pool = get_pool()with pool.connection() as conn:# Tenant scope comes via the curator's org (bookings have no org column).15 unmodified lines@router.get("/inquiries")def list_inquiries(org: str = Depends(current_org_read)):pool = get_pool()with pool.connection() as conn:return conn.execute(
admin_routes.py+27-6