Merge pull request #25586 from edx/saleem-latif/ENT-3680-fix

ENT-3680: Do not send email if profile not created, this code path is run as a result UserPreference save signal before profile is created.
This commit is contained in:
Saleem Latif
2020-11-16 11:59:07 +05:00
committed by GitHub
2 changed files with 9 additions and 1 deletions

View File

@@ -173,6 +173,10 @@ def email_marketing_user_field_changed(sender, user=None, table=None, setting=No
if user.is_anonymous:
return
# Ignore users that do not yet have a profile
if not hasattr(user, 'profile'):
return
# ignore anything but User, Profile or UserPreference tables
if table not in {'auth_user', 'auth_userprofile', 'user_api_userpreference'}:
return

View File

@@ -30,7 +30,7 @@ from lms.djangoapps.email_marketing.tasks import (
update_user_email
)
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from common.djangoapps.student.models import Registration
from common.djangoapps.student.models import Registration, User
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory, UserProfileFactory
from common.djangoapps.util.json_request import JsonResponse
@@ -336,6 +336,10 @@ class EmailMarketingTests(TestCase):
email_marketing_user_field_changed(None, user=anon)
self.assertFalse(mock_log_error.called)
user = User(username='test', email='test@example.com')
email_marketing_user_field_changed(None, user=user)
self.assertFalse(mock_log_error.called)
@patch('lms.djangoapps.email_marketing.tasks.SailthruClient.api_post')
def test_change_email(self, mock_sailthru):
"""