From 37ef4a40f42450327aeb41c22a485217092e13e4 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Fri, 28 May 2021 13:36:45 +0200 Subject: [PATCH] User deletion no longer impacts repos Deleted user repos are given to admin account and locked --- nest_backend/routes/users/user.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nest_backend/routes/users/user.py b/nest_backend/routes/users/user.py index 9251bb7..475ee44 100644 --- a/nest_backend/routes/users/user.py +++ b/nest_backend/routes/users/user.py @@ -128,10 +128,17 @@ def page_user(email): return json_error("User is not admin.", USER_NOT_ADMIN), 403 if user == target: return json_error("The user cant delete himself. Its a sin.", USER_PREVENT_SEPPUKU), 406 + repos = target.owner_of + for repository in repos: + repository.owner_id = user.email + repository.is_active = False + for authorization in target.authorizations: + ext.session.delete(authorization) + ext.session.commit() ext.session.delete(target) try: ext.session.commit() - except Exception: + except Exception as e: ext.session.rollback() return json_error("Could not delete the user.", USER_DELETION_ERROR), 500 return json_success(""), 204 # "The user has been deleted."