Skip to content

Commit 959e1ac

Browse files
authored
Updates to PD registration flow (#10777)
* Capture `unqualified` `pda` values * Set `pda` on account before sending email
1 parent c05ccf2 commit 959e1ac

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

openlibrary/plugins/upstream/account.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from collections.abc import Callable, Iterable, Mapping
44
from datetime import datetime
5+
from enum import Enum
56
from math import ceil
67
from typing import TYPE_CHECKING, Any, Final
78
from urllib.parse import urlparse
@@ -360,21 +361,24 @@ def _set_account_cookies(ol_account: OpenLibraryAccount, expires: int | str) ->
360361
)
361362

362363

363-
def _handle_pd_cookies(ol_account: OpenLibraryAccount) -> None:
364+
class PDRequestStatus(Enum):
365+
REQUESTED = 0
366+
EMAILED = 1
367+
368+
369+
def _update_account_for_pd(ol_account: OpenLibraryAccount) -> None:
364370
pda = web.cookies().get("pda")
365-
if pda == "unqualified":
366-
pda = "vtmas_disabilityresources"
367371
ol_account.get_user().save_preferences(
368372
{
369-
"rpd": 1,
373+
"rpd": PDRequestStatus.REQUESTED.value,
370374
"pda": pda,
371375
}
372376
)
373-
web.setcookie("pda", "", expires=1)
374377

375378

376379
def _notify_on_rpd_verification(ol_account, org):
377380
if org:
381+
org = "vtmas_disabilityresources" if org == "unqualified" else org
378382
displayname = web.safestr(ol_account.displayname)
379383
msg = render_template(
380384
"email/account/pd_request", displayname=displayname, org=org
@@ -385,6 +389,15 @@ def _notify_on_rpd_verification(ol_account, org):
385389
subject=msg.subject.strip(),
386390
message=msg,
387391
)
392+
ol_account.get_user().save_preferences(
393+
{
394+
"rpd": PDRequestStatus.EMAILED.value,
395+
}
396+
)
397+
398+
399+
def _expire_pd_cookies():
400+
web.setcookie("pda", "", expires=1)
388401

389402

390403
class account_login_json(delegate.page):
@@ -434,10 +447,11 @@ def POST(self):
434447
_set_account_cookies(ol_account, expires)
435448

436449
if web.cookies().get("pda"):
450+
_update_account_for_pd(ol_account)
437451
_notify_on_rpd_verification(
438452
ol_account, get_pd_org(web.cookies().get("pda"))
439453
)
440-
_handle_pd_cookies(ol_account)
454+
_expire_pd_cookies()
441455

442456
# Fallback to infogami user/pass
443457
else:
@@ -528,10 +542,11 @@ def POST(self):
528542
_set_account_cookies(ol_account, expires)
529543

530544
if web.cookies().get("pda"):
545+
_update_account_for_pd(ol_account)
531546
_notify_on_rpd_verification(
532547
ol_account, get_pd_org(web.cookies().get("pda"))
533548
)
534-
_handle_pd_cookies(ol_account)
549+
_expire_pd_cookies()
535550
add_flash_message(
536551
"info",
537552
_(

0 commit comments

Comments
 (0)