Skip to content

Public transparency export: formula-safe CSV download & print-friendly PDF statement #336

Open

Description

@JOY

Goal

Strengthen Give's transparency moat by letting any donor, journalist, or auditor download a formula-safe CSV or print/save a clean PDF directly from any public campaign statement page.

Scope (App-only — DOS/Give)

  1. Shared Formula-Safe CSV Builder (apps/web/src/lib/csv.ts + tests):
    • Pure RFC-4180 CSV serializer with optional UTF-8 BOM (\uFEFF) for Vietnamese Excel compatibility.
    • Strict CSV Formula Injection neutralization: prefix ' on any cell whose trimmed/untrimmed value starts with =, +, -, @, \t, or \r, plus proper double-quote escaping.
    • Safe filename slug helper.
  2. Public Statement CSV Export Route (apps/web/src/app/campaigns/[slug]/statement/export/route.ts + tests):
    • Public GET handler supporting ?filter=all|in|out|unexplained via parseStatementParams.
    • Validates slug (SLUG_PATTERN, <= 80), reads strictly via anonymous dbAs(), and requires isPublicStatus(campaign.status) (404 for drafts, pre-launch teasers, suspended, or cancelled campaigns).
    • Paginates give.public_statement up to a hard cap of 5,000 rows (setting X-Statement-Truncated: true when total > 5000).
    • Exports strictly public statement fields (Thời gian, Loại, Số tiền (VND), Nhóm, Đối tác (công khai), Trạng thái giải trình, Nội dung giải trình) — zero private donor PII, refund evidence, or receiving bank account numbers.
    • Headers: Content-Type: text/csv; charset=utf-8, Content-Disposition: attachment; filename="sao-ke-${slug}.csv", Cache-Control: public, s-maxage=60, stale-while-revalidate=300, X-Content-Type-Options: nosniff, X-Robots-Tag: noindex, nofollow.
  3. Statement Header Controls & Print/PDF Styling:
    • Add PrintStatementButton.tsx (window.print()) and "Tải CSV sao kê" link (preserving active filter) on apps/web/src/app/campaigns/[slug]/statement/page.tsx.
    • Add clean @media print styles in apps/web/src/app/globals.css: hide header/footer/nav/.print:hidden, render clean black-on-white typography, print masthead with campaign title/link/date, and break-inside: avoid on summary & statement rows.

Acceptance Criteria

  • pnpm --filter @give/web test, typecheck, lint, and build pass cleanly.
  • Zero leakage of private/suspended/pre-launch campaigns or non-public donor/refund info; CSV formula injection tested and neutralized.
  • Two independent reviews (worker + PO flagship review) pass with zero unresolved P0/P1/P2 findings.

Activity

  1. added
    line:money
    po:agy
    on Nov 23, 2026
  2. JOY commented on Nov 23, 2026

    @JOY
    ContributorAuthor

    Merged to dev (PR #340) — live on beta.give.vn, awaiting Production promotion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    line:moneypo:agy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions