feat: reposition code to set is_marketable (#30839)
This commit is contained in:
@@ -213,6 +213,7 @@ def create_account_with_params(request, params): # pylint: disable=too-many-sta
|
||||
tos_required=tos_required,
|
||||
)
|
||||
custom_form = get_registration_extension_form(data=params)
|
||||
is_marketable = params.get('marketing_emails_opt_in') in ['true', '1']
|
||||
|
||||
# Perform operations within a transaction that are critical to account creation
|
||||
with outer_atomic():
|
||||
@@ -227,6 +228,17 @@ def create_account_with_params(request, params): # pylint: disable=too-many-sta
|
||||
django_login(request, new_user)
|
||||
request.session.set_expiry(0)
|
||||
|
||||
try:
|
||||
_record_is_marketable_attribute(is_marketable, new_user)
|
||||
# Don't prevent a user from registering if is_marketable is not being set.
|
||||
# Also update the is_marketable value to None so that it is consistent with
|
||||
# our database when we send it to segment.
|
||||
except Exception: # pylint: disable=broad-except
|
||||
log.exception('Error while setting is_marketable attribute.')
|
||||
is_marketable = None
|
||||
|
||||
_track_user_registration(user, profile, params, third_party_provider, registration, is_marketable)
|
||||
|
||||
# Sites using multiple languages need to record the language used during registration.
|
||||
# If not, compose_and_send_activation_email will be sent in site's default language only.
|
||||
create_or_set_user_attribute_created_on_site(user, request.site)
|
||||
@@ -253,9 +265,6 @@ def create_account_with_params(request, params): # pylint: disable=too-many-sta
|
||||
except Exception: # pylint: disable=broad-except
|
||||
log.exception(f"Enable discussion notifications failed for user {user.id}.")
|
||||
|
||||
is_marketable = params.get('marketing_emails_opt_in') in ['true', '1']
|
||||
_track_user_registration(user, profile, params, third_party_provider, registration, is_marketable)
|
||||
|
||||
# Announce registration
|
||||
REGISTER_USER.send(sender=None, user=user, registration=registration)
|
||||
|
||||
@@ -276,7 +285,6 @@ def create_account_with_params(request, params): # pylint: disable=too-many-sta
|
||||
|
||||
try:
|
||||
_record_registration_attributions(request, new_user)
|
||||
_record_is_marketable_attribute(is_marketable, new_user)
|
||||
# Don't prevent a user from registering due to attribution errors.
|
||||
except Exception: # pylint: disable=broad-except
|
||||
log.exception('Error while attributing cookies to user registration.')
|
||||
|
||||
@@ -17,6 +17,7 @@ from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from pytz import UTC
|
||||
from social_django.models import Partial, UserSocialAuth
|
||||
from testfixtures import LogCapture
|
||||
from openedx_events.tests.utils import OpenEdxEventsTestMixin
|
||||
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
@@ -2285,6 +2286,37 @@ class RegistrationViewTestV2(RegistrationViewTestV1):
|
||||
)
|
||||
self._assert_redirect_url(response, expected_redirect)
|
||||
|
||||
@mock.patch('openedx.core.djangoapps.user_authn.views.register._record_is_marketable_attribute')
|
||||
def test_logs_for_error_when_setting_is_marketable_attribute(self, set_is_marketable_attr):
|
||||
"""
|
||||
Test that if some error occurs while setting is_marketable attribute, error
|
||||
is logged and that it doesn't affect the user registration workflow.
|
||||
"""
|
||||
set_is_marketable_attr.side_effect = Exception('BOOM!')
|
||||
post_params = {
|
||||
"email": self.EMAIL,
|
||||
"name": self.NAME,
|
||||
"username": self.USERNAME,
|
||||
"password": self.PASSWORD,
|
||||
"honor_code": "true",
|
||||
}
|
||||
|
||||
with LogCapture() as logger:
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
post_params,
|
||||
HTTP_ACCEPT='*/*',
|
||||
)
|
||||
logger.check_present(
|
||||
(
|
||||
'edx.student',
|
||||
'ERROR',
|
||||
'Error while setting is_marketable attribute.'
|
||||
)
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@httpretty.activate
|
||||
@ddt.ddt
|
||||
|
||||
Reference in New Issue
Block a user