Prevent reviewing courses for semesters that haven't started yet - #1261
Prevent reviewing courses for semesters that haven't started yet#1261IshanA2007 wants to merge 1 commit into
Conversation
Reviews could be placed for future terms (e.g. Fall 2026) because the review semester choices only had a lower year bound and ReviewForm.clean() only checked that a matching Section existed. Prod loads future-term sections for course registration, so those terms showed up as selectable, savable review options. Gate reviewable terms by calendar date instead of by whatever is loaded in the DB (Semester.latest()): - Add Semester.SEASON_START_MONTH + has_started() (started iff its start month has been reached in the current/prior year). - Add utils.reviewable_semesters(); route semesters_for_course() through it. recent_semesters() is left untouched so the schedule builder still sees upcoming terms. - ReviewForm.clean() now rejects a not-yet-started term (course and club). - Filter the club dropdown and empty-state semester lists to started terms. Tests: has_started() unit tests, form rejection of a future term, and XHR / semesters_for_course exclusion.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis PR adds a ChangesRestrict reviews and semester lists to started terms
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant ReviewForm
participant Semester
participant NewReviewView
User->>NewReviewView: Submit review with semester
NewReviewView->>ReviewForm: clean()
ReviewForm->>Semester: has_started()
Semester-->>ReviewForm: True/False
alt semester not started
ReviewForm-->>NewReviewView: ValidationError
NewReviewView-->>User: Re-render form with error
else semester started
ReviewForm-->>NewReviewView: Valid
NewReviewView-->>User: Review saved
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
GitHub Issues addressed
What I did
Reviews could be placed for a course in a future semester (e.g. Fall 2026). Root cause: the review semester choices (
recent_semesters()→semesters_for_course()) only had a lower year bound, andReviewForm.clean()only validated that a matchingSectionexisted. Production loads future-term sections for course registration, so those not-yet-started terms showed up as selectable and savable review options. (It didn't reproduce on older local data because that data simply lacked the future terms.)The fix gates reviewable terms by the calendar date rather than by whatever is loaded in the DB (
Semester.latest()):Semester.has_started()(models.py) — newSEASON_START_MONTHmap + method; a term is "started" once its start month is reached in the current/prior year (Fall→Aug, Summer→May, Spring/January→Jan).utils.reviewable_semesters()— started-only subset ofrecent_semesters()(DB-levelCase/Whenfilter);semesters_for_course()now routes through it.recent_semesters()is intentionally left unchanged so the schedule builder still sees upcoming terms.ReviewForm.clean()— the real backend gate: rejects a not-yet-started term for both course and club reviews.club_semester_choices_payload) and the empty-state / error-render semester lists innew_review.pynow only offer started terms, so users never see an invalid option.Screenshots
Testing
Verified against a fresh prod dump (contains Fall 2026 = 9,038 sections). As of 2026-07-08:
Fall 2026 has_started=False→ excluded fromreviewable_semesters()but still present inrecent_semesters();Summer 2026/Spring 2026remain reviewable.Automated (full suite green — 265 tests):
test_semester.HasStartedTestCase— unit tests for the date gate (past/future year, Fall-before-August, Summer-by-July, start-month boundary).test_review.ReviewFormSectionValidationTests— form rejects a future term (even with a matching section) and accepts a started term.test_review.ReviewCascadeJsonEndpointsTests— future terms excluded fromsemesters_for_course()and thereview_semester_optionsXHR.To test manually: pick a course with a Fall 2026 section under My Reviews → New Review; Fall 2026 should not be offered as a term.
Questions/Discussions/Notes
has_started().Summary by CodeRabbit
New Features
Bug Fixes
Tests