Skip to content

9409/feat/preserve patron intent - #12764

Merged
mekarpeles merged 23 commits into
internetarchive:masterfrom
Sadashii:9409/feat/preserve-patron-intent
May 31, 2026
Merged

9409/feat/preserve patron intent#12764
mekarpeles merged 23 commits into
internetarchive:masterfrom
Sadashii:9409/feat/preserve-patron-intent

Conversation

@Sadashii

Copy link
Copy Markdown
Collaborator

Closes #9409

[feature]

This PR introduces an Authentication Action Persistence mechanism across Open Library. It standardizes the workflow for unauthenticated users when they interact with protected features (such as Rating, Borrowing, Adding to lists, Joining Waitlist, or Following). Instead of losing their context after being redirected to the login page, their intent (Action, Book Name, and URL) is stored securely in a cookie. After a successful login, a dynamic banner prompts them to automatically resume their pending action, providing a seamless user experience.

Technical

  • Intent Capture & Tracking: Integrated data-login-action, data-login-book, and data-login-url data attributes across various interactive components (macros/Follow.html, macros/LoanStatus.html, macros/ReadButton.html, macros/StarRatings.html, modal_links.html, and My Books droppers).
  • Global Event Handler: Added global JavaScript logic (openlibrary/plugins/openlibrary/js/index.js and utils.js) that intercepts clicks on these protected elements when unauthenticated, serializes the action context into a cookie, and routes the user to the login page.
  • State Restoration & Banner: Enhanced templates/account/view.html and templates/site/banner.html to read the intent cookie post-login and render a "Resume Action" banner.
  • Backend Context: Updated mybooks.py and utils.py to parse the intent cookie and provide the context variables to the frontend.
  • Styling: Refactored mybooks-details.css to strictly use semantic CSS tokens from the design system for the pending action banner, rather than hard-coded HSL values, ensuring consistency across light/dark themes.

Testing

  1. In an unauthenticated session (logged out), navigate to a Work or Edition page.
  2. Click on a protected action, such as a star rating, "Want to Read", "Borrow", "Join Waitlist", or "Follow".
  3. Verify that you are redirected to the login screen.
  4. REMOVE the redirect from the url - it is there for logins to resume, signups will occur from a different page where this redirect generally gets lost.
  5. Log in using a test account.
  6. Verify that you see a "Pending Action" banner (e.g., prompting you to resume adding the book to your list or completing your rating).
  7. Click the banner's primary action button and verify the queued action successfully executes and resumes your original intent.

Screenshot

image *(Please attach screenshots or a GIF demonstrating the unauthenticated click -> login -> banner resume flow here)*

Stakeholders

@mekarpeles

(Please tag the issue lead or relevant maintainers here)

Sadashii added 6 commits May 18, 2026 23:08
Adds global Javascript handlers, cookie management, and template logic to capture unauthenticated user intent and auto-resume it after login via a banner.
Applies intent tracking to modal links and star ratings. Intercepts star rating actions for logged out users to navigate to the login page.
Injects intent persistence attributes into the primary action button for reading logs in the My Books dropper.
Updates Follow, Borrow, and Join Waitlist buttons to capture unauthenticated user intent, prompting the action to automatically resume after login.
Refactors pending action banner to strictly use semantic CSS tokens from the design system rather than hard-coding HSL values, ensuring consistency across themes.
Copilot AI review requested due to automatic review settings May 18, 2026 18:03
@github-actions github-actions Bot added the Priority: 2 Important, as time permits. [managed] label May 18, 2026
@mekarpeles mekarpeles added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label May 18, 2026
@mekarpeles

Copy link
Copy Markdown
Member

Thanks for this pull request, @Sadashii.

πŸ€– Copilot has been assigned for an initial review.

The linked issue #9409 has been triaged (Priority 2) but does not yet have an assignee. A reviewer must first be assigned. There are currently 16 open PRs of equal or higher priority ahead of yours.

Possible improvements for this PR

  • No test files were detected. The PR adds new backend logic to mybooks.py and utils.py β€” consider adding automated tests for the new functions to help maintainers verify correctness during review.
PR triage checklist (maintainers / Pam)
  • PR description β€” not empty; explains what the change does and how to verify it
  • References an issue β€” PR body contains a #NNN reference
    • Linked issue is triaged β€” has a Priority: * label (not just Needs: Triage)
    • Linked issue is assigned β€” has at least one assignee
  • Commit history clean β€” no WIP/fixup/conflict noise; commit messages are meaningful
  • CI passing β€” no failing check-runs
  • Test cases present β€” if the change touches substantive logic, test coverage exists or is explained
  • Proof of testing β€” PR body includes a description of what was tested, a screenshot, or a video

Note

This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.

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

This PR adds a login-intent persistence flow so unauthenticated patrons can resume protected actions after authenticating.

Changes:

  • Adds intent metadata to several protected UI controls and queues pending actions in a cookie.
  • Adds post-login banner rendering/parsing for pending actions.
  • Adds styling and i18n strings for the pending-action banner.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
