mirror of
https://github.com/a-mayb3/Kanban_clone_backend.git
synced 2026-03-21 10:05:38 +01:00
Fixed similar to last oversight where deleting a user would let it still in projects assigned users
This commit is contained in:
parent
52f13f5023
commit
a3fb4903ed
1 changed files with 12 additions and 0 deletions
|
|
@ -35,6 +35,18 @@ def delete_me(request: Request, db: db_dependency):
|
|||
"""Delete current authenticated user"""
|
||||
|
||||
user = auth.get_user_from_jwt(request, db)
|
||||
|
||||
## Remove user from all projects, delete projects with no users left
|
||||
projects = user.projects[:]
|
||||
for project in projects:
|
||||
project.users.remove(user)
|
||||
if len(project.users) == 0:
|
||||
## delete project if no users left
|
||||
tasks = project.tasks[:]
|
||||
for task in tasks:
|
||||
db.delete(task)
|
||||
db.delete(project)
|
||||
|
||||
db.delete(user)
|
||||
db.commit()
|
||||
## Logout user by clearing cookie
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue