Skip to content

fix: Update dashboard recipe user Get API #269

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 4 commits into from
Dec 26, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## unreleased

## [0.11.11] - 2022-12-26

- Updates dashboard version
- Updates user GET API for the dashboard recipe

## [0.11.10] - 2022-12-12

- Fixes issue of sign up API not sending a `FIELD_ERROR` response in case of duplicate email: https://github.com/supertokens/supertokens-python/issues/264
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

setup(
name="supertokens_python",
version="0.11.10",
version="0.11.11",
author="SuperTokens",
license="Apache 2.0",
author_email="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions supertokens_python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
SUPPORTED_CDI_VERSIONS = ["2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15"]
VERSION = "0.11.10"
VERSION = "0.11.11"
TELEMETRY = "/telemetry"
USER_COUNT = "/users/count"
USER_DELETE = "/user/remove"
Expand All @@ -25,4 +25,4 @@
FDI_KEY_HEADER = "fdi-version"
API_VERSION = "/apiversion"
API_VERSION_HEADER = "cdi-version"
DASHBOARD_VERSION = "0.2"
DASHBOARD_VERSION = "0.3"
12 changes: 10 additions & 2 deletions supertokens_python/recipe/dashboard/api/userdetails/user_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
APIOptions,
UserGetAPINoUserFoundError,
UserGetAPIOkResponse,
UserGetAPIRecipeNotInitialisedError,
)
from ...utils import is_valid_recipe_id
from ...utils import is_recipe_initialised, is_valid_recipe_id


async def handle_user_get(
_api_interface: APIInterface, api_options: APIOptions
) -> Union[UserGetAPINoUserFoundError, UserGetAPIOkResponse]:
) -> Union[
UserGetAPINoUserFoundError,
UserGetAPIOkResponse,
UserGetAPIRecipeNotInitialisedError,
]:
user_id = api_options.request.get_query_param("userId")
recipe_id = api_options.request.get_query_param("recipeId")

Expand All @@ -29,6 +34,9 @@ async def handle_user_get(
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(user_id, recipe_id)
if user_response is None:
return UserGetAPINoUserFoundError()
Expand Down
7 changes: 7 additions & 0 deletions supertokens_python/recipe/dashboard/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ def to_json(self) -> Dict[str, Any]:
return {"status": self.status}


class UserGetAPIRecipeNotInitialisedError(APIResponse):
status: str = "RECIPE_NOT_INITIALISED"

def to_json(self) -> Dict[str, Any]:
return {"status": self.status}


class FeatureNotEnabledError(APIResponse):
status: str = "FEATURE_NOT_ENABLED_ERROR"

Expand Down
61 changes: 61 additions & 0 deletions supertokens_python/recipe/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@
from supertokens_python.recipe.thirdparty.asyncio import (
get_user_by_id as tp_get_user_by_idx,
)
from supertokens_python.recipe.thirdpartyemailpassword import (
ThirdPartyEmailPasswordRecipe,
)
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
get_user_by_id as tpep_get_user_by_id,
)
from supertokens_python.recipe.thirdpartypasswordless import (
ThirdPartyPasswordlessRecipe,
)
from supertokens_python.recipe.thirdpartypasswordless.asyncio import (
get_user_by_id as tppless_get_user_by_id,
)
Expand Down Expand Up @@ -324,3 +330,58 @@ async def update_user_dict(
return GetUserForRecipeIdResult(user, recipe)

return None


def is_recipe_initialised(recipeId: str) -> bool:
isRecipeInitialised: bool = False

if recipeId == EmailPasswordRecipe.recipe_id:
try:
EmailPasswordRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

if not isRecipeInitialised:
try:
ThirdPartyEmailPasswordRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

elif recipeId == PasswordlessRecipe.recipe_id:
try:
PasswordlessRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

if not isRecipeInitialised:
try:
ThirdPartyPasswordlessRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

elif recipeId == ThirdPartyRecipe.recipe_id:
try:
ThirdPartyRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

if not isRecipeInitialised:
try:
ThirdPartyEmailPasswordRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

if not isRecipeInitialised:
try:
ThirdPartyPasswordlessRecipe.get_instance()
isRecipeInitialised = True
except Exception:
pass

return isRecipeInitialised