static/css/components/mybooks-details.css Styles the pending-action banner.
openlibrary/templates/type/edition/modal_links.html Adds intent metadata to review/notes modal links.
openlibrary/templates/site/banner.html Adjusts dismissible banner cookie display logic.
openlibrary/templates/my_books/primary_action.html Adds intent metadata to My Books primary/list actions.
openlibrary/templates/my_books/dropper.html Passes book title into primary action rendering.
openlibrary/templates/account/view.html Renders pending-action banner on account pages.
openlibrary/plugins/upstream/utils.py Adds helper for intent data attributes.
openlibrary/plugins/upstream/mybooks.py Parses pending-action cookie and builds banner HTML.
openlibrary/plugins/openlibrary/js/utils.js Adds cookie queueing helper.
openlibrary/plugins/openlibrary/js/star-ratings/index.js Redirects unauthenticated rating submissions to login.
openlibrary/plugins/openlibrary/js/index.js Adds global intent click handler and auto-resume logic.
openlibrary/macros/StarRatings.html Adds intent metadata to star rating labels.
openlibrary/macros/ReadButton.html Adds intent metadata for unauthenticated borrow buttons.
openlibrary/macros/LoanStatus.html Passes book title into loan actions and annotates waitlist.
openlibrary/macros/Follow.html Adds intent metadata to follow controls.
openlibrary/i18n/messages.pot Adds extracted strings for new intent/banner text.

Comment thread openlibrary/macros/LoanStatus.html Outdated
Comment thread openlibrary/plugins/upstream/mybooks.py
Comment thread openlibrary/plugins/upstream/mybooks.py
Comment thread openlibrary/templates/account/view.html
Comment thread openlibrary/plugins/openlibrary/js/index.js Outdated
Comment thread openlibrary/macros/Follow.html
Comment thread openlibrary/templates/my_books/primary_action.html Outdated
Comment thread openlibrary/macros/ReadButton.html Outdated
Comment thread openlibrary/macros/LoanStatus.html Outdated
Comment thread openlibrary/plugins/openlibrary/js/star-ratings/index.js
@github-actions github-actions Bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label May 19, 2026
@Sadashii
Sadashii requested a review from Copilot May 19, 2026 06:16

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

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Comment thread openlibrary/plugins/openlibrary/js/star-ratings/index.js Outdated
Comment thread openlibrary/plugins/openlibrary/js/index.js Outdated
Comment thread openlibrary/plugins/openlibrary/js/utils.js
Sadashii and others added 4 commits May 19, 2026 11:57
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…i/openlibrary into 9409/feat/preserve-patron-intent
…ction test

primary_action.html: logged-out users had data-action="Add to List" but after
login the same button renders as data-action="Want to Read". The resume script
matches by data-action, so the intent was never found. Use "Want to Read" as
the stable key in both states so the post-login resume click works.

utils.test.js: the URL-encoding test had a copy-paste bug β€” expectedData had
name: 'Dune' and type: 'book' that didn't match the actual queueAction call
args, causing the test to always fail.
@mekarpeles mekarpeles added this to the Sprint 2026-05 milestone May 21, 2026
Comment thread openlibrary/plugins/openlibrary/js/index.js
Comment thread openlibrary/plugins/upstream/mybooks.py Outdated
Comment thread openlibrary/i18n/messages.pot Outdated
Comment thread openlibrary/templates/type/edition/modal_links.html Outdated
Comment thread openlibrary/i18n/messages.pot Outdated
Comment thread openlibrary/i18n/messages.pot Outdated
Comment thread openlibrary/i18n/messages.pot Outdated
mekarpeles and others added 4 commits May 24, 2026 22:48
…, remove auto-click

- Banner message: 'You were trying to ... Click the link to resume.' β†’
  'Continue <action> the <type> <name>.' (consistent imperative phrasing)
- Star rating actions: 'Rate N star(s)' β†’ 'leaving a N star review for'
  (gerund form fits 'Continue <action> the book <title>.' template);
  also move title+actions outside the loop (computed once per render)
- modal_links.html: 'Add a review' β†’ 'reviewing', 'Add a note' β†’ 'adding notes to'
- Remove auto-click DOMContentLoaded handler and __modalsLoaded flag;
  the banner link is sufficient for resuming intent post-login
- Simplify account/view.html: remove sessionStorage.setItem (dead code
  without the auto-click); clean up cookie-clear on banner link click
@Sadashii

Copy link
Copy Markdown
Collaborator Author

@mekarpeles With the latest changes, if we hardcode 'book' it will give an incorrect message if the patron action was follow an author, as it will say 'follow the book (authorname)'. The page_type var dealt with this quirk.

@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label May 27, 2026
…e-patron-intent

# Conflicts:
#	openlibrary/plugins/upstream/utils.py
@Sadashii

Sadashii commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Preserve Patron Intent is added to 7 actions on the platform, all tested and working

  1. Review
  2. Follow x (patron account)
  3. Star Rating Actions
  4. Notes button
  5. Add to List - I think wording needs some thought
image
  1. Join Waitlit - "Continue Join Waitlist (bookname)" wording thought?
  2. Borrow - "Continue Borrow (bookname)"

@Sadashii

Copy link
Copy Markdown
Collaborator Author

Final UI:
image

@mekarpeles
mekarpeles merged commit c6e1f45 into internetarchive:master May 31, 2026
4 of 5 checks passed
@mekarpeles

Copy link
Copy Markdown
Member

Worth noting that clicking "continue to give 4 star review for ..." doesn't actually perform the star rating. This is something we may want to improve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead Priority: 2 Important, as time permits. [managed]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save/preserve patron's registration action post-registration

3 participants