Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-2020-09-08 #425

Merged
merged 4 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lms/djangoapps/bulk_email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from celery.states import FAILURE, RETRY, SUCCESS
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.mail import EmailMultiAlternatives, get_connection
from django.core.mail.message import forbid_multi_line_headers
from django.urls import reverse
Expand All @@ -49,6 +50,7 @@
update_subtask_status
)
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.lib.celery.task_utils import emulate_http_request
from openedx.core.lib.courses import course_image_url
from util.date_utils import get_default_time_display

Expand Down Expand Up @@ -109,16 +111,17 @@ def _get_course_email_context(course):
course_root
)
lms_url = settings.LMS_ROOT_URL
logo_url = get_logo_url()
logo_url = get_logo_url(is_secure=(not settings.DEBUG))
image_url = u'{}{}'.format(settings.LMS_ROOT_URL, course_image_url(course))

email_context = {
'course_title': course_title,
'course_root': course_root,
'course_language': course.language,
'course_url': course_url,
'course_image_url': image_url,
'lms_url': lms_url,
'logo_url': logo_url,
'lms_url': lms_url,
'logo_url': logo_url,
'course_end_date': course_end_date,
'account_settings_url': '{}{}'.format(settings.LMS_ROOT_URL, reverse('account_settings')),
'email_settings_url': '{}{}'.format(settings.LMS_ROOT_URL, reverse('dashboard')),
Expand All @@ -137,6 +140,7 @@ def perform_delegate_email_batches(entry_id, course_id, task_input, action_name)
# Get inputs to use in this task from the entry.
user_id = entry.requester.id
task_id = entry.task_id
site_id = task_input.get('site', None)

# Perfunctory check, since expansion is made for convenience of other task
# code that doesn't need the entry_id.
Expand Down Expand Up @@ -178,7 +182,16 @@ def perform_delegate_email_batches(entry_id, course_id, task_input, action_name)

# Get arguments that will be passed to every subtask.
targets = email_obj.targets.all()
global_email_context = _get_course_email_context(course)

# [UCSD_CUSTOM]
# If `site_id` was passed in the task_input, get the site and derive
# context as per the provided site, otherwise simply get the email
# context.
try:
with emulate_http_request(site=Site.objects.get(id=site_id), user=entry.requester):
global_email_context = _get_course_email_context(course)
except Site.DoesNotExist:
global_email_context = _get_course_email_context(course)

recipient_qsets = [
target.get_users(course_id, user_id)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor_task/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def submit_bulk_course_email(request, course_key, email_id):

task_type = 'bulk_course_email'
task_class = send_bulk_course_email
task_input = {'email_id': email_id, 'to_option': targets}
task_input = {'email_id': email_id, 'to_option': targets, 'site': request.site.id}
task_key_stub = str(email_id)
# create the key value by using MD5 hash:
task_key = hashlib.md5(task_key_stub).hexdigest()
Expand Down
4 changes: 3 additions & 1 deletion lms/djangoapps/instructor_task/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ def _test_resubmission(self, api_call):
api_call()

def test_submit_bulk_email_all(self):
request = self.create_task_request(self.instructor)
request.site.id = None
email_id = self._define_course_email()
api_call = lambda: submit_bulk_course_email(
self.create_task_request(self.instructor),
request,
self.course.id,
email_id
)
Expand Down