From d8fa556fc2a57093d468d8a742df6746027ab1e6 Mon Sep 17 00:00:00 2001 From: Jhony Lucas Date: Sat, 5 Oct 2024 22:07:58 -0300 Subject: [PATCH] fix: change email --- backend/apps/account_payment/graphql.py | 14 ++++++++++---- backend/apps/account_payment/webhooks.py | 7 +++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/apps/account_payment/graphql.py b/backend/apps/account_payment/graphql.py index a147313c..26b6009e 100644 --- a/backend/apps/account_payment/graphql.py +++ b/backend/apps/account_payment/graphql.py @@ -432,8 +432,10 @@ class Arguments: def mutate(cls, root, info, email): try: user = info.context.user - old_email = user.gcp_email or user.email + if user is None: + return cls(ok=False, errors=["User is none"]) + old_email = user.gcp_email or user.email if old_email == email: return cls(ok=True) @@ -446,8 +448,12 @@ def mutate(cls, root, info, email): except Exception: pass - subscription = user.pro_subscription() - if subscription and not is_email_in_group(email): + subscription = user.pro_subscription + + if subscription is None: + return cls(ok=True) + + if subscription.is_active and not is_email_in_group(email): try: add_user(email) except Exception: @@ -456,7 +462,7 @@ def mutate(cls, root, info, email): return cls(ok=True) except Exception as e: logger.error(e) - return cls(errors=[str(e)]) + return cls(ok=False, errors=[str(e)]) # Query to check based on a email if the user is in a group diff --git a/backend/apps/account_payment/webhooks.py b/backend/apps/account_payment/webhooks.py index e4d848da..fb1a29a4 100644 --- a/backend/apps/account_payment/webhooks.py +++ b/backend/apps/account_payment/webhooks.py @@ -128,8 +128,11 @@ def is_email_in_group(email: str, group_key: str = None) -> bool: .execute() ) - member_email = response.get("email", "").lower() - return member_email == email.lower() + member_email = response.get("email") + if not member_email: + return False + + return member_email.lower() == email.lower() except HttpError as e: logger.error(f"Erro ao verificar o usuário {email} no grupo {group_key}: {e}") return False