From f9820aa9f7d25ec0a42c7b9dddf516410fec0546 Mon Sep 17 00:00:00 2001 From: Mo Balaa Date: Tue, 6 Aug 2024 12:01:36 -0500 Subject: [PATCH] Add login and alogin to MatrixAdminClient --- fractal/matrix/admin_client.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fractal/matrix/admin_client.py b/fractal/matrix/admin_client.py index 3c85fcb..e09fc2e 100644 --- a/fractal/matrix/admin_client.py +++ b/fractal/matrix/admin_client.py @@ -3,6 +3,7 @@ from typing import Tuple import requests +from asgiref.sync import async_to_sync class MatrixAdminClient: @@ -51,7 +52,7 @@ async def create_or_modify_user( deactivated=False, user_type=None, locked=False, - ) -> Tuple[str, str]: + ) -> None: """ Create or modify a user account using the Synapse Admin API. @@ -105,11 +106,16 @@ async def create_or_modify_user( body = {k: v for k, v in body.items() if v is not None} # Make the API request - response = self.do_request("PUT", endpoint, body) + # TODO make me async + self.do_request("PUT", endpoint, body) + async def alogin(self, user_id, password): from fractal.matrix import MatrixClient async with MatrixClient(self.homeserver_url) as client: client.user = user_id result = await client.login(password) - return result.user_id, result.access_token + return result.user_id, result.access_token + + def login(self, user_id, password): + return async_to_sync(self.alogin)(user_id, password)