Commit 83ebc231 by Ned Batchelder Committed by GitHub

Merge pull request #15708 from edx/schen/learner-1521-for-ginkgo

Move the user_attribute creation for site from within the user creation transaction to outside
parents 50b75023 1da320f1
...@@ -1675,7 +1675,7 @@ def user_signup_handler(sender, **kwargs): # pylint: disable=unused-argument ...@@ -1675,7 +1675,7 @@ def user_signup_handler(sender, **kwargs): # pylint: disable=unused-argument
log.info(u'user {} originated from a white labeled "Microsite"'.format(kwargs['instance'].id)) log.info(u'user {} originated from a white labeled "Microsite"'.format(kwargs['instance'].id))
def _do_create_account(form, custom_form=None, site=None): def _do_create_account(form, custom_form=None):
""" """
Given cleaned post variables, create the User and UserProfile objects, as well as the Given cleaned post variables, create the User and UserProfile objects, as well as the
registration for this user. registration for this user.
...@@ -1716,10 +1716,6 @@ def _do_create_account(form, custom_form=None, site=None): ...@@ -1716,10 +1716,6 @@ def _do_create_account(form, custom_form=None, site=None):
custom_model = custom_form.save(commit=False) custom_model = custom_form.save(commit=False)
custom_model.user = user custom_model.user = user
custom_model.save() custom_model.save()
if site:
# Set UserAttribute indicating the site the user account was created on.
UserAttribute.set_user_attribute(user, 'created_on_site', site.domain)
except IntegrityError: except IntegrityError:
# Figure out the cause of the integrity error # Figure out the cause of the integrity error
if len(User.objects.filter(username=user.username)) > 0: if len(User.objects.filter(username=user.username)) > 0:
...@@ -1762,6 +1758,13 @@ def _do_create_account(form, custom_form=None, site=None): ...@@ -1762,6 +1758,13 @@ def _do_create_account(form, custom_form=None, site=None):
return (user, profile, registration) return (user, profile, registration)
def _create_or_set_user_attribute_created_on_site(user, site):
# Create or Set UserAttribute indicating the microsite site the user account was created on.
# User maybe created on 'courses.edx.org', or a white-label site
if site:
UserAttribute.set_user_attribute(user, 'created_on_site', site.domain)
def create_account_with_params(request, params): def create_account_with_params(request, params):
""" """
Given a request and a dict of parameters (which may or may not have come Given a request and a dict of parameters (which may or may not have come
...@@ -1868,7 +1871,7 @@ def create_account_with_params(request, params): ...@@ -1868,7 +1871,7 @@ def create_account_with_params(request, params):
# Perform operations within a transaction that are critical to account creation # Perform operations within a transaction that are critical to account creation
with transaction.atomic(): with transaction.atomic():
# first, create the account # first, create the account
(user, profile, registration) = _do_create_account(form, custom_form, site=request.site) (user, profile, registration) = _do_create_account(form, custom_form)
# If a 3rd party auth provider and credentials were provided in the API, link the account with social auth # If a 3rd party auth provider and credentials were provided in the API, link the account with social auth
# (If the user is using the normal register page, the social auth pipeline does the linking, not this code) # (If the user is using the normal register page, the social auth pipeline does the linking, not this code)
...@@ -1905,6 +1908,8 @@ def create_account_with_params(request, params): ...@@ -1905,6 +1908,8 @@ def create_account_with_params(request, params):
raise ValidationError({'access_token': [error_message]}) raise ValidationError({'access_token': [error_message]})
# Perform operations that are non-critical parts of account creation # Perform operations that are non-critical parts of account creation
_create_or_set_user_attribute_created_on_site(user, request.site)
preferences_api.set_user_preference(user, LANGUAGE_KEY, get_language()) preferences_api.set_user_preference(user, LANGUAGE_KEY, get_language())
if settings.FEATURES.get('ENABLE_DISCUSSION_EMAIL_DIGEST'): if settings.FEATURES.get('ENABLE_DISCUSSION_EMAIL_DIGEST'):
...@@ -2225,7 +2230,7 @@ def auto_auth(request): ...@@ -2225,7 +2230,7 @@ def auto_auth(request):
# If successful, this will return a tuple containing # If successful, this will return a tuple containing
# the new user object. # the new user object.
try: try:
user, profile, reg = _do_create_account(form, site=request.site) user, profile, reg = _do_create_account(form)
except (AccountValidationError, ValidationError): except (AccountValidationError, ValidationError):
# Attempt to retrieve the existing user. # Attempt to retrieve the existing user.
user = User.objects.get(username=username) user = User.objects.get(username=username)
...@@ -2252,6 +2257,8 @@ def auto_auth(request): ...@@ -2252,6 +2257,8 @@ def auto_auth(request):
profile.year_of_birth = (year - age_limit) - 1 profile.year_of_birth = (year - age_limit) - 1
profile.save() profile.save()
_create_or_set_user_attribute_created_on_site(user, request.site)
# Enroll the user in a course # Enroll the user in a course
course_key = None course_key = None
if course_id: if course_id:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment