From 6d6583ced6a6b30a24afdb0d1ba80fd221e866ab Mon Sep 17 00:00:00 2001 From: dettlaff Date: Wed, 11 Dec 2024 12:22:52 +0400 Subject: [PATCH] fix: get_user_by_username --- selfprivacy_api/actions/users.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/selfprivacy_api/actions/users.py b/selfprivacy_api/actions/users.py index b9eaddd..9abada5 100644 --- a/selfprivacy_api/actions/users.py +++ b/selfprivacy_api/actions/users.py @@ -159,23 +159,22 @@ def update_user( def get_user_by_username(username: str) -> UserDataUser: - user = ACTIVE_USERS_PROVIDER.get_user_by_username( - username=username - ) + if isinstance(ACTIVE_USERS_PROVIDER, JsonUserRepository): + return ACTIVE_USERS_PROVIDER.get_user_by_username(username=username) - if not isinstance(ACTIVE_USERS_PROVIDER, JsonUserRepository): - if username == "root": - return UserDataUser( - username="root", - user_type=UserDataUserOrigin.ROOT, - ssh_keys=get_ssh_keys(username="root"), - ) + if username == "root": + return UserDataUser( + username="root", + user_type=UserDataUserOrigin.ROOT, + ssh_keys=get_ssh_keys(username="root"), + ) - try: - if user: - user.ssh_keys = get_ssh_keys(username=user.username) - except UserNotFound: - pass + user = ACTIVE_USERS_PROVIDER.get_user_by_username(username=username) + + try: + user.ssh_keys = get_ssh_keys(username=user.username) + except UserNotFound: + pass return user