|
1 | 1 | import logging |
2 | 2 | import uuid |
3 | 3 | from datetime import UTC, date, datetime |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | from fastapi import Depends, File, HTTPException, UploadFile |
6 | 7 | from fastapi.responses import FileResponse |
@@ -1130,12 +1131,6 @@ async def get_payment_url( |
1130 | 1131 | if not participant: |
1131 | 1132 | raise HTTPException(status_code=404, detail="Participant not found.") |
1132 | 1133 |
|
1133 | | - if participant.validation_progress != 100: |
1134 | | - raise HTTPException( |
1135 | | - status_code=400, |
1136 | | - detail="You must complete your registration before paying.", |
1137 | | - ) |
1138 | | - |
1139 | 1134 | if not participant.payment: |
1140 | 1135 | if ( |
1141 | 1136 | participant.student_card is not None |
@@ -1177,3 +1172,63 @@ async def get_payment_url( |
1177 | 1172 | return schemas_raid.PaymentUrl( |
1178 | 1173 | url=checkout.payment_url, |
1179 | 1174 | ) |
| 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 | + ) |
0 commit comments