Commit 1da320f1 by Simon Chen

Move the user_attribute creation for site from within the user creation transaction to outside

learner-1521
parent d17bc753
......@@ -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))
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
registration for this user.
......@@ -1716,10 +1716,6 @@ def _do_create_account(form, custom_form=None, site=None):
custom_model = custom_form.save(commit=False)
custom_model.user = user
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:
# Figure out the cause of the integrity error
if len(User.objects.filter(username=user.username)) > 0:
......@@ -1762,6 +1758,13 @@ def _do_create_account(form, custom_form=None, site=None):
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):
"""
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):
# Perform operations within a transaction that are critical to account creation
with transaction.atomic():
# 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 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):
raise ValidationError({'access_token': [error_message]})
# 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())
if settings.FEATURES.get('ENABLE_DISCUSSION_EMAIL_DIGEST'):
......@@ -2225,7 +2230,7 @@ def auto_auth(request):
# If successful, this will return a tuple containing
# the new user object.
try:
user, profile, reg = _do_create_account(form, site=request.site)
user, profile, reg = _do_create_account(form)
except (AccountValidationError, ValidationError):
# Attempt to retrieve the existing user.
user = User.objects.get(username=username)
......@@ -2252,6 +2257,8 @@ def auto_auth(request):
profile.year_of_birth = (year - age_limit) - 1
profile.save()
_create_or_set_user_attribute_created_on_site(user, request.site)
# Enroll the user in a course
course_key = None
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