Skip to content

Commit ee6bd1b

Browse files
committed
Make tenant id compulsory in userrolesl
1 parent bb00729 commit ee6bd1b

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

supertokens_python/recipe/userroles/asyncio/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, Dict, List, Union, Optional
22

3+
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
34
from supertokens_python.recipe.userroles.interfaces import (
45
AddRoleToUserOkResult,
56
CreateNewRoleOrAddPermissionsOkResult,
@@ -25,7 +26,7 @@ async def add_role_to_user(
2526
if user_context is None:
2627
user_context = {}
2728
return await UserRolesRecipe.get_instance().recipe_implementation.add_role_to_user(
28-
user_id, role, tenant_id, user_context
29+
user_id, role, tenant_id or DEFAULT_TENANT_ID, user_context
2930
)
3031

3132

@@ -38,7 +39,7 @@ async def remove_user_role(
3839
if user_context is None:
3940
user_context = {}
4041
return await UserRolesRecipe.get_instance().recipe_implementation.remove_user_role(
41-
user_id, role, tenant_id, user_context
42+
user_id, role, tenant_id or DEFAULT_TENANT_ID, user_context
4243
)
4344

4445

@@ -51,7 +52,7 @@ async def get_roles_for_user(
5152
user_context = {}
5253
return (
5354
await UserRolesRecipe.get_instance().recipe_implementation.get_roles_for_user(
54-
user_id, tenant_id, user_context
55+
user_id, tenant_id or DEFAULT_TENANT_ID, user_context
5556
)
5657
)
5758

@@ -64,7 +65,7 @@ async def get_users_that_have_role(
6465
if user_context is None:
6566
user_context = {}
6667
return await UserRolesRecipe.get_instance().recipe_implementation.get_users_that_have_role(
67-
role, tenant_id, user_context
68+
role, tenant_id or DEFAULT_TENANT_ID, user_context
6869
)
6970

7071

supertokens_python/recipe/userroles/interfaces.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def add_role_to_user(
6161
self,
6262
user_id: str,
6363
role: str,
64-
tenant_id: Optional[str],
64+
tenant_id: str,
6565
user_context: Dict[str, Any],
6666
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
6767
pass
@@ -71,20 +71,20 @@ async def remove_user_role(
7171
self,
7272
user_id: str,
7373
role: str,
74-
tenant_id: Optional[str],
74+
tenant_id: str,
7575
user_context: Dict[str, Any],
7676
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
7777
pass
7878

7979
@abstractmethod
8080
async def get_roles_for_user(
81-
self, user_id: str, tenant_id: Optional[str], user_context: Dict[str, Any]
81+
self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
8282
) -> GetRolesForUserOkResult:
8383
pass
8484

8585
@abstractmethod
8686
async def get_users_that_have_role(
87-
self, role: str, tenant_id: Optional[str], user_context: Dict[str, Any]
87+
self, role: str, tenant_id: str, user_context: Dict[str, Any]
8888
) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
8989
pass
9090

supertokens_python/recipe/userroles/recipe_implementation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def add_role_to_user(
4444
self,
4545
user_id: str,
4646
role: str,
47-
tenant_id: Optional[str],
47+
tenant_id: str,
4848
user_context: Dict[str, Any],
4949
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
5050
params = {"userId": user_id, "role": role}
@@ -62,7 +62,7 @@ async def remove_user_role(
6262
self,
6363
user_id: str,
6464
role: str,
65-
tenant_id: Optional[str],
65+
tenant_id: str,
6666
user_context: Dict[str, Any],
6767
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
6868
params = {"userId": user_id, "role": role}
@@ -79,7 +79,7 @@ async def remove_user_role(
7979
return UnknownRoleError()
8080

8181
async def get_roles_for_user(
82-
self, user_id: str, tenant_id: Optional[str], user_context: Dict[str, Any]
82+
self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
8383
) -> GetRolesForUserOkResult:
8484
params = {"userId": user_id}
8585
response = await self.querier.send_get_request(
@@ -89,7 +89,7 @@ async def get_roles_for_user(
8989
return GetRolesForUserOkResult(roles=response["roles"])
9090

9191
async def get_users_that_have_role(
92-
self, role: str, tenant_id: Optional[str], user_context: Dict[str, Any]
92+
self, role: str, tenant_id: str, user_context: Dict[str, Any]
9393
) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
9494
params = {"role": role}
9595
response = await self.querier.send_get_request(

0 commit comments

Comments
 (0)