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

feat: add confirm attendance route for non-hackers #362

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading