Fix email will not sent to white-label users
White label partners reported that the users are receiving edX welcome emails at the time of signup.To solve it, a check is added that will assure, only edX users will receive the welcome email. LEARNER-1466 changes requested update update updated
This commit is contained in:
@@ -95,7 +95,7 @@ def update_user(self, sailthru_vars, email, site=None, new_user=False):
|
||||
return
|
||||
|
||||
# if new user, send welcome email
|
||||
if new_user and email_config.sailthru_welcome_template:
|
||||
if new_user and email_config.sailthru_welcome_template and is_default_site(site):
|
||||
scheduled_datetime = datetime.utcnow() + timedelta(seconds=email_config.welcome_email_send_delay)
|
||||
try:
|
||||
sailthru_response = sailthru_client.api_post(
|
||||
@@ -120,6 +120,17 @@ def update_user(self, sailthru_vars, email, site=None, new_user=False):
|
||||
max_retries=email_config.sailthru_max_retries)
|
||||
|
||||
|
||||
def is_default_site(site):
|
||||
"""
|
||||
Checks whether the site is a default site or a white-label
|
||||
Args:
|
||||
site: A dict containing the site info
|
||||
Returns:
|
||||
Boolean
|
||||
"""
|
||||
return not site or site.get('id') == settings.SITE_ID
|
||||
|
||||
|
||||
# pylint: disable=not-callable
|
||||
@task(bind=True, default_retry_delay=3600, max_retries=24)
|
||||
def update_user_email(self, new_email, old_email):
|
||||
@@ -184,7 +195,7 @@ def _get_or_create_user_list_for_site(sailthru_client, site=None, default_list_n
|
||||
:param: default_list_name
|
||||
:return: list name if exists or created else return None
|
||||
"""
|
||||
if site and site.get('id') != settings.SITE_ID:
|
||||
if not is_default_site(site):
|
||||
list_name = site.get('domain', '').replace(".", "_") + "_user_list"
|
||||
else:
|
||||
list_name = default_list_name
|
||||
|
||||
@@ -191,6 +191,23 @@ class EmailMarketingTests(TestCase):
|
||||
self.assertEquals(userparms['template'], "Welcome")
|
||||
self.assertEquals(userparms['schedule_time'], expected_schedule.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
||||
|
||||
@patch('email_marketing.tasks.log.error')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_post')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_get')
|
||||
def test_email_not_sent_to_white_label(self, mock_sailthru_get, mock_sailthru_post, mock_log_error):
|
||||
"""
|
||||
tests that welcome email is not sent to the white-label site learner
|
||||
"""
|
||||
white_label_site = Site.objects.create(domain='testwhitelabel.com', name='White Label')
|
||||
site_dict = {'id': white_label_site.id, 'domain': white_label_site.domain, 'name': white_label_site.name}
|
||||
mock_sailthru_post.return_value = SailthruResponse(JsonResponse({'ok': True}))
|
||||
mock_sailthru_get.return_value = SailthruResponse(JsonResponse({'lists': [{'name': 'new list'}], 'ok': True}))
|
||||
update_user.delay(
|
||||
{'gender': 'm', 'username': 'test', 'activated': 1}, TEST_EMAIL, site_dict, new_user=True
|
||||
)
|
||||
self.assertFalse(mock_log_error.called)
|
||||
self.assertNotEqual(mock_sailthru_post.call_args[0][0], "send")
|
||||
|
||||
@patch('email_marketing.tasks.SailthruClient.api_post')
|
||||
@patch('email_marketing.tasks.SailthruClient.api_get')
|
||||
def test_add_user_list_existing_domain(self, mock_sailthru_get, mock_sailthru_post):
|
||||
|
||||
Reference in New Issue
Block a user