-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a4fa38
commit 06e5d86
Showing
8 changed files
with
57 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 14 additions & 30 deletions
44
supertokens_python/recipe/dashboard/api/userdetails/user_get.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,51 @@ | ||
from typing import Union, Dict, Any | ||
from supertokens_python.asyncio import get_user | ||
|
||
from supertokens_python.exceptions import raise_bad_input_exception | ||
from supertokens_python.recipe.dashboard.utils import get_user_for_recipe_id | ||
from supertokens_python.recipe.dashboard.utils import ( | ||
UserWithMetadata, | ||
) | ||
from supertokens_python.recipe.usermetadata import UserMetadataRecipe | ||
from supertokens_python.recipe.usermetadata.asyncio import get_user_metadata | ||
from supertokens_python.types import RecipeUserId | ||
|
||
from ...interfaces import ( | ||
APIInterface, | ||
APIOptions, | ||
UserGetAPINoUserFoundError, | ||
UserGetAPIOkResponse, | ||
UserGetAPIRecipeNotInitialisedError, | ||
) | ||
from ...utils import is_recipe_initialised, is_valid_recipe_id | ||
|
||
|
||
async def handle_user_get( | ||
_api_interface: APIInterface, | ||
_tenant_id: str, | ||
api_options: APIOptions, | ||
_user_context: Dict[str, Any], | ||
) -> Union[ | ||
UserGetAPINoUserFoundError, | ||
UserGetAPIOkResponse, | ||
UserGetAPIRecipeNotInitialisedError, | ||
]: | ||
) -> Union[UserGetAPINoUserFoundError, UserGetAPIOkResponse,]: | ||
user_id = api_options.request.get_query_param("userId") | ||
recipe_id = api_options.request.get_query_param("recipeId") | ||
|
||
if user_id is None: | ||
raise_bad_input_exception("Missing required parameter 'userId'") | ||
|
||
if recipe_id is None: | ||
raise_bad_input_exception("Missing required parameter 'recipeId'") | ||
|
||
if not is_valid_recipe_id(recipe_id): | ||
raise_bad_input_exception("Invalid recipe id") | ||
|
||
if not is_recipe_initialised(recipe_id): | ||
return UserGetAPIRecipeNotInitialisedError() | ||
|
||
user_response = await get_user_for_recipe_id( | ||
RecipeUserId(user_id), recipe_id, _user_context | ||
) | ||
if user_response.user is None: | ||
user_response = await get_user(user_id, _user_context) | ||
if user_response is None: | ||
return UserGetAPINoUserFoundError() | ||
|
||
user = user_response.user | ||
user_with_metadata: UserWithMetadata = UserWithMetadata().from_user(user_response) | ||
|
||
try: | ||
UserMetadataRecipe.get_instance() | ||
except Exception: | ||
user.first_name = "FEATURE_NOT_ENABLED" | ||
user.last_name = "FEATURE_NOT_ENABLED" | ||
user_with_metadata.first_name = "FEATURE_NOT_ENABLED" | ||
user_with_metadata.last_name = "FEATURE_NOT_ENABLED" | ||
|
||
return UserGetAPIOkResponse(recipe_id, user) | ||
return UserGetAPIOkResponse(user_with_metadata) | ||
|
||
user_metadata = await get_user_metadata(user_id, user_context=_user_context) | ||
first_name = user_metadata.metadata.get("first_name", "") | ||
last_name = user_metadata.metadata.get("last_name", "") | ||
|
||
user.first_name = first_name | ||
user.last_name = last_name | ||
user_with_metadata.first_name = first_name | ||
user_with_metadata.last_name = last_name | ||
|
||
return UserGetAPIOkResponse(recipe_id, user) | ||
return UserGetAPIOkResponse(user_with_metadata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters