Skip to content

Commit eb5d1c8

Browse files
Raid fixups (#828)
### Description Please explain the changes you made here. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] All tests passing - [ ] Extended the documentation, if necessary
1 parent 5a7b72a commit eb5d1c8

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

app/modules/raid/cruds_raid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ async def create_document(
304304

305305
async def assign_document(
306306
participant_id: str,
307-
document_id: str,
307+
document_id: str | None,
308308
document_key: str,
309309
db: AsyncSession,
310310
) -> None:

app/modules/raid/endpoints_raid.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import uuid
33
from datetime import UTC, date, datetime
4+
from pathlib import Path
45

56
from fastapi import Depends, File, HTTPException, UploadFile
67
from fastapi.responses import FileResponse
@@ -1130,12 +1131,6 @@ async def get_payment_url(
11301131
if not participant:
11311132
raise HTTPException(status_code=404, detail="Participant not found.")
11321133

1133-
if participant.validation_progress != 100:
1134-
raise HTTPException(
1135-
status_code=400,
1136-
detail="You must complete your registration before paying.",
1137-
)
1138-
11391134
if not participant.payment:
11401135
if (
11411136
participant.student_card is not None
@@ -1177,3 +1172,63 @@ async def get_payment_url(
11771172
return schemas_raid.PaymentUrl(
11781173
url=checkout.payment_url,
11791174
)
1175+
1176+
1177+
@module.router.post(
1178+
"/raid/clear_documents",
1179+
status_code=204,
1180+
)
1181+
async def clear_documents(
1182+
db: AsyncSession = Depends(get_db),
1183+
user: models_users.CoreUser = Depends(is_user_in(GroupType.raid_admin)),
1184+
):
1185+
"""
1186+
For each participant, for all their document, check if this document exists, if not, clear the document from the participant
1187+
"""
1188+
1189+
raid_data_path = Path("data/raid")
1190+
existing_file_ids = set()
1191+
1192+
if raid_data_path.exists():
1193+
for file_path in raid_data_path.glob("*.*"):
1194+
if file_path.is_file():
1195+
existing_file_ids.add(file_path.stem)
1196+
1197+
hyperion_error_logger.info(
1198+
f"RAID: Found {len(existing_file_ids)} existing files",
1199+
)
1200+
1201+
participants = await cruds_raid.get_all_participants(db)
1202+
cleared_documents_count = 0
1203+
checked_documents_count = 0
1204+
1205+
for participant in participants:
1206+
if not participant:
1207+
continue
1208+
documents = {
1209+
"id_card_id": participant.id_card_id,
1210+
"medical_certificate_id": participant.medical_certificate_id,
1211+
"student_card_id": participant.student_card_id,
1212+
"raid_rules_id": participant.raid_rules_id,
1213+
"parent_authorization_id": participant.parent_authorization_id,
1214+
}
1215+
for document_key, document_id in documents.items():
1216+
if document_id:
1217+
checked_documents_count += 1
1218+
1219+
file_exists = document_id in existing_file_ids
1220+
1221+
if not file_exists:
1222+
await cruds_raid.assign_document(
1223+
participant.id,
1224+
None,
1225+
document_key,
1226+
db,
1227+
)
1228+
cleared_documents_count += 1
1229+
1230+
hyperion_error_logger.info(
1231+
f"RAID: Document cleanup completed. "
1232+
f"Checked {checked_documents_count} document references, "
1233+
f"cleared {cleared_documents_count} invalid ones.",
1234+
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [{ name = "AEECL ECLAIR" }]
66

77
# Hyperion follows Semantic Versioning
88
# https://semver.org/
9-
version = "4.7.8"
9+
version = "4.7.9"
1010
minimal-titan-version-code = 139
1111
requires-python = ">= 3.11, < 3.13"
1212

0 commit comments

Comments
 (0)