From 699764d19e0f585c450499cf0d887368ff1ee608 Mon Sep 17 00:00:00 2001 From: Nathan Huey Date: Thu, 25 Jan 2024 23:54:47 -0800 Subject: [PATCH] feat: add update attending route for non-hackers --- apps/api/src/admin/participant_manager.py | 30 +++++++++++++++++++++++ apps/api/src/routers/admin.py | 16 ++++++++++++ 2 files changed, 46 insertions(+) diff --git a/apps/api/src/admin/participant_manager.py b/apps/api/src/admin/participant_manager.py index 354aefe9..c0df12cf 100644 --- a/apps/api/src/admin/participant_manager.py +++ b/apps/api/src/admin/participant_manager.py @@ -68,3 +68,33 @@ async def check_in_applicant(uid: str, associate: User) -> None: raise RuntimeError(f"Could not update check-in record for {uid}.") log.info(f"Applicant {uid} checked in by {associate.uid}") + + +async def confirm_attendance_non_hacker(uid: str, director: User) -> None: + """Update status for Role.Attending for non-hackers.""" + allowed_roles = ( + Role.MENTOR, + Role.ORGANIZER, + Role.VOLUNTEER, + Role.SPONSOR, + Role.JUDGE, + Role.WORKSHOP_LEAD, + ) + + record: Optional[dict[str, object]] = await mongodb_handler.retrieve_one( + Collection.USERS, {"_id": uid, "status": Status.WAIVER_SIGNED} + ) + + if not record or record["role"] not in allowed_roles: + raise ValueError + + update_status = await mongodb_handler.raw_update_one( + Collection.USERS, + {"_id": uid}, + {"status": Status.ATTENDING}, + ) + + if not update_status: + raise RuntimeError(f"Could not update status to ATTENDING for {uid}.") + + log.info(f"Non-hacker {uid} status updated to attending by {director.uid}") diff --git a/apps/api/src/routers/admin.py b/apps/api/src/routers/admin.py index e8b81be5..01f4bef5 100644 --- a/apps/api/src/routers/admin.py +++ b/apps/api/src/routers/admin.py @@ -267,6 +267,22 @@ async def checkin( raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR) +@router.post( + "/update-attendance/{uid}", +) +async def update_attendance( + uid: str, director: Annotated[User, Depends(require_role([Role.DIRECTOR]))] +) -> None: + """Update status to Role.ATTENDING for non-hackers.""" + try: + await participant_manager.confirm_attendance_non_hacker(uid, director) + except ValueError: + raise HTTPException(status.HTTP_404_NOT_FOUND) + except RuntimeError as err: + log.exception("While updating participant attendance: %s", err) + raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR) + + async def _process_status(uids: Sequence[str], status: Status) -> None: ok = await mongodb_handler.update( Collection.USERS, {"_id": {"$in": uids}}, {"status": status}