Skip to content

Commit daece26

Browse files
Merge pull request #269 from supertokens/dashboard-user-get-change
fix: Update dashboard recipe user Get API
2 parents 0eaf3c9 + 7451922 commit daece26

File tree

6 files changed

+86
-5
lines changed

6 files changed

+86
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## unreleased
99

10+
## [0.11.11] - 2022-12-26
11+
12+
- Updates dashboard version
13+
- Updates user GET API for the dashboard recipe
14+
1015
## [0.11.10] - 2022-12-12
1116

1217
- 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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
setup(
7272
name="supertokens_python",
73-
version="0.11.10",
73+
version="0.11.11",
7474
author="SuperTokens",
7575
license="Apache 2.0",
7676
author_email="[email protected]",

supertokens_python/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414
SUPPORTED_CDI_VERSIONS = ["2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15"]
15-
VERSION = "0.11.10"
15+
VERSION = "0.11.11"
1616
TELEMETRY = "/telemetry"
1717
USER_COUNT = "/users/count"
1818
USER_DELETE = "/user/remove"
@@ -25,4 +25,4 @@
2525
FDI_KEY_HEADER = "fdi-version"
2626
API_VERSION = "/apiversion"
2727
API_VERSION_HEADER = "cdi-version"
28-
DASHBOARD_VERSION = "0.2"
28+
DASHBOARD_VERSION = "0.3"

supertokens_python/recipe/dashboard/api/userdetails/user_get.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
APIOptions,
1111
UserGetAPINoUserFoundError,
1212
UserGetAPIOkResponse,
13+
UserGetAPIRecipeNotInitialisedError,
1314
)
14-
from ...utils import is_valid_recipe_id
15+
from ...utils import is_recipe_initialised, is_valid_recipe_id
1516

1617

1718
async def handle_user_get(
1819
_api_interface: APIInterface, api_options: APIOptions
19-
) -> Union[UserGetAPINoUserFoundError, UserGetAPIOkResponse]:
20+
) -> Union[
21+
UserGetAPINoUserFoundError,
22+
UserGetAPIOkResponse,
23+
UserGetAPIRecipeNotInitialisedError,
24+
]:
2025
user_id = api_options.request.get_query_param("userId")
2126
recipe_id = api_options.request.get_query_param("recipeId")
2227

@@ -29,6 +34,9 @@ async def handle_user_get(
2934
if not is_valid_recipe_id(recipe_id):
3035
raise_bad_input_exception("Invalid recipe id")
3136

37+
if not is_recipe_initialised(recipe_id):
38+
return UserGetAPIRecipeNotInitialisedError()
39+
3240
user_response = await get_user_for_recipe_id(user_id, recipe_id)
3341
if user_response is None:
3442
return UserGetAPINoUserFoundError()

supertokens_python/recipe/dashboard/interfaces.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ def to_json(self) -> Dict[str, Any]:
132132
return {"status": self.status}
133133

134134

135+
class UserGetAPIRecipeNotInitialisedError(APIResponse):
136+
status: str = "RECIPE_NOT_INITIALISED"
137+
138+
def to_json(self) -> Dict[str, Any]:
139+
return {"status": self.status}
140+
141+
135142
class FeatureNotEnabledError(APIResponse):
136143
status: str = "FEATURE_NOT_ENABLED_ERROR"
137144

supertokens_python/recipe/dashboard/utils.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@
2727
from supertokens_python.recipe.thirdparty.asyncio import (
2828
get_user_by_id as tp_get_user_by_idx,
2929
)
30+
from supertokens_python.recipe.thirdpartyemailpassword import (
31+
ThirdPartyEmailPasswordRecipe,
32+
)
3033
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
3134
get_user_by_id as tpep_get_user_by_id,
3235
)
36+
from supertokens_python.recipe.thirdpartypasswordless import (
37+
ThirdPartyPasswordlessRecipe,
38+
)
3339
from supertokens_python.recipe.thirdpartypasswordless.asyncio import (
3440
get_user_by_id as tppless_get_user_by_id,
3541
)
@@ -324,3 +330,58 @@ async def update_user_dict(
324330
return GetUserForRecipeIdResult(user, recipe)
325331

326332
return None
333+
334+
335+
def is_recipe_initialised(recipeId: str) -> bool:
336+
isRecipeInitialised: bool = False
337+
338+
if recipeId == EmailPasswordRecipe.recipe_id:
339+
try:
340+
EmailPasswordRecipe.get_instance()
341+
isRecipeInitialised = True
342+
except Exception:
343+
pass
344+
345+
if not isRecipeInitialised:
346+
try:
347+
ThirdPartyEmailPasswordRecipe.get_instance()
348+
isRecipeInitialised = True
349+
except Exception:
350+
pass
351+
352+
elif recipeId == PasswordlessRecipe.recipe_id:
353+
try:
354+
PasswordlessRecipe.get_instance()
355+
isRecipeInitialised = True
356+
except Exception:
357+
pass
358+
359+
if not isRecipeInitialised:
360+
try:
361+
ThirdPartyPasswordlessRecipe.get_instance()
362+
isRecipeInitialised = True
363+
except Exception:
364+
pass
365+
366+
elif recipeId == ThirdPartyRecipe.recipe_id:
367+
try:
368+
ThirdPartyRecipe.get_instance()
369+
isRecipeInitialised = True
370+
except Exception:
371+
pass
372+
373+
if not isRecipeInitialised:
374+
try:
375+
ThirdPartyEmailPasswordRecipe.get_instance()
376+
isRecipeInitialised = True
377+
except Exception:
378+
pass
379+
380+
if not isRecipeInitialised:
381+
try:
382+
ThirdPartyPasswordlessRecipe.get_instance()
383+
isRecipeInitialised = True
384+
except Exception:
385+
pass
386+
387+
return isRecipeInitialised

0 commit comments

Comments
 (0)