Account deletion: DELETE /employees/me

Ouverte
#181 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
20/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
Active
Stack technique
fastapi, postgresql, python, sqlalchemy
Domaine
api, backend, databases

Piste de recherche

This is a planning issue; it names no implementation files or tests, and explicitly leaves tests out of scope. Read the listed sub-issues in order, starting with #141 and #142, then review #178–#180 for the database changes and endpoint branches. Done means the specified student and supervisor deletion behavior, notifications, file cleanup, and clerk updates are implemented across those issues.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Context

Students and supervisors have the right to delete all data associated with their account. This adds DELETE /employees/me, which deletes all clockwork-backend data for the caller identified by the JWT sub.
Supervisors/approvers (or the student/approvers) are notified about deleted petitions that were not completed.

Builds on the user_account linking: StudentDocuments (#144, done), PrevEmployment (#141), Petition student_user_account (#142).

Decisions

  1. Student deletion cascade-deletes all their data, including all petitions (completed too), via DB ON DELETE CASCADE on every FK to employee.user_account (StudentDocuments, PrevEmployment, Petition.student_user_account) and on budget_position.petition_id.

  2. Scope: clockwork-backend data only. Deleting the auth-service account is out of scope.

  3. One endpoint DELETE /employees/me. Identity comes from the JWT sub only, with no id in the path. It uses decode_user_jwt and not get_current_student (which would auto-create the Employee), and branches on user_role:

    • student → delete the Employee (DB cascade). 204, or 404 if no Employee exists
    • supervisor → app-level logic (supervisors have no Employee row). Always 204
    • clerk → 403
  4. Supervisor deletion:
    4.1 Supervisor's non-completed petitions (Petition.user_account == sub) are deleted.
    4.2 On completed petitions, user_account and supervisor_mail are set to NULL, so the student's contract record survives.

  5. Notifications are sent only for affected non-completed petitions:

    • student deletion → supervisor + all budget approvers
    • supervisor deletion → student + all budget approvers

    They're sent explicitly from the handler (no mapper hooks) through EmailHandler + BackgroundTasks after commit, using data captured before the delete (petition id, student_username, start/end date, status). One DE+EN mail per recipient per petition.

  6. Uploaded files are removed explicitly in the handler: collect file names → delete rows → commit → delete_student_doc_file / delete_prev_emp_file (api/utils.py). Best effort: failures are logged and the request still succeeds.

  7. JWT still valid after deletion: a later student request makes get_current_student recreate empty Employee/StudentDocuments rows. This is accepted, and the frontend logs out right after the 204.

  8. Clerk websocket push: after commit, send the refreshed clerk petition list via send_serialized_data_to_clerks, but only if an affected petition had a clerk-relevant status (same list as api/events/petition_events.py).

  9. Invariant change: "supervisor_mail is always present" now holds for non-completed petitions only. Petition.user_account / supervisor_mail and their PetitionRead fields become Optional.

Sub-issues (order)

#141 → #142 → #178 (DB cascades + nullable supervisor fields) → #179 (endpoint + student branch) → #180 (supervisor branch)

Frontend notes

  • Call DELETE /employees/me, then log out immediately on 204
  • PetitionRead.user_account and supervisor_mail may be null (completed petitions of deleted supervisors)

Out of scope

  • Deleting the account in the auth microservice
  • Tests (planning issue)
Langage dominant
Python
Étoiles
0
Forks
0
Merge moyen
12 h 7 min
PR mergées (30 j)
18

Préparer son environnement

  • Fournit un Dockerfile ou un fichier Docker Compose
  • Aucun modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de ClockGU/clockwork-backend

Toutes les issues de ClockGU/clockwork-backend

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.