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

Fix login json SFW #7935

Merged
merged 1 commit into from
Jun 6, 2023
Merged

Fix login json SFW #7935

merged 1 commit into from
Jun 6, 2023

Conversation

mekarpeles
Copy link
Member

@mekarpeles mekarpeles commented Jun 5, 2023

Fixes a case where for login json endpoint ol_account was being fetched using an empty email as opposed to the email matched by the audit.

image

fix json login sfw
@mekarpeles mekarpeles added Priority: 1 Do this week, receiving emails, time sensitive, . [managed] Patch Deployed This PR has been deployed to production independently, outside of the regular deploy cycle. On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing labels Jun 5, 2023
Comment on lines +339 to +342
if audit.get('ia_email'):
ol_account = OpenLibraryAccount.get(email=audit['ia_email'])
if ol_account and ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
Copy link
Contributor

Choose a reason for hiding this comment

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

Get ia_email once, not twice...

Suggested change
if audit.get('ia_email'):
ol_account = OpenLibraryAccount.get(email=audit['ia_email'])
if ol_account and ol_account.get_user().get_safe_mode() == 'yes':
web.setcookie('sfw', 'yes', expires=expires)
if (
ia_email := audit.get('ia_email')
and ol_account := OpenLibraryAccount.get(email=ia_email)
and ol_account.get_user().get_safe_mode() == 'yes'
):
web.setcookie('sfw', 'yes', expires=expires)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure in this code ia_email will be undefined within the if statement.
Screenshot 2023-06-06 at 11 41 33 AM

Copy link
Contributor

Choose a reason for hiding this comment

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

Today I Learned: You need an extra sent of parens around the ia_email := audit.get('ia_email') bit just to make it work properly! Thanks @mekarpeles

@mekarpeles mekarpeles merged commit 6dd899c into master Jun 6, 2023
@cclauss cclauss deleted the fix-json-login branch June 6, 2023 20:12
@jimchamp jimchamp removed the On testing.openlibrary.org This PR has been deployed to testing.openlibrary.org for testing label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Patch Deployed This PR has been deployed to production independently, outside of the regular deploy cycle. Priority: 1 Do this week, receiving emails, time sensitive, . [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants