Account deletion: DELETE /employees/me

Aperta
#181 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
fastapi, postgresql, python, sqlalchemy
Ambito
api, backend, databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)
Lingua principale
Python
Stelle
0
Fork
0
Merge medio
12h 7m
PR unite (30g)
18

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ClockGU/clockwork-backend

Tutte le issue di ClockGU/clockwork-backend

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.