Skip to content

Commit

Permalink
feat: add update attending route for non-hackers
Browse files Browse the repository at this point in the history
  • Loading branch information
njhuey committed Jan 26, 2024
1 parent 3568acb commit 699764d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/api/src/admin/participant_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
16 changes: 16 additions & 0 deletions apps/api/src/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 699764d

Please sign in to comment.