Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scc 4405/hold pages js disabled #429

Open
wants to merge 17 commits into
base: hold-pages
Choose a base branch
from

Conversation

dgcohen
Copy link
Contributor

@dgcohen dgcohen commented Jan 2, 2025

Ticket:

This PR does the following:

  • Adds server-side validation on EDD hold requests
  • Fixes bugs causing errors on No-js hold requests (related to JSON parsing/query string formatting)
  • Adds formState and validatedFields query params to populate field values/validation state on refreshes/js-disabled redirects.
  • Renames initialEDDInvalidFields to defaultValidatedEDDFields

How has this been tested?

  • Added unit tests

Accessibility concerns or updates

  • I thought about adding autofocus when js is disabled but it ended up adding a bunch of code, so not sure if it's worth it. Let me know if you think this is important (will check with Clare as well) and I'll add it back.

Checklist:

  • I updated the CHANGELOG with the appropriate information and JIRA ticket number (if applicable).
  • I have added relevant accessibility documentation for this pull request.
  • All new and existing tests passed.

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
research-catalog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 6:59pm

@dgcohen dgcohen changed the base branch from main to hold-pages January 2, 2025 15:59
Copy link
Member

@EdwinGuzman EdwinGuzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works very well. I left a comment about the general architecture but some questions:

  • shouldn't the query params be escaped?
  • it feels a bit unsafe having the patron's email in the query params. I don't think there's anything that can be done.
  • What if a value like requestNotes is very long? Thankfully, I think the limit is big so there's no need to worry but something to keep in mind.

example: validatedFields=[{"key":"emailAddress","isInvalid":false},{"key":"startPage","isInvalid":true},{"key":"endPage","isInvalid":true},{"key":"chapterTitle","isInvalid":true}]&formState={"source":"sierra-nypl","emailAddress":"[email protected]","startPage":"","endPage":"","chapterTitle":"","author":"","date":"","volume":"","issue":"","requestNotes":""}

const { id } = params
const { formInvalid } = query
const serverValidationFailed = formInvalid ? JSON.parse(formInvalid) : false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to pass the formInvalid object to the component so you can then remove the router.query?.formState call? The values are already being parsed in the server so it doesn't seem necessary to do it again in the client.

Copy link
Contributor Author

@dgcohen dgcohen Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The router.query?.formState call is responsible for pre-populating the form fields, whereas the formInvalid query param is just responsible for setting the page's status. I could derive the "invalid" status using the form's state, but it would require some weird changes to the component (moving the error status setting from the submit handler to a useEffect), and I felt that this was cleaner since there was already a switch statement in getServerSideProps that sets the page status before the component renders.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just cause you mentioned there being a lot happening in the getServerSideProps, maybe the email fetch can be moved to the server/api/hold file with the other fetchers

@dgcohen
Copy link
Contributor Author

dgcohen commented Jan 3, 2025

This works very well. I left a comment about the general architecture but some questions:

  • shouldn't the query params be escaped?
  • it feels a bit unsafe having the patron's email in the query params. I don't think there's anything that can be done.
  • What if a value like requestNotes is very long? Thankfully, I think the limit is big so there's no need to worry but something to keep in mind.

example: validatedFields=[{"key":"emailAddress","isInvalid":false},{"key":"startPage","isInvalid":true},{"key":"endPage","isInvalid":true},{"key":"chapterTitle","isInvalid":true}]&formState={"source":"sierra-nypl","emailAddress":"[email protected]","startPage":"","endPage":"","chapterTitle":"","author":"","date":"","volume":"","issue":"","requestNotes":""}

The query params should definitely be escaped. I'm seeing them escaped in chrome's address bar (same as in the unit test), where are you seeing them unescaped?

Not sure if I understand the security concern about the email address in the url. Wouldn't the patron who submitted the form be the only one who sees the redirect url (not including NYPL staff)?

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