Skip to content

fix(restacker): refactor and use ProjectContext permissions checks - #909

Open
jakeaturner wants to merge 8 commits into
stagingfrom
fix/restacker-perms
Open

fix(restacker): refactor and use ProjectContext permissions checks#909
jakeaturner wants to merge 8 commits into
stagingfrom
fix/restacker-perms

Conversation

@jakeaturner

Copy link
Copy Markdown
Collaborator

No description provided.

@jakeaturner
jakeaturner requested review from yghaemi and a lite review from Copilot August 13, 2026 20:31

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.

Pull request overview

Refactors project permission and book-attachment checks to use the centralized ProjectContext helper (and its permission checks) across Restacker/BookService/Remixer flows, reducing direct project/user lookups in those endpoints.

Changes:

  • Extend ProjectContext to always load LibreTexts book attachment fields and add helpers to validate/compose a project’s attached bookID.
  • Update BookService.canAccessPage to use ProjectContext for project membership checks.
  • Refactor multiple Restacker endpoints to use ProjectContext + ProjectError-based error handling; minor Remixer cleanup for bookID composition.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
server/api/services/project-context.ts Adds book-attachment fields to permission shape and introduces helpers for attached book ID + validation + new error code.
server/api/services/book-service.ts Replaces ad-hoc user lookup + permission check with ProjectContext.canMember in canAccessPage.
server/api/restacker.ts Refactors Restacker endpoints to ProjectContext permission checks and centralized error handling; adjusts restacker run parameters from attached book.
server/api/remixer.ts Minor refactor to reuse a bookID variable and clarifying comment about when project-book enforcement applies.
Suppressed comments (2)

server/api/services/project-context.ts:151

  • Docstring: the composed book ID is library-coverID (not library-bookID). The current wording is confusing and doesn’t match the actual return value (${libreLibrary}-${libreCoverID}).
     * Returns the book ID attached to the project, or null if no book is attached.
     * @param this The ProjectContext instance.
     * @returns An object containing the library, coverID, and the composed bookID (library-bookID), or null if no book is attached.
     */

server/api/services/project-context.ts:130

  • assertBookBelongsToProject currently treats any string containing a hyphen as parseable (because getLibraryAndPageFromBookID only checks split('-').length > 1). That means values like lib-123-extra are considered valid and will pass if the first two segments match the project’s book, even though they aren’t valid lib-coverID identifiers per checkBookIDFormat.
        // Check that book ID can be parsed into a valid subdomain and path
        const [subdomain, path] = getLibraryAndPageFromBookID(bookID);
        if (!subdomain || !path) {
            debug("[ProjectContext.assertBookBelongsToProject] Invalid bookID format:", bookID);
            return false;
        }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/api/restacker.ts
Comment on lines +626 to +629
const bookService = new BookService({ bookID });

const currentTags = await bookService.getPageTags(pageID);
const preservedTags = currentTags
.map((tag) => tag["@value"])
.filter(
(tag) =>
!tag.startsWith("license:") && !tag.startsWith("licenseversion:"),
const currentTags = await bookService.getPageTags(pageID);
const preservedTags = currentTags
Comment on lines +43 to +45
case "invalidbookid":
message = "Requested book ID is invalid or does not belong to this project";
break;
yghaemi
yghaemi previously approved these changes Aug 14, 2026
@jakeaturner
jakeaturner dismissed yghaemi’s stale review August 17, 2026 17:27

The merge-base changed after approval.

@jakeaturner
jakeaturner force-pushed the staging branch 2 times, most recently from 3068ccf to 78c3f6f Compare August 18, 2026 20:18
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.

4 participants