Skip to content

feat(view for 990 forms): redirect to latest uploaded form - #3643

Open
relyks wants to merge 4 commits into
masterfrom
self-updating-link-for-990-form
Open

feat(view for 990 forms): redirect to latest uploaded form#3643
relyks wants to merge 4 commits into
masterfrom
self-updating-link-for-990-form

Conversation

@relyks

@relyks relyks commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add /current-990-form, which redirects to the highest-year matching Form 990 PDF in static/files.
  • Update every public Form 990 link to use the stable endpoint.
  • Add coverage for latest-file selection and missing files.

Why

Uploading a new Sefaria_YYYY_990_Public.pdf now automatically makes it the public Form 990 without changing page links.

Validation

  • DJANGO_SETTINGS_MODULE=sefaria.settings python -m pytest -q reader/tests/current_990_form_test.py

@relyks
relyks marked this pull request as ready for review August 19, 2026 08:17
@gitvelocity-reviewer

Copy link
Copy Markdown

📊 Code Quality Score: 8/100

Base Score 32 × ESF 0.25 = 8

Category Score Factors
🔭 Scope 7/20 Five files are modified: reader/views.py adds the new view, sites/sefaria/urls.py adds the route, static/js/StaticPages.jsx updates two link hrefs, templates/static/he/ways-to-give.html updates one link, and reader/tests/current_990_form_test.py is a new test file. All changes are within the static-page-serving subsystem.
🏗️ Architecture 5/20 The change converts two static file references into a server-side redirect view, following the same pattern already used by annual_report in reader/views.py. No new module boundary or dependency is introduced.
⚙️ Implementation 6/20 current_990_form uses re.compile with a walrus operator inside a list comprehension to extract year integers from filenames, then calls max() on the resulting list of (year, filename) tuples to select the latest file. The STATICFILES_DIRS[0] index and os.listdir call are unguarded against an empty list or a missing directory.
⚠️ Risk 4/20 The two replaced links in StaticPages.jsx and ways-to-give.html now go through a server redirect instead of directly to a file; a misconfigured STATICFILES_DIRS or absent files directory would surface as an unhandled IndexError or FileNotFoundError rather than an Http404. The change is easily reverted by restoring the hardcoded hrefs.
✅ Quality 9/15 current_990_form_test.py provides two pytest tests using tmp_path and monkeypatch: one verifies the redirect targets the 2025 file over 2023 while ignoring Sefaria_2026_Annual_Report.pdf, and one verifies Http404 is raised when no matching file exists. No test covers an empty STATICFILES_DIRS list or a missing files subdirectory.
🔒 Perf / Security 1/5 The view performs a single os.listdir call on each request with no caching. No security-specific work is present beyond what the existing Django request handling provides.

Was this score accurate? 👍 Yes · 👎 No

How this was scored →

Scored by GitVelocity · How are scores calculated?

@relyks
relyks requested a review from yitzhakc August 21, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant