Skip to content

Commit

Permalink
1604-Server error for new SUMO user with existing ZD User
Browse files Browse the repository at this point in the history
* Moved check for ZD user into the block for non-authenticated
  users
* This allows a SUMO user to get profile updated properly with
  ZD id
  • Loading branch information
smithellis committed Dec 4, 2023
1 parent ed2763a commit 40dc626
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions kitsune/customercare/zendesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@ def __init__(self, **kwargs):

def _user_to_zendesk_user(self, user, email):
"""Given a Django user, return a Zendesk user."""
# If the user already exists in Zendesk return
# the Zendesk user object
# instead of creating a new one
if zuser := self.get_user_by_email(email):
return zuser
# If the user is not authenticated, we can't save anything to
# AnonymousUser Profile as it has none
# Four possible cases to account for:
# 1. No Django User, No ZD User -> Create ZD User From Email
# 2. No Django User, ZD User -> Get Existing ZD User Using Email
# 3. Django User, No ZD User -> Create ZD User from Django User
# 4. Django User, ZD User -> Get ZD User, Update Django User with Zendesk ID
if not user.is_authenticated:
# If the user already exists in Zendesk return
# the Zendesk user object
# instead of creating a new one
if zuser := self.get_user_by_email(email):
# No Django user, but yes ZD user
return zuser
# No Django user, no ZD user
name = "Anonymous User"
locale = "en-US"
id = None
external_id = None
user_fields = None
# Yes Django user
else:
fxa_uid = user.profile.fxa_uid
id_str = user.profile.zendesk_id
id = int(id_str) if id_str else None
id = int(id_str) if id_str else None # Yes Or No ZD User
name = user.profile.display_name
locale = user.profile.locale
user_fields = {"user_id": fxa_uid}
Expand Down

0 comments on commit 40dc626

Please sign in to comment.