Account deletion: DELETE /employees/me

Abierto
#181 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
fastapi, postgresql, python, sqlalchemy

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
Python
Estrellas
0
Forks
0
Merge medio
12 h 7 min
PR fusionados (30 d)
18

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ClockGU/clockwork-backend

Todos los issues de ClockGU/clockwork-backend

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.