You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hide Peer Instruction (Student) menu option in courses without peer assignments - #1705
Goal is to eliminate distraction (and links to current accessibility issues) for courses not making use of Peer Instruction by only presenting that link to students in the user menu when the course has at least one peer instruction assignment.
This pull request introduces a new utility function, course_has_peer_assignments, and updates both backend and frontend logic to show the "Peer Instruction (Student)" menu link only for courses that have at least one peer instruction assignment (regardless of visibility). The changes ensure that users see a relevant menu, improve performance by skipping unnecessary lookups for anonymous users, and add comprehensive tests to verify the new logic.
Backend: Peer Assignment Detection and Context Propagation
Added course_has_peer_assignments to the database layer to detect if a course has any peer instruction assignments, using efficient SQL queries that check both the is_peer flag and kind == "Peer"[1]], [2]], [3]]).
Updated routers (auth.py, problem_report.py, student.py, course.py) to include has_peer_assignments in the context passed to templates, ensuring that the information is available for rendering menus [1]], [2]], [3]], [4]], [5]], [6]], [7]], [8]], [9]], [10]]).
Frontend: Conditional Menu Rendering
Modified the navigation bar template (_navbar.html) and JavaScript (bookfuncs.js) to only show the "Peer Instruction (Student)" link if has_peer_assignments is true or undefined (for backward compatibility with older servers) [1]], [2]], [3]]).
Template and Configuration Updates
Updated ebook_config.py to include hasPeerAssignments in the configuration, and optimized the logic to skip peer assignment lookups for anonymous users, improving performance [1]], [2]], [3]]).
Testing
Added comprehensive tests for course_has_peer_assignments and for the new configuration logic, ensuring correct behavior for courses with and without peer assignments, and for both anonymous and logged-in users [1]], [2]], [3]]).
Backend: Peer Assignment Detection
Added course_has_peer_assignments to the database access layer, efficiently checking for peer instruction assignments using SQLAlchemy's exists[1]], [2]], [3]]).
Updated routers to include has_peer_assignments in their template contexts, so the frontend can conditionally render the menu link [1]], [2]], [3]], [4]], [5]], [6]], [7]], [8]], [9]], [10]]).
Frontend: Conditional Menu Rendering
Updated _navbar.html and bookfuncs.js to only display the "Peer Instruction (Student)" link if has_peer_assignments is true or not defined [1]], [2]], [3]]).
Template/Configuration
Modified ebook_config.py to add hasPeerAssignments to the eBook config, and skip peer assignment lookups for anonymous users [1]], [2]], [3]]).
Testing
Added new tests for course_has_peer_assignments and for the configuration logic to ensure correct menu visibility and efficient lookups [1]], [2]], [3]]).
Add course_has_peer_assignments(), which checks for any assignment with
is_peer set or kind "Peer", visible or not: an empty peer page beats a
missing link the day an instructor makes one visible.
- ebook_config_override sends hasPeerAssignments (false without a lookup
for logged-out readers); bookfuncs.js drops the menu item only when it
is false, so older servers keep the link.
- _navbar.html hides the item when a route passes
has_peer_assignments=False. Student-facing routes (profile and change
course, problem report, progress, and the shared-template course home,
assignment list and assignment pages) now pass it; instructor pages
keep the link.
RST books keep the link until bookfuncs.js is ported to legacy_support.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The default book-first template fallback omits has_peer_assignments, causing the navbar to show a peer link for courses without peer assignments in the course and student routes.
This PR makes Runestone’s student menus course-aware, hiding “Peer Instruction (Student)” when a course has no peer assignments, including hidden assignments.
Changes:
Adds a database helper that checks both peer-assignment markers.
Passes the result through page contexts and eBook configuration to conditionally render the link, preserving compatibility when the flag is absent.
Adds database and configuration tests, including verification that anonymous readers skip the lookup.
With use_pretext_student_pages on (the default), a book with no
_base.html of its own falls back to the shared one, whose _navbar.html
ignores ebook_config_override. Course home, chooseAssignment and
doAssignment only set has_peer_assignments when the setting was off, so
those pages kept the peer link in courses without peer assignments.
Each route now looks the flag up once, puts it in the template context,
and passes it to ebook_config_override, which takes an optional
has_peer_assignments and only does its own lookup when none is given.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The added route test does not exercise the JavaScript dropdown, leaving peer-link visibility for false, true, and undefined flags without menu-rendering test coverage.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Add dropdown tests for PreTeXt visibility and undefined flags
The added route test uses the shared _base.html fallback, so it never exercises this JavaScript dropdown. The existing bookfuncs tests also do not cover menu rendering, leaving the PreTeXt visibility change and backward-compatible undefined case untested. Please add a Vitest/jsdom test with the dropdown templates that dispatches DOMContentLoaded and checks the peer link is absent for false and present for both true and an undefined flag.
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
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.
Goal is to eliminate distraction (and links to current accessibility issues) for courses not making use of Peer Instruction by only presenting that link to students in the user menu when the course has at least one peer instruction assignment.
This pull request introduces a new utility function,
course_has_peer_assignments, and updates both backend and frontend logic to show the "Peer Instruction (Student)" menu link only for courses that have at least one peer instruction assignment (regardless of visibility). The changes ensure that users see a relevant menu, improve performance by skipping unnecessary lookups for anonymous users, and add comprehensive tests to verify the new logic.Backend: Peer Assignment Detection and Context Propagation
course_has_peer_assignmentsto the database layer to detect if a course has any peer instruction assignments, using efficient SQL queries that check both theis_peerflag andkind == "Peer"[1]], [2]], [3]]).auth.py,problem_report.py,student.py,course.py) to includehas_peer_assignmentsin the context passed to templates, ensuring that the information is available for rendering menus [1]], [2]], [3]], [4]], [5]], [6]], [7]], [8]], [9]], [10]]).Frontend: Conditional Menu Rendering
_navbar.html) and JavaScript (bookfuncs.js) to only show the "Peer Instruction (Student)" link ifhas_peer_assignmentsis true or undefined (for backward compatibility with older servers) [1]], [2]], [3]]).Template and Configuration Updates
ebook_config.pyto includehasPeerAssignmentsin the configuration, and optimized the logic to skip peer assignment lookups for anonymous users, improving performance [1]], [2]], [3]]).Testing
course_has_peer_assignmentsand for the new configuration logic, ensuring correct behavior for courses with and without peer assignments, and for both anonymous and logged-in users [1]], [2]], [3]]).Backend: Peer Assignment Detection
course_has_peer_assignmentsto the database access layer, efficiently checking for peer instruction assignments using SQLAlchemy'sexists[1]], [2]], [3]]).has_peer_assignmentsin their template contexts, so the frontend can conditionally render the menu link [1]], [2]], [3]], [4]], [5]], [6]], [7]], [8]], [9]], [10]]).Frontend: Conditional Menu Rendering
_navbar.htmlandbookfuncs.jsto only display the "Peer Instruction (Student)" link ifhas_peer_assignmentsis true or not defined [1]], [2]], [3]]).Template/Configuration
ebook_config.pyto addhasPeerAssignmentsto the eBook config, and skip peer assignment lookups for anonymous users [1]], [2]], [3]]).Testing
course_has_peer_assignmentsand for the configuration logic to ensure correct menu visibility and efficient lookups [1]], [2]], [3]]).