|
12 | 12 | # under the License. |
13 | 13 | from typing import Any, Dict, Union, Optional |
14 | 14 |
|
15 | | -from supertokens_python.recipe.emailverification.interfaces import ( |
16 | | - GetEmailForUserIdOkResult, |
17 | | - EmailDoesNotExistError, |
18 | | - CreateEmailVerificationTokenEmailAlreadyVerifiedError, |
19 | | - UnverifyEmailOkResult, |
20 | | - CreateEmailVerificationTokenOkResult, |
21 | | - RevokeEmailVerificationTokensOkResult, |
| 15 | +from ..interfaces import ( |
| 16 | + TenantConfig, |
| 17 | + ProviderConfig, |
| 18 | + CreateOrUpdateTenantOkResult, |
| 19 | + DeleteTenantOkResult, |
| 20 | + GetTenantOkResult, |
| 21 | + ListAllTenantsOkResult, |
| 22 | + CreateOrUpdateThirdPartyConfigOkResult, |
| 23 | + DeleteThirdPartyConfigOkResult, |
| 24 | + AssociateUserToTenantOkResult, |
| 25 | + AssociateUserToTenantErrorResult, |
| 26 | + DisassociateUserFromTenantOkResult, |
22 | 27 | ) |
23 | | -from supertokens_python.recipe.emailverification.types import EmailTemplateVars |
24 | | -from supertokens_python.recipe.emailverification.recipe import EmailVerificationRecipe |
| 28 | +from ..recipe import MultitenancyRecipe |
25 | 29 |
|
26 | 30 |
|
27 | | -async def create_email_verification_token( |
28 | | - user_id: str, |
29 | | - email: Optional[str] = None, |
30 | | - user_context: Union[None, Dict[str, Any]] = None, |
31 | | -) -> Union[ |
32 | | - CreateEmailVerificationTokenOkResult, |
33 | | - CreateEmailVerificationTokenEmailAlreadyVerifiedError, |
34 | | -]: |
| 31 | +async def create_or_update_tenant( |
| 32 | + tenant_id: Optional[str], |
| 33 | + config: TenantConfig, |
| 34 | + user_context: Optional[Dict[str, Any]] = None, |
| 35 | +) -> CreateOrUpdateTenantOkResult: |
35 | 36 | if user_context is None: |
36 | 37 | user_context = {} |
37 | | - recipe = EmailVerificationRecipe.get_instance() |
38 | | - if email is None: |
39 | | - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
40 | | - if isinstance(email_info, GetEmailForUserIdOkResult): |
41 | | - email = email_info.email |
42 | | - elif isinstance(email_info, EmailDoesNotExistError): |
43 | | - return CreateEmailVerificationTokenEmailAlreadyVerifiedError() |
44 | | - else: |
45 | | - raise Exception("Unknown User ID provided without email") |
46 | | - |
47 | | - return await recipe.recipe_implementation.create_email_verification_token( |
48 | | - user_id, email, user_context |
| 38 | + recipe = MultitenancyRecipe.get_instance() |
| 39 | + |
| 40 | + return await recipe.recipe_implementation.create_or_update_tenant( |
| 41 | + tenant_id, config, user_context |
49 | 42 | ) |
50 | 43 |
|
51 | 44 |
|
52 | | -async def verify_email_using_token( |
53 | | - token: str, user_context: Union[None, Dict[str, Any]] = None |
54 | | -): |
| 45 | +async def delete_tenant( |
| 46 | + tenant_id: str, user_context: Optional[Dict[str, Any]] = None |
| 47 | +) -> DeleteTenantOkResult: |
55 | 48 | if user_context is None: |
56 | 49 | user_context = {} |
57 | | - return await EmailVerificationRecipe.get_instance().recipe_implementation.verify_email_using_token( |
58 | | - token, user_context |
59 | | - ) |
| 50 | + recipe = MultitenancyRecipe.get_instance() |
60 | 51 |
|
| 52 | + return await recipe.recipe_implementation.delete_tenant(tenant_id, user_context) |
61 | 53 |
|
62 | | -async def is_email_verified( |
63 | | - user_id: str, |
64 | | - email: Optional[str] = None, |
65 | | - user_context: Union[None, Dict[str, Any]] = None, |
66 | | -): |
| 54 | + |
| 55 | +async def get_tenant( |
| 56 | + tenant_id: Optional[str], user_context: Optional[Dict[str, Any]] = None |
| 57 | +) -> GetTenantOkResult: |
| 58 | + if user_context is None: |
| 59 | + user_context = {} |
| 60 | + recipe = MultitenancyRecipe.get_instance() |
| 61 | + |
| 62 | + return await recipe.recipe_implementation.get_tenant(tenant_id, user_context) |
| 63 | + |
| 64 | + |
| 65 | +async def list_all_tenants( |
| 66 | + user_context: Optional[Dict[str, Any]] = None |
| 67 | +) -> ListAllTenantsOkResult: |
67 | 68 | if user_context is None: |
68 | 69 | user_context = {} |
69 | 70 |
|
70 | | - recipe = EmailVerificationRecipe.get_instance() |
71 | | - if email is None: |
72 | | - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
73 | | - if isinstance(email_info, GetEmailForUserIdOkResult): |
74 | | - email = email_info.email |
75 | | - elif isinstance(email_info, EmailDoesNotExistError): |
76 | | - return True |
77 | | - else: |
78 | | - raise Exception("Unknown User ID provided without email") |
79 | | - |
80 | | - return await recipe.recipe_implementation.is_email_verified( |
81 | | - user_id, email, user_context |
| 71 | + recipe = MultitenancyRecipe.get_instance() |
| 72 | + |
| 73 | + return await recipe.recipe_implementation.list_all_tenants(user_context) |
| 74 | + |
| 75 | + |
| 76 | +async def create_or_update_third_party_config( |
| 77 | + tenant_id: Optional[str], |
| 78 | + config: ProviderConfig, |
| 79 | + skip_validation: Optional[bool], |
| 80 | + user_context: Optional[Dict[str, Any]] = None, |
| 81 | +) -> CreateOrUpdateThirdPartyConfigOkResult: |
| 82 | + if user_context is None: |
| 83 | + user_context = {} |
| 84 | + |
| 85 | + recipe = MultitenancyRecipe.get_instance() |
| 86 | + |
| 87 | + return await recipe.recipe_implementation.create_or_update_third_party_config( |
| 88 | + tenant_id, config, skip_validation, user_context |
82 | 89 | ) |
83 | 90 |
|
84 | 91 |
|
85 | | -async def revoke_email_verification_tokens( |
86 | | - user_id: str, |
87 | | - email: Optional[str] = None, |
| 92 | +async def delete_third_party_config( |
| 93 | + tenant_id: Optional[str], |
| 94 | + third_party_id: str, |
88 | 95 | user_context: Optional[Dict[str, Any]] = None, |
89 | | -) -> RevokeEmailVerificationTokensOkResult: |
| 96 | +) -> DeleteThirdPartyConfigOkResult: |
90 | 97 | if user_context is None: |
91 | 98 | user_context = {} |
92 | 99 |
|
93 | | - recipe = EmailVerificationRecipe.get_instance() |
94 | | - if email is None: |
95 | | - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
96 | | - if isinstance(email_info, GetEmailForUserIdOkResult): |
97 | | - email = email_info.email |
98 | | - elif isinstance(email_info, EmailDoesNotExistError): |
99 | | - return RevokeEmailVerificationTokensOkResult() |
100 | | - else: |
101 | | - raise Exception("Unknown User ID provided without email") |
102 | | - |
103 | | - return await EmailVerificationRecipe.get_instance().recipe_implementation.revoke_email_verification_tokens( |
104 | | - user_id, email, user_context |
| 100 | + recipe = MultitenancyRecipe.get_instance() |
| 101 | + |
| 102 | + return await recipe.recipe_implementation.delete_third_party_config( |
| 103 | + tenant_id, third_party_id, user_context |
105 | 104 | ) |
106 | 105 |
|
107 | 106 |
|
108 | | -async def unverify_email( |
| 107 | +async def associate_user_to_tenant( |
| 108 | + tenant_id: Optional[str], |
109 | 109 | user_id: str, |
110 | | - email: Optional[str] = None, |
111 | | - user_context: Union[None, Dict[str, Any]] = None, |
112 | | -): |
| 110 | + user_context: Optional[Dict[str, Any]] = None, |
| 111 | +) -> Union[AssociateUserToTenantOkResult, AssociateUserToTenantErrorResult]: |
113 | 112 | if user_context is None: |
114 | 113 | user_context = {} |
115 | 114 |
|
116 | | - recipe = EmailVerificationRecipe.get_instance() |
117 | | - if email is None: |
118 | | - email_info = await recipe.get_email_for_user_id(user_id, user_context) |
119 | | - if isinstance(email_info, GetEmailForUserIdOkResult): |
120 | | - email = email_info.email |
121 | | - elif isinstance(email_info, EmailDoesNotExistError): |
122 | | - # Here we are returning OK since that's how it used to work, but a later call |
123 | | - # to is_verified will still return true |
124 | | - return UnverifyEmailOkResult |
125 | | - else: |
126 | | - raise Exception("Unknown User ID provided without email") |
127 | | - |
128 | | - return await EmailVerificationRecipe.get_instance().recipe_implementation.unverify_email( |
129 | | - user_id, email, user_context |
| 115 | + recipe = MultitenancyRecipe.get_instance() |
| 116 | + |
| 117 | + return await recipe.recipe_implementation.associate_user_to_tenant( |
| 118 | + tenant_id, user_id, user_context |
130 | 119 | ) |
131 | 120 |
|
132 | 121 |
|
133 | | -async def send_email( |
134 | | - input_: EmailTemplateVars, user_context: Union[None, Dict[str, Any]] = None |
135 | | -): |
| 122 | +async def dissociate_user_from_tenant( |
| 123 | + tenant_id: Optional[str], |
| 124 | + user_id: str, |
| 125 | + user_context: Optional[Dict[str, Any]] = None, |
| 126 | +) -> DisassociateUserFromTenantOkResult: |
136 | 127 | if user_context is None: |
137 | 128 | user_context = {} |
138 | | - return await EmailVerificationRecipe.get_instance().email_delivery.ingredient_interface_impl.send_email( |
139 | | - input_, user_context |
| 129 | + |
| 130 | + recipe = MultitenancyRecipe.get_instance() |
| 131 | + |
| 132 | + return await recipe.recipe_implementation.dissociate_user_from_tenant( |
| 133 | + tenant_id, user_id, user_context |
140 | 134 | ) |
0 commit comments