From 9ec71641cd85f36e3996e578d52b56e87448a21d Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah Date: Tue, 9 Jul 2024 12:58:24 +0500 Subject: [PATCH] fix: should autogenerate username in tpa pipeline if feature is enabled --- common/djangoapps/third_party_auth/pipeline.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py index fde2bb9cbc0c..8e688208af19 100644 --- a/common/djangoapps/third_party_auth/pipeline.py +++ b/common/djangoapps/third_party_auth/pipeline.py @@ -90,7 +90,9 @@ def B(*args, **kwargs): from openedx.core.djangoapps.user_api import accounts from openedx.core.djangoapps.user_api.accounts.utils import username_suffix_generator from openedx.core.djangoapps.user_authn import cookies as user_authn_cookies +from openedx.core.djangoapps.user_authn.toggles import is_auto_generated_username_enabled from openedx.core.djangoapps.user_authn.utils import is_safe_login_or_logout_redirect +from openedx.core.djangoapps.user_authn.views.utils import get_auto_generated_username from common.djangoapps.third_party_auth.utils import ( get_associated_user_by_email_response, get_user_from_email, @@ -991,12 +993,15 @@ def get_username(strategy, details, backend, user=None, *args, **kwargs): # lin else: slug_func = lambda val: val - if email_as_username and details.get('email'): - username = details['email'] - elif details.get('username'): - username = details['username'] + if is_auto_generated_username_enabled(): + username = get_auto_generated_username(details) else: - username = uuid4().hex + if email_as_username and details.get('email'): + username = details['email'] + elif details.get('username'): + username = details['username'] + else: + username = uuid4().hex input_username = username final_username = slug_func(clean_func(username[:max_length]))