Skip to content

Commit ee4b68d

Browse files
committed
refactor: Create a new class for dashboard tenant list item
1 parent 6f02fcf commit ee4b68d

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

supertokens_python/recipe/dashboard/api/list_tenants.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
from typing import TYPE_CHECKING, Any, Dict, List
1818

19-
from supertokens_python.recipe.multitenancy.interfaces import (
20-
ListAllTenantsItem,
19+
from supertokens_python.recipe.dashboard.interfaces import (
20+
DashboardListTenantItem
2121
)
2222

2323
if TYPE_CHECKING:
@@ -32,9 +32,6 @@
3232
DashboardListTenantsGetResponse,
3333
)
3434

35-
from copy import deepcopy
36-
37-
3835
async def handle_list_tenants_api(
3936
_api_implementation: APIInterface,
4037
_tenant_id: str,
@@ -43,11 +40,15 @@ async def handle_list_tenants_api(
4340
) -> APIResponse:
4441
tenants = await list_all_tenants(user_context)
4542

46-
final_tenants: List[ListAllTenantsItem] = []
43+
final_tenants: List[DashboardListTenantItem] = []
4744

4845
for current_tenant in tenants.tenants:
49-
modified_tenant = deepcopy(current_tenant)
50-
modified_tenant.core_config = None
51-
final_tenants.append(modified_tenant)
52-
53-
return DashboardListTenantsGetResponse(tenants.tenants)
46+
dashboard_tenant = DashboardListTenantItem(
47+
tenant_id=current_tenant.tenant_id,
48+
emailpassword=current_tenant.emailpassword,
49+
passwordless=current_tenant.passwordless,
50+
third_party=current_tenant.third_party,
51+
)
52+
final_tenants.append(dashboard_tenant)
53+
54+
return DashboardListTenantsGetResponse(final_tenants)

supertokens_python/recipe/dashboard/interfaces.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,38 @@ def to_json(self) -> Dict[str, Any]:
101101
}
102102

103103

104-
from supertokens_python.recipe.multitenancy.interfaces import ListAllTenantsOkResult
104+
from supertokens_python.recipe.multitenancy.interfaces import EmailPasswordConfig, PasswordlessConfig, ThirdPartyConfig
105105

106+
class DashboardListTenantItem:
107+
def __init__(
108+
self,
109+
tenant_id: str,
110+
emailpassword: EmailPasswordConfig,
111+
passwordless: PasswordlessConfig,
112+
third_party: ThirdPartyConfig,
113+
):
114+
self.tenant_id = tenant_id
115+
self.emailpassword = emailpassword
116+
self.passwordless = passwordless
117+
self.third_party = third_party
106118

107-
class DashboardListTenantsGetResponse(APIResponse, ListAllTenantsOkResult):
108119
def to_json(self):
120+
res = {
121+
"tenantId": self.tenant_id,
122+
"emailpassword": self.emailpassword.to_json(),
123+
"passwordless": self.passwordless.to_json(),
124+
"thirdParty": self.third_party.to_json(),
125+
}
126+
127+
return res
128+
129+
class DashboardListTenantsGetResponse(APIResponse):
130+
status: str = "OK"
131+
132+
def __init__(self, tenants: List[DashboardListTenantItem]) -> None:
133+
self.tenants = tenants
134+
135+
def to_json(self) -> Dict[str, Any]:
109136
return {
110137
"status": self.status,
111138
"tenants": [t.to_json() for t in self.tenants],

supertokens_python/recipe/multitenancy/interfaces.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
emailpassword: EmailPasswordConfig,
102102
passwordless: PasswordlessConfig,
103103
third_party: ThirdPartyConfig,
104-
core_config: Optional[Dict[str, Any]],
104+
core_config: Dict[str, Any],
105105
):
106106
self.emailpassword = emailpassword
107107
self.passwordless = passwordless
@@ -131,9 +131,8 @@ def to_json(self):
131131
"emailpassword": self.emailpassword.to_json(),
132132
"passwordless": self.passwordless.to_json(),
133133
"thirdParty": self.third_party.to_json(),
134+
"coreConfig": self.core_config
134135
}
135-
if self.core_config is not None:
136-
res["coreConfig"] = self.core_config
137136

138137
return res
139138

supertokens_python/recipe/multitenancy/recipe_implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ async def list_all_tenants(
193193
config.emailpassword,
194194
config.passwordless,
195195
config.third_party,
196-
config.core_config or {},
196+
config.core_config,
197197
)
198198
tenant_items.append(item)
199199

0 commit comments

Comments
 (0)