Skip to content

Hide Peer Instruction (Student) menu option in courses without peer assignments - #1705

Merged
bnmnetp merged 2 commits into
RunestoneInteractive:mainfrom
ascholerChemeketa:hide-peer-when-not-in-course
Nov 25, 2026
Merged

bnmnetp merged 2 commits into
RunestoneInteractive:mainfrom
ascholerChemeketa:hide-peer-when-not-in-course

Conversation

@ascholerChemeketa

Copy link
Copy Markdown
Contributor

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>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue
What changed in this PR

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.
File Description
test/​components/​rsptx/​templates/​test_ebook_config.py Tests flag propagation and anonymous lookup skipping.
test/​components/​rsptx/​db/​test_course_has_peer_assignments.py Tests peer detection, hidden assignments, and unknown courses.
components/​rsptx/​templates/​ebook_config.py Adds the peer-assignment flag for logged-in readers.
components/​rsptx/​templates/​_navbar.html Conditionally renders the student peer link.
components/​rsptx/​db/​crud/​assignment.py Adds the peer-assignment existence query.
components/​rsptx/​db/​crud/​__init__.py Exports the new helper.
bases/​rsptx/​interactives/​runestone/​common/​js/​bookfuncs.js Gates the book menu link on eBook configuration.
bases/​rsptx/​book_server_api/​routers/​course.py Adds the flag to the shared course-page context.
bases/​rsptx/​assignment_server_api/​routers/​student.py Adds the flag to student assignment and progress contexts.
bases/​rsptx/​admin_server_api/​routers/​problem_report.py Adds the flag to problem-report page context.
bases/​rsptx/​admin_server_api/​routers/​auth.py Adds the flag to authentication-page navbar context.

Review effort: Balanced

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>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Low severity Add dropdown tests for PreTeXt visibility and undefined flags

bases/​rsptx/​interactives/​runestone/​common/​js/​bookfuncs.js:1692

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.

1 resolved since last review

Review effort: Balanced

@bnmnetp

bnmnetp commented Nov 25, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@bnmnetp
bnmnetp merged commit dfaf3ec into RunestoneInteractive:main Nov 25, 2026
2 checks passed
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.

3 participants