Skip to content

Commit

Permalink
refactor: Create a new class for dashboard tenant list item
Browse files Browse the repository at this point in the history
  • Loading branch information
KShivendu committed Aug 14, 2023
1 parent 6f02fcf commit ee4b68d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
23 changes: 12 additions & 11 deletions supertokens_python/recipe/dashboard/api/list_tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from typing import TYPE_CHECKING, Any, Dict, List

from supertokens_python.recipe.multitenancy.interfaces import (
ListAllTenantsItem,
from supertokens_python.recipe.dashboard.interfaces import (
DashboardListTenantItem
)

if TYPE_CHECKING:
Expand All @@ -32,9 +32,6 @@
DashboardListTenantsGetResponse,
)

from copy import deepcopy


async def handle_list_tenants_api(
_api_implementation: APIInterface,
_tenant_id: str,
Expand All @@ -43,11 +40,15 @@ async def handle_list_tenants_api(
) -> APIResponse:
tenants = await list_all_tenants(user_context)

final_tenants: List[ListAllTenantsItem] = []
final_tenants: List[DashboardListTenantItem] = []

for current_tenant in tenants.tenants:
modified_tenant = deepcopy(current_tenant)
modified_tenant.core_config = None
final_tenants.append(modified_tenant)

return DashboardListTenantsGetResponse(tenants.tenants)
dashboard_tenant = DashboardListTenantItem(
tenant_id=current_tenant.tenant_id,
emailpassword=current_tenant.emailpassword,
passwordless=current_tenant.passwordless,
third_party=current_tenant.third_party,
)
final_tenants.append(dashboard_tenant)

return DashboardListTenantsGetResponse(final_tenants)
31 changes: 29 additions & 2 deletions supertokens_python/recipe/dashboard/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,38 @@ def to_json(self) -> Dict[str, Any]:
}


from supertokens_python.recipe.multitenancy.interfaces import ListAllTenantsOkResult
from supertokens_python.recipe.multitenancy.interfaces import EmailPasswordConfig, PasswordlessConfig, ThirdPartyConfig

class DashboardListTenantItem:
def __init__(
self,
tenant_id: str,
emailpassword: EmailPasswordConfig,
passwordless: PasswordlessConfig,
third_party: ThirdPartyConfig,
):
self.tenant_id = tenant_id
self.emailpassword = emailpassword
self.passwordless = passwordless
self.third_party = third_party

class DashboardListTenantsGetResponse(APIResponse, ListAllTenantsOkResult):
def to_json(self):
res = {
"tenantId": self.tenant_id,
"emailpassword": self.emailpassword.to_json(),
"passwordless": self.passwordless.to_json(),
"thirdParty": self.third_party.to_json(),
}

return res

class DashboardListTenantsGetResponse(APIResponse):
status: str = "OK"

def __init__(self, tenants: List[DashboardListTenantItem]) -> None:
self.tenants = tenants

def to_json(self) -> Dict[str, Any]:
return {
"status": self.status,
"tenants": [t.to_json() for t in self.tenants],
Expand Down
5 changes: 2 additions & 3 deletions supertokens_python/recipe/multitenancy/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
emailpassword: EmailPasswordConfig,
passwordless: PasswordlessConfig,
third_party: ThirdPartyConfig,
core_config: Optional[Dict[str, Any]],
core_config: Dict[str, Any],
):
self.emailpassword = emailpassword
self.passwordless = passwordless
Expand Down Expand Up @@ -131,9 +131,8 @@ def to_json(self):
"emailpassword": self.emailpassword.to_json(),
"passwordless": self.passwordless.to_json(),
"thirdParty": self.third_party.to_json(),
"coreConfig": self.core_config
}
if self.core_config is not None:
res["coreConfig"] = self.core_config

return res

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def list_all_tenants(
config.emailpassword,
config.passwordless,
config.third_party,
config.core_config or {},
config.core_config,
)
tenant_items.append(item)

Expand Down

0 comments on commit ee4b68d

Please sign in to comment.