From 1eca8cbf859da33804f4d4fc0503b68a44c96d01 Mon Sep 17 00:00:00 2001 From: Landeers Date: Fri, 2 Feb 2024 11:24:07 +0100 Subject: [PATCH] fix revocation (#353) --- client/resana_secure/routes/humans.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/client/resana_secure/routes/humans.py b/client/resana_secure/routes/humans.py index 7d9a58595..463e4de01 100644 --- a/client/resana_secure/routes/humans.py +++ b/client/resana_secure/routes/humans.py @@ -6,7 +6,12 @@ from parsec.core.logged_core import LoggedCore -from ..utils import APIException, authenticated, backend_errors_to_api_exceptions +from ..utils import ( + APIException, + authenticated, + backend_errors_to_api_exceptions, + get_user_id_from_email, +) humans_bp = Blueprint("humans_api", __name__) @@ -67,19 +72,10 @@ async def search_humans(core: LoggedCore) -> tuple[dict[str, Any], int]: @authenticated async def revoke_user(core: LoggedCore, email: str) -> tuple[dict[str, Any], int]: with backend_errors_to_api_exceptions(): - results, _ = await core.find_humans(query=email) - # find_humans doesn't guarantee exact match on email, so manually filter just to be sure - recipient = next( - ( - r.user_id - for r in results - if r.human_handle is not None and r.human_handle.email == email - ), - None, - ) - if not recipient: + user_id = await get_user_id_from_email(core, email, omit_revoked=True) + if not user_id: raise APIException(404, {"error": "unknown_email"}) - await core.revoke_user(user_id=recipient) + await core.revoke_user(user_id=user_id) return {}, 200