diff --git a/api/chalicelib/core/tenants.py b/api/chalicelib/core/tenants.py index 4d95ae491..7a4e1a451 100644 --- a/api/chalicelib/core/tenants.py +++ b/api/chalicelib/core/tenants.py @@ -1,7 +1,6 @@ -import schemas -from chalicelib.utils import pg_client +from chalicelib.core import license from chalicelib.utils import helper -from chalicelib.core import users, license +from chalicelib.utils import pg_client def get_by_tenant_id(tenant_id): @@ -43,7 +42,7 @@ def generate_new_api_key(tenant_id): return helper.dict_to_camel_case(cur.fetchone()) -def edit_client(tenant_id, changes): +def edit_tenant(tenant_id, changes): with pg_client.PostgresClient() as cur: query = cur.mogrify(f"""UPDATE public.tenants SET {", ".join([f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()])} @@ -53,21 +52,6 @@ def edit_client(tenant_id, changes): return helper.dict_to_camel_case(cur.fetchone()) -def update(tenant_id, user_id, data: schemas.UpdateTenantSchema): - admin = users.get(user_id=user_id, tenant_id=tenant_id) - - if not admin["admin"] and not admin["superAdmin"]: - return {"errors": ["unauthorized, needs admin or owner"]} - if data.name is None and data.opt_out is None: - return {"errors": ["please provide 'name' of 'optOut' attribute for update"]} - changes = {} - if data.name is not None and len(data.name) > 0: - changes["name"] = data.name - if data.opt_out is not None: - changes["optOut"] = data.opt_out - return edit_client(tenant_id=tenant_id, changes=changes) - - def tenants_exists(use_pool=True): with pg_client.PostgresClient(use_pool=use_pool) as cur: cur.execute(f"SELECT EXISTS(SELECT 1 FROM public.tenants)") diff --git a/api/chalicelib/core/users.py b/api/chalicelib/core/users.py index 45b034587..3e92c8a56 100644 --- a/api/chalicelib/core/users.py +++ b/api/chalicelib/core/users.py @@ -291,7 +291,7 @@ def edit_account(user_id, tenant_id, changes: schemas.EditAccountSchema): if changes.opt_out is not None: _tenant_changes["opt_out"] = changes.opt_out if len(_tenant_changes.keys()) > 0: - tenants.edit_client(tenant_id=tenant_id, changes=_tenant_changes) + tenants.edit_tenant(tenant_id=tenant_id, changes=_tenant_changes) return {"data": __get_account_info(tenant_id=tenant_id, user_id=user_id)} diff --git a/api/routers/core.py b/api/routers/core.py index 49782e2a0..e71ad36f8 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -655,13 +655,6 @@ async def generate_new_tenant_token(context: schemas.CurrentContext = Depends(OR } -@app.post('/client', tags=['client']) -@app.put('/client', tags=['client']) -async def edit_client(data: schemas.UpdateTenantSchema = Body(...), - context: schemas.CurrentContext = Depends(OR_context)): - return tenants.update(tenant_id=context.tenant_id, user_id=context.user_id, data=data) - - @app.get('/notifications', tags=['notifications']) async def get_notifications(context: schemas.CurrentContext = Depends(OR_context)): return {"data": notifications.get_all(tenant_id=context.tenant_id, user_id=context.user_id)} diff --git a/api/schemas.py b/api/schemas.py index b13ee6547..e8a5c8a59 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -265,32 +265,6 @@ class MetadataListSchema(BaseModel): list: List[MetadataBasicSchema] = Field(...) -class EmailPayloadSchema(BaseModel): - auth: str = Field(...) - email: EmailStr = Field(...) - link: str = Field(...) - message: str = Field(...) - - _transform_email = validator('email', pre=True, allow_reuse=True)(transform_email) - - -class MemberInvitationPayloadSchema(BaseModel): - auth: str = Field(...) - email: EmailStr = Field(...) - invitation_link: str = Field(...) - client_id: str = Field(...) - sender_name: str = Field(...) - - _transform_email = validator('email', pre=True, allow_reuse=True)(transform_email) - - class Config: - alias_generator = attribute_to_camel_case - - -class ErrorIdsPayloadSchema(BaseModel): - errors: List[str] = Field([]) - - class _AlertMessageSchema(BaseModel): type: str = Field(...) value: str = Field(...) diff --git a/ee/api/chalicelib/core/tenants.py b/ee/api/chalicelib/core/tenants.py index 7ea621007..5f245188a 100644 --- a/ee/api/chalicelib/core/tenants.py +++ b/ee/api/chalicelib/core/tenants.py @@ -1,5 +1,4 @@ -import schemas -from chalicelib.core import users, license +from chalicelib.core import license from chalicelib.utils import helper from chalicelib.utils import pg_client @@ -68,7 +67,7 @@ def generate_new_api_key(tenant_id): return helper.dict_to_camel_case(cur.fetchone()) -def edit_client(tenant_id, changes): +def edit_tenant(tenant_id, changes): with pg_client.PostgresClient() as cur: query = cur.mogrify(f"""UPDATE public.tenants SET {", ".join([f"{helper.key_to_snake_case(k)} = %({k})s" for k in changes.keys()])} @@ -79,21 +78,6 @@ def edit_client(tenant_id, changes): return helper.dict_to_camel_case(cur.fetchone()) -def update(tenant_id, user_id, data: schemas.UpdateTenantSchema): - admin = users.get(user_id=user_id, tenant_id=tenant_id) - - if not admin["admin"] and not admin["superAdmin"]: - return {"errors": ["unauthorized, needs admin or owner"]} - if data.name is None and data.opt_out is None: - return {"errors": ["please provide 'name' of 'optOut' attribute for update"]} - changes = {} - if data.name is not None and len(data.name) > 0: - changes["name"] = data.name - if data.opt_out is not None: - changes["optOut"] = data.opt_out - return edit_client(tenant_id=tenant_id, changes=changes) - - def tenants_exists(use_pool=True): with pg_client.PostgresClient(use_pool=use_pool) as cur: cur.execute(f"SELECT EXISTS(SELECT 1 FROM public.tenants)") diff --git a/ee/api/chalicelib/core/users.py b/ee/api/chalicelib/core/users.py index b6141a351..e610bed41 100644 --- a/ee/api/chalicelib/core/users.py +++ b/ee/api/chalicelib/core/users.py @@ -339,7 +339,7 @@ def edit_account(user_id, tenant_id, changes: schemas.EditAccountSchema): if changes.opt_out is not None: _tenant_changes["opt_out"] = changes.opt_out if len(_tenant_changes.keys()) > 0: - tenants.edit_client(tenant_id=tenant_id, changes=_tenant_changes) + tenants.edit_tenant(tenant_id=tenant_id, changes=_tenant_changes) return {"data": __get_account_info(tenant_id=tenant_id, user_id=user_id)}