From 8a370fc2ae0c6b66ebc27c8bd3067141b0b488a4 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Wed, 8 Nov 2023 18:45:01 +0100 Subject: [PATCH] Api v1.15.0 (#1632) * refactor(chalice): refactored logs fix(chalice): fixed edit account --- api/chalicelib/core/users.py | 41 +++++++++++---------------------- api/chalicelib/utils/smtp.py | 6 +++-- api/routers/core_dynamic.py | 5 ++-- ee/api/chalicelib/core/users.py | 9 ++------ ee/api/routers/core_dynamic.py | 5 ++-- 5 files changed, 23 insertions(+), 43 deletions(-) diff --git a/api/chalicelib/core/users.py b/api/chalicelib/core/users.py index 036bb05ce..242f0bee1 100644 --- a/api/chalicelib/core/users.py +++ b/api/chalicelib/core/users.py @@ -114,6 +114,10 @@ def reset_member(tenant_id, editor_id, user_id_to_update): def update(tenant_id, user_id, changes, output=True): + print("---------") + print(tenant_id) + print(user_id) + print(changes) AUTH_KEYS = ["password", "invitationToken", "invitedAt", "changePwdExpireAt", "changePwdToken"] if len(changes.keys()) == 0: return None @@ -132,39 +136,20 @@ def update(tenant_id, user_id, changes, output=True): with pg_client.PostgresClient() as cur: if len(sub_query_users) > 0: - cur.execute( - cur.mogrify(f"""\ + query = cur.mogrify(f"""\ UPDATE public.users SET {" ,".join(sub_query_users)} - FROM public.basic_authentication - WHERE users.user_id = %(user_id)s - AND users.user_id = basic_authentication.user_id - RETURNING users.user_id, - users.email, - users.role, - users.name, - (CASE WHEN users.role = 'owner' THEN TRUE ELSE FALSE END) AS super_admin, - (CASE WHEN users.role = 'admin' THEN TRUE ELSE FALSE END) AS admin, - (CASE WHEN users.role = 'member' THEN TRUE ELSE FALSE END) AS member;""", - {"user_id": user_id, **changes}) - ) + WHERE users.user_id = %(user_id)s;""", + {"user_id": user_id, **changes}) + cur.execute(query) + print(query) if len(sub_query_bauth) > 0: - cur.execute( - cur.mogrify(f"""\ + query = cur.mogrify(f"""\ UPDATE public.basic_authentication SET {" ,".join(sub_query_bauth)} - FROM public.users AS users - WHERE basic_authentication.user_id = %(user_id)s - AND users.user_id = basic_authentication.user_id - RETURNING users.user_id, - users.email, - users.role, - users.name, - (CASE WHEN users.role = 'owner' THEN TRUE ELSE FALSE END) AS super_admin, - (CASE WHEN users.role = 'admin' THEN TRUE ELSE FALSE END) AS admin, - (CASE WHEN users.role = 'member' THEN TRUE ELSE FALSE END) AS member;""", - {"user_id": user_id, **changes}) - ) + WHERE basic_authentication.user_id = %(user_id)s;""", + {"user_id": user_id, **changes}) + cur.execute(query) if not output: return None return get(user_id=user_id, tenant_id=tenant_id) diff --git a/api/chalicelib/utils/smtp.py b/api/chalicelib/utils/smtp.py index 4182d5a10..d47235fbc 100644 --- a/api/chalicelib/utils/smtp.py +++ b/api/chalicelib/utils/smtp.py @@ -72,10 +72,11 @@ class SMTPClient: VALID_SMTP = None SMTP_ERROR = None +SMTP_NOTIFIED = False def has_smtp(): - global VALID_SMTP, SMTP_ERROR + global VALID_SMTP, SMTP_ERROR, SMTP_NOTIFIED if SMTP_ERROR is not None: logging.error("!!! SMTP error found, disabling SMTP configuration:") logging.error(SMTP_ERROR) @@ -86,7 +87,8 @@ def has_smtp(): if config("EMAIL_HOST") is not None and len(config("EMAIL_HOST")) > 0: VALID_SMTP, SMTP_ERROR = check_connexion() return VALID_SMTP - else: + elif not SMTP_NOTIFIED: + SMTP_NOTIFIED = True logging.info("no SMTP configuration found") return False diff --git a/api/routers/core_dynamic.py b/api/routers/core_dynamic.py index 3dde4e7d6..96acc4097 100644 --- a/api/routers/core_dynamic.py +++ b/api/routers/core_dynamic.py @@ -103,14 +103,13 @@ def get_account(context: schemas.CurrentContext = Depends(OR_context)): t = tenants.get_by_tenant_id(context.tenant_id) if t is not None: t["createdAt"] = TimeUTC.datetime_to_timestamp(t["createdAt"]) - t["tenantName"] = t.get("name") + t["tenantName"] = t.pop("name") return { 'data': { **r, **t, **license.get_status(context.tenant_id), - "smtp": smtp.has_smtp(), - # "iceServers": assist.get_ice_servers() + "smtp": smtp.has_smtp() } } diff --git a/ee/api/chalicelib/core/users.py b/ee/api/chalicelib/core/users.py index c0fcaa7c8..aaa0a5b18 100644 --- a/ee/api/chalicelib/core/users.py +++ b/ee/api/chalicelib/core/users.py @@ -166,10 +166,8 @@ def update(tenant_id, user_id, changes, output=True): cur.mogrify(f"""\ UPDATE public.users SET {" ,".join(sub_query_users)} - FROM public.basic_authentication WHERE users.user_id = %(user_id)s - AND users.tenant_id = %(tenant_id)s - AND users.user_id = basic_authentication.user_id;""", + AND users.tenant_id = %(tenant_id)s;""", {"tenant_id": tenant_id, "user_id": user_id, **changes}) ) if len(sub_query_bauth) > 0: @@ -177,10 +175,7 @@ def update(tenant_id, user_id, changes, output=True): cur.mogrify(f"""\ UPDATE public.basic_authentication SET {" ,".join(sub_query_bauth)} - FROM public.users AS users - WHERE basic_authentication.user_id = %(user_id)s - AND users.tenant_id = %(tenant_id)s - AND users.user_id = basic_authentication.user_id;""", + WHERE basic_authentication.user_id = %(user_id)s;""", {"tenant_id": tenant_id, "user_id": user_id, **changes}) ) if not output: diff --git a/ee/api/routers/core_dynamic.py b/ee/api/routers/core_dynamic.py index 9af7dd964..20cc71d5d 100644 --- a/ee/api/routers/core_dynamic.py +++ b/ee/api/routers/core_dynamic.py @@ -108,15 +108,14 @@ def get_account(context: schemas.CurrentContext = Depends(OR_context)): t = tenants.get_by_tenant_id(context.tenant_id) if t is not None: t["createdAt"] = TimeUTC.datetime_to_timestamp(t["createdAt"]) - t["tenantName"] = t.get("name") + t["tenantName"] = t.pop("name") return { 'data': { **r, **t, **license.get_status(context.tenant_id), "smtp": smtp.has_smtp(), - "saml2": SAML2_helper.is_saml2_available(), - # "iceServers": assist.get_ice_servers() + "saml2": SAML2_helper.is_saml2_available() } }