Skip to content

Commit 327287c

Browse files
feat(raid): delete invite and Google Drive PDF when deleting teams (#714)
### Description Mandatory fixes before openning the registering for 2025 edition ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] All tests passing - [ ] Extended the documentation, if necessary --------- Co-authored-by: armanddidierjean <[email protected]>
1 parent a765d39 commit 327287c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

app/modules/raid/cruds_raid.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ async def delete_team_invite_tokens(
214214
await db.commit()
215215

216216

217+
async def delete_all_invite_tokens(
218+
db: AsyncSession,
219+
) -> None:
220+
await db.execute(delete(models_raid.InviteToken))
221+
await db.commit()
222+
223+
217224
async def delete_team(
218225
team_id: str,
219226
db: AsyncSession,

app/modules/raid/endpoints_raid.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,38 @@ async def delete_team(
418418
async def delete_all_teams(
419419
db: AsyncSession = Depends(get_db),
420420
user: models_users.CoreUser = Depends(is_user_in(GroupType.raid_admin)),
421+
settings: Settings = Depends(get_settings),
421422
):
422423
"""
423424
Delete all teams
424425
"""
426+
# First get all teams to access their file IDs
427+
teams = await cruds_raid.get_all_teams(db)
428+
# Delete files associated with each team from Google Drive
429+
async with DriveGoogleAPI(db, settings) as google_api:
430+
for team in teams:
431+
# Delete team PDF
432+
if team.file_id:
433+
google_api.delete_file(team.file_id)
434+
# Delete captain's security file if exists
435+
if (
436+
team.captain
437+
and team.captain.security_file
438+
and team.captain.security_file.file_id
439+
):
440+
google_api.delete_file(team.captain.security_file.file_id)
441+
# Delete second member's security file if exists
442+
if (
443+
team.second
444+
and team.second.security_file
445+
and team.second.security_file.file_id
446+
):
447+
google_api.delete_file(team.second.security_file.file_id)
448+
# Delete team invite tokens
449+
450+
await cruds_raid.delete_all_invite_tokens(db)
451+
452+
# Delete all teams from the database
425453
await cruds_raid.delete_all_teams(db)
426454

427455

0 commit comments

Comments
 (0)