-
Notifications
You must be signed in to change notification settings - Fork 75
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
Classifier: Remove the faulty session id code #7233
Conversation
try | ||
storage.setItem('session_id', JSON.stringify(stored)) | ||
stored | ||
|
||
getSessionID = () -> | ||
{id, ttl} = JSON.parse(storage.getItem('session_id')) ? generateSessionID() | ||
if ttl < Date.now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition was comparing a Date() string to a Date.now() number and therefore never met. It was copied directly from PFE's codebase, so I'll be doing the same cleanup over there.
@@ -1,29 +1,17 @@ | |||
storage = window.sessionStorage ? window.localStorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature is supposed to be a session id, which refreshes just like a browser session. If researchers are using session ids to analyze anonymous users, then don't use localStorage as a backup.
See https://github.com/zooniverse/front-end-monorepo/pull/6499/files#r1861103668
@shaunanoordin I'm requesting your review on this one as a pair to zooniverse/front-end-monorepo#6499. I've done my best educated guess about coffeescript, but need a second set of eyes on the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Review
Related: FEM PR 6499
This PR removes some code in our session ID-generating function. The removed portion was never working, so no actual changes in website behaviour are expected.
Behaviour:
- a session ID (for a browser tab/window) is generated when any PFE page loads.
- this session ID stays for the duration of the browser session (i.e. until the tab/window closes)
- this session ID is only used when submitting classifications (i.e. on a project's Classify page). The session ID is submitted as
classification.metadata.session = "some_string"
Note:
- in theory it was possible for the generated session ID to be stored/pulled from the longer-term local storage instead of short-term session storage, but in practice this should never have realistically happened. (i.e. unlikely we need to worry about a browser with no session storage, but with local storage.) Nonetheless, the removal of the "window.localStorage" fallback is desirable to keep the code intent clear: session IDs should only live in the session.
The code changes look good, and I see no particular issues with the new Coffeescript. Functionality/behaviour tests also look good.
Testing
Tested on localhost with macOS + Chrome, on an incognito window.
- Load a random PFE page, e.g. https://local.zooniverse.org:3735/projects/
- Confirm that a session ID (hexadecimal string) is generated in the session storage, in the format of
session_id = '{ "id": "abcdef1234567890" }'
- Go to a random project, and go to the Classify page, e.g. https://local.zooniverse.org:3735/projects/brooke/i-fancy-cats/classify
- Submit a classification.
- Confirm that the correct session ID is submitted in the /classifications POST payload, as part of
my_submitted_classification.metadata.session
Status
LGTM! 👍
Staging branch URL: https://pr-7233.pfe-preview.zooniverse.org
Paired with zooniverse/front-end-monorepo#6499
Required Manual Testing
Review Checklist
npm ci
and app works as expected?