Skip to content

Commit

Permalink
fix: change email
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonylucas74 committed Oct 6, 2024
1 parent a09709d commit d8fa556
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 10 additions & 4 deletions backend/apps/account_payment/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions backend/apps/account_payment/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8fa556

Please sign in to comment.