Skip to content

Supply eBookConfig values from the server via ebook_config_override (#1392) - #1626

Open
bnmnetp wants to merge 1 commit into
mainfrom
ebook-config-override
Open

bnmnetp wants to merge 1 commit into
mainfrom
ebook-config-override

Conversation

@bnmnetp

@bnmnetp bnmnetp commented Oct 21, 2026

Copy link
Copy Markdown
Member

Part of #1392: moves responsibility for the Runestone-specific eBookConfig values from the PreTeXt template to the server.

How it works

PreTeXt 2.56 emits {{ ebook_config_override | safe }} after its own eBookConfig assignments. The server fills that with ebook_config_override = {...}, and bookfuncs.js merges it into eBookConfig (Object.assign) when the module loads, before anything else reads it. Values the override doesn't name, such as enableScratchAC, acDefaultLanguage and runestone_version, keep the book's value.

What the server sends

The green items in #1392: useRunestoneServices, course, termStartDate, basecourse, isLoggedIn, email, isInstructor, logLevel, username, readings, activities, downloadsEnabled, allow_pairs, course_attrs, plus isAuthor and isEditor. These are real JSON booleans, not "true"/"false" strings.

enableScratchAC and acDefaultLanguage are also green in the issue, but they're publisher options with no server-side source, so the book keeps them.

Where

  • A shared helper, rsptx.templates.ebook_config.ebook_config_override(), builds the object.
    • It uses htmlsafe_json_dumps, so a course attribute containing </script> can't break out of the script tag.
    • It only runs the author/editor group lookups for instructors, since those links only appear in the instructor menu.
  • Book pages (serve_page) always send it; useRunestoneServices is false in ?mode=browsing.
  • The course home page, chooseAssignment and doAssignment send it only when use_pretext_student_pages is on, since their PreTeXt _base.html is the one that emits the marker. As a side effect these pages now get the real username and email, which used to be empty on some of them.

Also

  • is_author returns False when the DB has no author group, like is_editor already does. Without this, instructor page views would crash on such installs.
  • The Editor Dashboard link goes to /admin/editor/manage_exercises (overridable with eBookConfig.editorServerUrl) instead of the author dashboard.
  • uv.lock bumps pretext from 2.55.0 to 2.56.0, the version that emits the marker.

Testing

  • New tests: bookfuncs_config_override.test.js (vitest) and test/components/rsptx/templates/test_ebook_config.py.
  • The full vitest suite passes, and the templates, book and assignment pytest suites pass (301).
  • Manually checked in Chromium against PTXSB, both logged in and anonymous: book page, course home, chooseAssignment and doAssignment all have the merged values and no page errors. With use_pretext_student_pages=false, the three student pages have no override.

RST books are unaffected: their template doesn't emit the marker, and their JS ships from legacy_support.

🤖 Generated with Claude Code

…1392)

PreTeXt 2.56 emits {{ ebook_config_override | safe }} after its own
eBookConfig assignments. The server now fills it with the values only a
Runestone server can know (the green items in #1392, plus isAuthor and
isEditor), and bookfuncs.js merges it into eBookConfig before anything
reads it, so the server rather than the book's template is the authority.

- rsptx.templates.ebook_config builds the statement, HTML-safe JSON so a
  course attribute can't close the <script> tag. Author/editor group
  lookups run only for instructors, the only ones shown those links.
- Book pages, the course home page, chooseAssignment and doAssignment
  provide it; the last three only when use_pretext_student_pages is on.
- is_author returns False when no author group exists, like is_editor.
- The Editor Dashboard link goes to the editor page, not the author one.
- Bump pretext to 2.56.0 in uv.lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 19:20

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 course-home override enables a malformed reading tracker when an assignment remains in localStorage.

1 open issue
What changed in this PR

Moves Runestone-specific eBookConfig values to a shared server-generated override, supporting the migration in #1392 while preserving publisher settings.

Changes:

  • Supplies and merges configuration overrides for book and PreTeXt student pages.
  • Handles missing author groups and corrects the Editor Dashboard link.
  • Adds override tests and updates PreTeXt to 2.56.0.
File Description
uv.lock Updates PreTeXt to support the override marker.
test/​components/​rsptx/​templates/​test_ebook_config.py Tests server configuration and safe serialization.
components/​rsptx/​templates/​ebook_config.py Adds the shared configuration helper.
components/​rsptx/​db/​crud/​group.py Handles missing author groups.
bases/​rsptx/​interactives/​runestone/​common/​test/​bookfuncs_config_override.test.js Tests configuration merging.
bases/​rsptx/​interactives/​runestone/​common/​js/​bookfuncs.js Applies overrides and corrects the editor link.
bases/​rsptx/​book_server_api/​routers/​course.py Supplies course-home overrides.
bases/​rsptx/​book_server_api/​routers/​books.py Supplies book-page overrides.
bases/​rsptx/​assignment_server_api/​routers/​student.py Supplies assignment-page overrides.

Review effort: Balanced

user=user,
user_is_instructor=user_is_instructor,
course_attrs=attrs,
readings=[],
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.

2 participants