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: new API route to apply status changes after RSVP deadline #288

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a3b5530
added admin/confirm-attendance and tests
Bl20052005 Jan 20, 2024
5f78b30
formatting changes
Bl20052005 Jan 20, 2024
057993c
Update apps/api/src/routers/admin.py
Bl20052005 Jan 20, 2024
0a95580
simplified or logic
Bl20052005 Jan 20, 2024
89ee79a
Merge branch 'main' of https://github.com/HackAtUCI/irvinehacks-site-…
Bl20052005 Jan 20, 2024
732660f
only update now for needed values
Bl20052005 Jan 20, 2024
60cd615
Update apps/api/src/routers/admin.py
Bl20052005 Jan 20, 2024
fd89c48
Update apps/api/src/routers/admin.py
Bl20052005 Jan 20, 2024
8d098ea
Update apps/api/src/routers/admin.py
Bl20052005 Jan 20, 2024
d02388e
Update apps/api/src/routers/admin.py
Bl20052005 Jan 20, 2024
fed9e0f
Update apps/api/src/routers/admin.py
Bl20052005 Jan 20, 2024
627faf2
incomplete testing
Bl20052005 Jan 21, 2024
b46da83
new testing method
Bl20052005 Jan 21, 2024
56d43c3
optimized logic, removed comments
Bl20052005 Jan 21, 2024
f2bd56e
updated typing
Bl20052005 Jan 21, 2024
946f302
updated tests for 3 cases
Bl20052005 Jan 21, 2024
a182b45
test description fix
Bl20052005 Jan 21, 2024
d797660
changed test messages
Bl20052005 Jan 21, 2024
e330935
Merge branch 'main' of https://github.com/HackAtUCI/irvinehacks-site-…
Bl20052005 Jan 21, 2024
de356ae
updated typing to Sequence
Bl20052005 Jan 21, 2024
b766dec
fixed typing for Sequence
Bl20052005 Jan 21, 2024
2b6eb17
combined all tests into one
Bl20052005 Jan 21, 2024
dd1c0f7
pytest refactoring
samderanova Jan 21, 2024
aac96e9
Merge branch '275-create-new-admin-route-to-apply-status-changes-afte…
samderanova Jan 21, 2024
456cf53
reorder test and route
samderanova Jan 21, 2024
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
44 changes: 43 additions & 1 deletion apps/api/src/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,42 @@ async def release_decisions() -> None:
group = [record for record in records if record["decision"] == decision]
if not group:
continue

await asyncio.gather(
*(_process_batch(batch, decision) for batch in batched(group, 100))
)


@router.post(
"/confirm-attendance", dependencies=
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
[Depends(require_role([Role.DIRECTOR]))]
)
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
async def confirm_attendance() -> None:
"""Update applicant status to void or attending based on their current status."""
records = await mongodb_handler.retrieve(
Collection.USERS,
{"role": Role.APPLICANT},
["_id", "status"],
)

for record in records:
_set_confirmations(record)

for cur_status in (Status.ATTENDING, Status.VOID):
group = [record for record in records if record["status"] == cur_status]
await asyncio.gather(
*(_process_status(batch, cur_status) for batch in batched(group, 100))
)
samderanova marked this conversation as resolved.
Show resolved Hide resolved

Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved

async def _process_status(batch: tuple[dict[str, Any], ...], status: Status) -> None:
uids: list[str] = [record["_id"] for record in batch]
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
ok = await mongodb_handler.update(
Collection.USERS, {"_id": {"$in": uids}}, {"status": status}
)
if not ok:
raise RuntimeError("gg wp")

Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved

async def _process_batch(batch: tuple[dict[str, Any], ...], decision: Decision) -> None:
uids: list[str] = [record["_id"] for record in batch]
log.info(f"Setting {','.join(uids)} as {decision}")
Expand Down Expand Up @@ -165,3 +195,15 @@ def _include_review_decision(applicant_record: dict[str, Any]) -> None:
"""Sets the applicant's decision as the last submitted review decision or None."""
reviews = applicant_record["application_data"]["reviews"]
applicant_record["decision"] = reviews[-1][2] if reviews else None


def _set_confirmations(applicant_record: dict[str, Any]) -> None:
"""Sets the applicant's status based on their RSVP status"""

status = applicant_record["status"]
if status == Status.CONFIRMED:
applicant_record["status"] = Status.ATTENDING
elif status == Status.WAIVER_SIGNED:
applicant_record["status"] = Status.VOID
elif status == Decision.ACCEPTED:
applicant_record["status"] = Status.VOID
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions apps/api/src/utils/user_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Status(str, Enum):
REVIEWED = "REVIEWED"
WAIVER_SIGNED = "WAIVER_SIGNED"
CONFIRMED = "CONFIRMED"
ATTENDING = "ATTENDING"
VOID = "VOID"


class UserRecord(BaseRecord):
Expand Down
36 changes: 36 additions & 0 deletions apps/api/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,42 @@ def test_no_decision_from_no_reviews() -> None:
assert record["decision"] is None


def test_confirm_attendance_when_status_confirmed() -> None:
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
"""Test that a decision is None for an applicant with no reviews."""
record = {
"_id": "edu.uci.Hey",
"status": "CONFIRMED",
"decision": "ACCEPTED",
}

admin._set_confirmations(record)
assert record["status"] == "ATTENDING"


def test_confirm_attendance_when_status_accepted() -> None:
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
"""Test that a decision is None for an applicant with no reviews."""
record = {
"_id": "edu.uci.Vsauce",
"status": "ACCEPTED",
"decision": "ACCEPTED",
}

admin._set_confirmations(record)
assert record["status"] == "VOID"

Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved

def test_confirm_attendance_when_status_waiver_signed() -> None:
Bl20052005 marked this conversation as resolved.
Show resolved Hide resolved
"""Test that a decision is None for an applicant with no reviews."""
record = {
"_id": "edu.uci.Michael",
"status": "WAIVER_SIGNED",
"decision": "ACCEPTED",
}

admin._set_confirmations(record)
assert record["status"] == "VOID"


@patch("services.mongodb_handler.raw_update_one", autospec=True)
@patch("services.mongodb_handler.retrieve_one", autospec=True)
def test_can_submit_review(
Expand Down