Repository navigation
feat(statement): formula-safe CSV export & print-friendly PDF view (Refs #336) - #340
Conversation
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
…e CSV safety (Refs #336)
|
PO acceptance: merge at 207701b |
Summary
Refs #336
Implements public transparency exports (formula-safe CSV download and print-friendly PDF statement view) for public campaign statements:
apps/web/src/lib/csv.ts+csv.test.ts):\uFEFF, enabled by default for Vietnamese Excel compatibility) and CRLF line endings.'on any cell starting with=,+,-,@,\t, or\r(including when preceded by leading whitespace or ASCII control characters), applied prior to RFC-4180 quoting while keeping finite non-negative numbers unquoted.csvFilenameSlughelper restricting filenames to[a-z0-9-].apps/web/src/app/campaigns/[slug]/statement/export/route.ts+route.test.ts):GETroute reading strictly via anonymousdbAs(), validatingslug, enforcingisPublicStatus(campaign.status), and verifyinggetMoneyTotals(db, campaign.id)(404for drafts, pre-launchapprovedteasers, suspended, cancelled, or missing campaigns).?filter=all|in|out|unexplainedviaparseStatementParams, paginatesgive.public_statementcleanly up to5,000rows (with ID deduplication across concurrent shifts andX-Statement-Truncated: truewhentotal > 5000), and exports strictly public fields shown onStatementPage.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, andX-Robots-Tag: noindex, nofollow.PrintStatementButton.tsx,statement/page.tsx,globals.css,PublicEvidence.tsx,icons.tsx+ tests):print:hiddenaction bar withTải CSV sao kêlink (preserving active filter) andIn / Lưu PDFbutton..print-onlymasthead (hidden print:block) with campaign title, canonical statement URL, print timestamp, active filter/pagination context when applicable, and public totals summary.@media printrules forcing light color tokens,display: blockbody layout, hiding site header/footer/nav/.print\:hidden, andbreak-inside: avoidon summary cards and statement rows.Verification
pnpm format:check— passpnpm --filter @give/web typecheck— passpnpm --filter @give/web lint— passpnpm --filter @give/web exec vitest run --maxWorkers=2 --fileParallelism=false— 216 test files passed, 2967 tests passedpnpm --filter @give/web build— pass📌 TL;DR
This PR implements a public CSV export endpoint and print-optimized UI for campaign financial statements, featuring robust security measures against CSV formula injection and strict data privacy controls. It introduces a dedicated
csvutility library, a new API route for paginated data retrieval, and print-specific CSS/HTML adjustments to ensure accurate offline reporting.🎯 Type of Change
🔍 Changes Walkthrough
apps/web/src/lib/csv.ts=,+,-,@, etc.) with a single quote.apps/web/src/lib/csv.test.tsapps/web/src/app/campaigns/[slug]/statement/export/route.tsGET /campaigns/[slug]/statement/export. Validates campaign public status, fetches statement rows with pagination (capped at 5,000 rows), resolves returned-transfer pairs, and returns a secure CSV response with appropriate headers (Content-Disposition,Cache-Control,X-Statement-Truncated).apps/web/src/app/campaigns/[slug]/statement/export/route.test.tsapps/web/src/app/campaigns/[slug]/statement/page.tsxprint-onlymasthead section that displays campaign totals, canonical URL, and print timestamp, visible only when printing.apps/web/src/app/campaigns/[slug]/statement/page.test.tsapps/web/src/app/campaigns/[slug]/statement/PrintStatementButton.tsxwindow.print()on click.apps/web/src/app/campaigns/[slug]/statement/PrintStatementButton.test.tsapps/web/src/app/globals.css@media printstyles to hide navigation/headers, force light color scheme, and prevent page breaks inside cards.apps/web/src/components/ui/icons.tsxPrinterIconSVG component.apps/web/src/components/PublicEvidence.tsxprint:hiddenclass to evidence details to keep print output clean.apps/web/src/lib/statement.test.tsstatementExportHref,statementCsvRow) and CSV header constants.📊 Architectural Flow
sequenceDiagram participant User participant WebUI as Statement Page (React) participant API as Export Route (Next.js) participant DB as Supabase (Public) participant CSV as CSV Lib User->>WebUI: Click "Download CSV" or "Print" alt Download CSV WebUI->>API: GET /campaigns/[slug]/statement/export API->>DB: Validate Campaign Status (Public?) alt Not Public API-->>User: 404 Not Found else Public API->>DB: Fetch Statement Rows (Paginated) API->>DB: Fetch Returned Transfer Pairs API->>CSV: Build CSV (Neutralize Formulas, Add BOM) API-->>User: 200 OK (CSV Blob) end else Print WebUI->>User: Trigger window.print() Note over User: Browser applies @media print CSS Note over User: Hides nav, shows print-only masthead end