From 40dc626bdc0e2b792a9247a3f4d7f8646e8b1202 Mon Sep 17 00:00:00 2001 From: smith Date: Mon, 4 Dec 2023 11:00:28 -0500 Subject: [PATCH] 1604-Server error for new SUMO user with existing ZD User * 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 --- kitsune/customercare/zendesk.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/kitsune/customercare/zendesk.py b/kitsune/customercare/zendesk.py index 925486036db..d1e3ba2fd1f 100644 --- a/kitsune/customercare/zendesk.py +++ b/kitsune/customercare/zendesk.py @@ -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}