Skip to content

Commit bb00729

Browse files
committed
fix: Make similar to node sdk
1 parent 1fca64e commit bb00729

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

supertokens_python/recipe/userroles/interfaces.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any, Dict, List, Union
2+
from typing import Any, Dict, List, Union, Optional
33

44

55
class AddRoleToUserOkResult:
@@ -58,25 +58,33 @@ def __init__(self, roles: List[str]):
5858
class RecipeInterface(ABC):
5959
@abstractmethod
6060
async def add_role_to_user(
61-
self, user_id: str, role: str, tenant_id: str, user_context: Dict[str, Any]
61+
self,
62+
user_id: str,
63+
role: str,
64+
tenant_id: Optional[str],
65+
user_context: Dict[str, Any],
6266
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
6367
pass
6468

6569
@abstractmethod
6670
async def remove_user_role(
67-
self, user_id: str, role: str, tenant_id: str, user_context: Dict[str, Any]
71+
self,
72+
user_id: str,
73+
role: str,
74+
tenant_id: Optional[str],
75+
user_context: Dict[str, Any],
6876
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
6977
pass
7078

7179
@abstractmethod
7280
async def get_roles_for_user(
73-
self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
81+
self, user_id: str, tenant_id: Optional[str], user_context: Dict[str, Any]
7482
) -> GetRolesForUserOkResult:
7583
pass
7684

7785
@abstractmethod
7886
async def get_users_that_have_role(
79-
self, role: str, tenant_id: str, user_context: Dict[str, Any]
87+
self, role: str, tenant_id: Optional[str], user_context: Dict[str, Any]
8088
) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
8189
pass
8290

supertokens_python/recipe/userroles/recipe_implementation.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ async def add_role_to_user(
4949
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
5050
params = {"userId": user_id, "role": role}
5151
response = await self.querier.send_put_request(
52-
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/role"), params
52+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/role"),
53+
params,
5354
)
5455
if response.get("status") == "OK":
5556
return AddRoleToUserOkResult(
@@ -66,7 +67,10 @@ async def remove_user_role(
6667
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
6768
params = {"userId": user_id, "role": role}
6869
response = await self.querier.send_post_request(
69-
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/role/remove"), params
70+
NormalisedURLPath(
71+
f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/role/remove"
72+
),
73+
params,
7074
)
7175
if response["status"] == "OK":
7276
return RemoveUserRoleOkResult(
@@ -79,7 +83,8 @@ async def get_roles_for_user(
7983
) -> GetRolesForUserOkResult:
8084
params = {"userId": user_id}
8185
response = await self.querier.send_get_request(
82-
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/roles"), params
86+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/user/roles"),
87+
params,
8388
)
8489
return GetRolesForUserOkResult(roles=response["roles"])
8590

@@ -88,7 +93,8 @@ async def get_users_that_have_role(
8893
) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
8994
params = {"role": role}
9095
response = await self.querier.send_get_request(
91-
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/role/users"), params
96+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/role/users"),
97+
params,
9298
)
9399
if response.get("status") == "OK":
94100
return GetUsersThatHaveRoleOkResult(users=response["users"])

0 commit comments

Comments
 (0)