Skip to content

Commit

Permalink
fix revocation (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
Landeers authored Feb 2, 2024
1 parent a91a6b4 commit 1eca8cb
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions client/resana_secure/routes/humans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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

0 comments on commit 1eca8cb

Please sign in to comment.