diff options
| author | stuppie | 2026-09-29 14:55:44 -0600 |
|---|---|---|
| committer | stuppie | 2026-09-29 14:55:44 -0600 |
| commit | 814782db6d829c20279cde00cdc1a7a5ef18b74a (patch) | |
| tree | 403a76095ca3c1f7f6971dff3245319930df5af3 | |
| parent | 5d26a04de9ae188edc45e77d213202b1ce921be9 (diff) | |
| download | amt-jb-814782db6d829c20279cde00cdc1a7a5ef18b74a.tar.gz amt-jb-814782db6d829c20279cde00cdc1a7a5ef18b74a.zip | |
| -rw-r--r-- | jb/managers/email_manager.py | 6 | ||||
| -rw-r--r-- | jb/managers/gr_api.py | 7 | ||||
| -rw-r--r-- | jb/managers/thl.py | 8 | ||||
| -rw-r--r-- | jb/views/auth.py | 20 | ||||
| -rw-r--r-- | jb/views/wallet.py | 6 | ||||
| -rw-r--r-- | requirements.txt | 2 |
6 files changed, 31 insertions, 18 deletions
diff --git a/jb/managers/email_manager.py b/jb/managers/email_manager.py index 59b74d3..8a796e3 100644 --- a/jb/managers/email_manager.py +++ b/jb/managers/email_manager.py @@ -6,7 +6,7 @@ from generalresearch.config import is_debug from generalresearch.currency import USDCent from generalresearch.models.thl.wallet.cashout_method import ( CashoutMethodOut, - CashoutRequestInfo, + CashoutRequestDetail, ) from jb.config import settings @@ -98,7 +98,7 @@ def send_cashout_confirmation_email( def format_cashout_status_email_tokens( - cashout: CashoutRequestInfo, + cashout: CashoutRequestDetail, ) -> dict[str, str]: tx = cashout.transaction_info or {} assert cashout.id is not None @@ -147,7 +147,7 @@ def format_tango_credentials(transaction: dict[str, Any]) -> str: return "".join(rows) -def send_cashout_status_email(email: str, cashout: CashoutRequestInfo) -> None: +def send_cashout_status_email(email: str, cashout: CashoutRequestDetail) -> None: email_tokens = format_cashout_status_email_tokens(cashout) if is_debug(): diff --git a/jb/managers/gr_api.py b/jb/managers/gr_api.py index f0be1a7..164f35a 100644 --- a/jb/managers/gr_api.py +++ b/jb/managers/gr_api.py @@ -90,6 +90,13 @@ class GRApiManager: res = self._request("GET", url).json() return self._parse_user_response(res) + def get_user_if_exists(self, product_user_id: str) -> User | None: + """Retrieve the user's email address and display name.""" + try: + return self.get_user(product_user_id) + except GRApiNotFoundError: + return None + def get_user_by_email(self, email: str) -> User: user = User.model_validate({"email": email}) return self.get_user(user.product_user_id) diff --git a/jb/managers/thl.py b/jb/managers/thl.py index 96f624e..4d29467 100644 --- a/jb/managers/thl.py +++ b/jb/managers/thl.py @@ -6,7 +6,7 @@ from generalresearch.models.thl.payout import UserPayoutEvent from generalresearch.models.thl.task_status import TaskStatusResponse from generalresearch.models.thl.wallet.cashout_method import ( CashoutMethodOut, - CashoutRequestInfo, + CashoutRequestDetail, CashoutRequestResponse, ) @@ -24,7 +24,7 @@ def get_task_status(tsid: str) -> TaskStatusResponse | None: def user_cashout_request( product_user_id: str, amount: USDCent, cashout_method_id: str -) -> CashoutRequestInfo: +) -> CashoutRequestDetail: assert isinstance(amount, USDCent) assert USDCent(0) < amount <= USDCent(100_00) url = f"{settings.fsb_host}{settings.product_id}/cashout/" @@ -123,8 +123,8 @@ def get_wallet_balance_if_non_negative(amt_worker_id: str) -> USDCent | None: return None -def get_cashout_detail(cashout_id: str) -> CashoutRequestInfo: +def get_cashout_detail(cashout_id: str) -> CashoutRequestDetail: url = f"{settings.fsb_host}{settings.product_id}/cashout/{cashout_id}/" res = requests.get(url) assert res.status_code == status.HTTP_200_OK, res.text - return CashoutRequestInfo.model_validate(res.json()["cashout"]) + return CashoutRequestDetail.model_validate(res.json()["cashout"]) diff --git a/jb/views/auth.py b/jb/views/auth.py index ba1a6f8..e6410a6 100644 --- a/jb/views/auth.py +++ b/jb/views/auth.py @@ -86,8 +86,10 @@ def authenticate_invite_amt_account_link( @auth_router.post("/magic-link/request/") def request_magic_link(body: AccountLogin) -> dict[str, str]: - """Create a magic link.""" - email = str(body.email) + return _request_magic_link(str(body.email)) + + +def _request_magic_link(email: str) -> dict[str, str]: token = create_magic_token(user_email=email) if settings.debug: @@ -181,15 +183,19 @@ def _exchange_magic_link( @auth_router.post("/link-amt/request/") -def link_amt_account(body: AmtAccountLink) -> dict[str, str]: +def link_amt_account( + body: AmtAccountLink, + gr_api: Annotated[GRApiManager, Depends(get_gr_api_manager)], +) -> dict[str, str]: """Link an AMT account and login.""" email = str(body.email) amt_worker_id = body.amt_worker_id - # TODO! Prevent a user that's already transitioned their account, from being - # TODO! able to continuously create this special link token. - # TODO! Max Notes: this seems to be handled within the gr-api, and that - # TODO! can raise, the following line would / should fail if needed. + # If the email already has transitioned, treat this as a login request + user = User.model_validate({"email": email}) + user_exists = gr_api.get_user_if_exists(user.product_user_id) + if user_exists: + return _request_magic_link(email) token = create_amt_account_link_token(email=email, amt_worker_id=amt_worker_id) diff --git a/jb/views/wallet.py b/jb/views/wallet.py index 681cc21..de295ac 100644 --- a/jb/views/wallet.py +++ b/jb/views/wallet.py @@ -5,7 +5,7 @@ from urllib.parse import urlencode from fastapi import APIRouter, Depends, HTTPException, status from fastapi.responses import HTMLResponse from generalresearch.models.thl.definitions import PayoutStatus -from generalresearch.models.thl.wallet.cashout_method import CashoutRequestInfo +from generalresearch.models.thl.wallet.cashout_method import CashoutRequestDetail from generalresearch.redis_helper import RedisConfig from jb.api.auth import get_authenticated_user @@ -77,11 +77,11 @@ def cashout_confirmation_page() -> HTMLResponse: ) -@wallet_router.post("/cashout/confirm/", response_model=CashoutRequestInfo) +@wallet_router.post("/cashout/confirm/", response_model=CashoutRequestDetail) def confirm_cashout( body: CashoutConfirmation, user: Annotated[User, Depends(get_authenticated_user)], -) -> CashoutRequestInfo: +) -> CashoutRequestDetail: cashout = consume_cashout_token(body.token) return user_cashout_request( diff --git a/requirements.txt b/requirements.txt index 5bb0fa7..a45c1c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -git+ssh://code.g-r-l.com:6611/generalresearch@v3.6.1 +git+ssh://code.g-r-l.com:6611/generalresearch@v3.6.4 aiohappyeyeballs==2.6.1 aiohttp==3.13.0 aiosignal==1.4.0 |
