From c33d7428a9fedc87374fd3f087efb3bbb1ef4c16 Mon Sep 17 00:00:00 2001 From: Kristi Nikolla Date: Thu, 19 Jan 2023 10:42:30 -0500 Subject: [PATCH] Refactor: Simplify logic in deleting user --- acct_mgt/app.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/acct_mgt/app.py b/acct_mgt/app.py index b1b98d0..f7ec782 100644 --- a/acct_mgt/app.py +++ b/acct_mgt/app.py @@ -291,9 +291,7 @@ def create_moc_user(user_name): @APP.route("/users/", methods=["DELETE"]) @AUTH.login_required def delete_moc_user(user_name): - user_does_not_exist = 0 - # use case if User exists then delete - if shift.user_exists(user_name): + if user_exists := shift.user_exists(user_name): result = shift.delete_user(user_name) if result.status_code not in (200, 201): return Response( @@ -303,25 +301,19 @@ def delete_moc_user(user_name): status=400, mimetype="application/json", ) - else: - user_does_not_exist = 0x01 - id_user = user_name - - if shift.identity_exists(id_user): - result = shift.delete_identity(id_user) + if identity_exists := shift.identity_exists(user_name): + result = shift.delete_identity(user_name) if result.status_code not in (200, 201): return Response( response=json.dumps( - {"msg": f"unable to delete identity for ({id_user})"} + {"msg": f"unable to delete identity for ({user_name})"} ), status=400, mimetype="application/json", ) - else: - user_does_not_exist = user_does_not_exist | 0x02 - if user_does_not_exist == 3: + if not (user_exists and identity_exists): return Response( response=json.dumps({"msg": f"user does not exist ({user_name})"}), status=200,