Fix CSV exports returning no data for OIDC-authenticated sessions#11845
Merged
Conversation
CSV export links were plain <a href> navigations, but this app now authenticates via a bearer token attached to fetch/GraphQL requests rather than a Devise session cookie (OIDC sign-in never establishes one). A plain link click therefore hit the export routes unauthenticated, and the policy scopes correctly-but-silently returned zero rows -- a CSV with headers but no data. ExportButton now fetches the CSV with the same bearer token Apollo attaches, then triggers a client-side blob download. This fixes every export in the app (signup spy, orders, coupons, attendees, etc.), since they all share this component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #11843 (signup spy export returns headers with no data) — and, as it turns out, every other CSV export in the app for the same reason.
Root cause: CSV export buttons (
ExportButton.tsx) rendered a plain<a href="/csv_exports/...">link. But this app's current auth model authenticates via a bearer token attached tofetch/GraphQL requests (AuthenticationManager), not a Devise session cookie — OIDC sign-in (the default "Sign In" flow) never establishes one, only an in-memory access token plus an HttpOnly refresh-token cookie scoped to/oauth_session/*thatCsvExportsControllernever reads.A plain link click therefore hits the export routes with no usable credentials.
CsvExportsController#signup_changes(and its siblings) don't crash on this — the Pundit scopes correctly-but-silently resolve to nothing for an unauthenticated request, so the response is a valid 200 CSV with headers and zero data rows. This affects every route under/csv_exports/*(coupons, event proposals, orders, run signups, run signup changes, runs, user con profiles, users, signup changes), since they all share the same export button component.Fix:
ReactTableExportButtonnow fetches the export URL itself, attaching the same bearer token Apollo Client attaches to GraphQL calls (viaAuthenticationManagerContext), then triggers a client-side blob download using the filename from theContent-Dispositionheader — instead of relying on a plain navigation.Test plan
test/controllers/csv_exports_controller_test.rbcoverage:bin/rails test test/controllers/csv_exports_controller_test.rb— 6/6 passingeslinton the changed frontend file — cleanyarn run ts:check— blocked locally by unrelated system memory pressure; please run before merging🤖 Generated with Claude Code