Skip to content

fix: Make tenant id compulsory in userroles #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions supertokens_python/recipe/userroles/asyncio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Dict, List, Union, Optional

from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
from supertokens_python.recipe.userroles.interfaces import (
AddRoleToUserOkResult,
CreateNewRoleOrAddPermissionsOkResult,
Expand All @@ -25,7 +26,7 @@ async def add_role_to_user(
if user_context is None:
user_context = {}
return await UserRolesRecipe.get_instance().recipe_implementation.add_role_to_user(
user_id, role, tenant_id, user_context
user_id, role, tenant_id or DEFAULT_TENANT_ID, user_context
)


Expand All @@ -38,7 +39,7 @@ async def remove_user_role(
if user_context is None:
user_context = {}
return await UserRolesRecipe.get_instance().recipe_implementation.remove_user_role(
user_id, role, tenant_id, user_context
user_id, role, tenant_id or DEFAULT_TENANT_ID, user_context
)


Expand All @@ -51,7 +52,7 @@ async def get_roles_for_user(
user_context = {}
return (
await UserRolesRecipe.get_instance().recipe_implementation.get_roles_for_user(
user_id, tenant_id, user_context
user_id, tenant_id or DEFAULT_TENANT_ID, user_context
)
)

Expand All @@ -64,7 +65,7 @@ async def get_users_that_have_role(
if user_context is None:
user_context = {}
return await UserRolesRecipe.get_instance().recipe_implementation.get_users_that_have_role(
role, tenant_id, user_context
role, tenant_id or DEFAULT_TENANT_ID, user_context
)


Expand Down
8 changes: 4 additions & 4 deletions supertokens_python/recipe/userroles/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def add_role_to_user(
self,
user_id: str,
role: str,
tenant_id: Optional[str],
tenant_id: str,
user_context: Dict[str, Any],
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
pass
Expand All @@ -71,20 +71,20 @@ async def remove_user_role(
self,
user_id: str,
role: str,
tenant_id: Optional[str],
tenant_id: str,
user_context: Dict[str, Any],
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
pass

@abstractmethod
async def get_roles_for_user(
self, user_id: str, tenant_id: Optional[str], user_context: Dict[str, Any]
self, user_id: str, tenant_id: str, user_context: Dict[str, Any]
) -> GetRolesForUserOkResult:
pass

@abstractmethod
async def get_users_that_have_role(
self, role: str, tenant_id: Optional[str], user_context: Dict[str, Any]
self, role: str, tenant_id: str, user_context: Dict[str, Any]
) -> Union[GetUsersThatHaveRoleOkResult, UnknownRoleError]:
pass

Expand Down
8 changes: 4 additions & 4 deletions supertokens_python/recipe/userroles/recipe_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def add_role_to_user(
self,
user_id: str,
role: str,
tenant_id: Optional[str],
tenant_id: str,
user_context: Dict[str, Any],
) -> Union[AddRoleToUserOkResult, UnknownRoleError]:
params = {"userId": user_id, "role": role}
Expand All @@ -62,7 +62,7 @@ async def remove_user_role(
self,
user_id: str,
role: str,
tenant_id: Optional[str],
tenant_id: str,
user_context: Dict[str, Any],
) -> Union[RemoveUserRoleOkResult, UnknownRoleError]:
params = {"userId": user_id, "role": role}
Expand All @@ -79,7 +79,7 @@ async def remove_user_role(
return UnknownRoleError()

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

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