Skip to content

Commit

Permalink
refactor: change emails name for individual_emails
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Oct 10, 2023
1 parent 9adfd5c commit c0dc16b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.20 on 2023-09-04 14:11
# Generated by Django 3.2.21 on 2023-10-10 14:30

from django.db import migrations, models

Expand All @@ -13,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='target',
name='target_type',
field=models.CharField(choices=[('myself', 'Myself'), ('staff', 'Staff and instructors'), ('learners', 'All students'), ('cohort', 'Specific cohort'), ('track', 'Specific course mode'), ('individual-students', 'Specific list of students')], max_length=64),
field=models.CharField(choices=[('myself', 'Myself'), ('staff', 'Staff and instructors'), ('learners', 'All students'), ('cohort', 'Specific cohort'), ('track', 'Specific course mode'), ('individual-learners', 'Specific list of students')], max_length=64),
),
]

This file was deleted.

4 changes: 2 additions & 2 deletions lms/djangoapps/bulk_email/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def long_display(self):
else:
return self.get_target_type_display()

def get_users(self, course_id, user_id=None, emails=None):
def get_users(self, course_id, user_id=None, individual_emails=None):
"""
Gets the users for a given target.
Expand Down Expand Up @@ -152,7 +152,7 @@ def get_users(self, course_id, user_id=None, emails=None):
elif self.target_type == SEND_TO_INDIVIDUAL_LEARNERS:
return use_read_replica_if_available(
User.objects.filter(
models.Q(email__in=emails)
models.Q(email__in=individual_emails)
& enrollment_query
)
)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/bulk_email/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def perform_delegate_email_batches(entry_id, course_id, task_input, action_name)
global_email_context = _get_course_email_context(course)

recipient_qsets = [
target.get_users(course_id, user_id, task_input.get("emails", []))
target.get_users(course_id, user_id, task_input.get("individual_emails", []))
for target in targets
]
# Use union here to combine the qsets instead of the | operator. This avoids generating an
Expand Down
16 changes: 14 additions & 2 deletions lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def setUp(self):
('update_forum_role_membership',
{'unique_student_identifier': self.user.email, 'rolename': 'Moderator', 'action': 'allow'}),
('list_forum_members', {'rolename': FORUM_ROLE_COMMUNITY_TA}),
('send_email', {'send_to': '["staff"]', 'subject': 'test', 'message': 'asdf'}),
('send_email', {'send_to': '["staff"]', 'individual_learners_emails': '[]' ,'subject': 'test', 'message': 'asdf'}),
('list_instructor_tasks', {}),
('instructor_api_v1:list_instructor_tasks', {}),
('list_background_email_tasks', {}),
Expand Down Expand Up @@ -3409,6 +3409,7 @@ def setUp(self):
test_message = '\u6824 test message'
self.full_test_message = {
'send_to': '["myself", "staff"]',
'individual_learners_emails': '[]',
'subject': test_subject,
'message': test_message,
}
Expand Down Expand Up @@ -3444,6 +3445,16 @@ def test_send_email_but_course_not_exist(self):
response = self.client.post(url, self.full_test_message)
assert response.status_code != 200

def test_send_email_to_individual_learners_emails(self):
url = reverse('send_email', kwargs={'course_id': str(self.course.id)})
response = self.client.post(url, {
'send_to': '["individual-learners"]',
'individual_learners_emails': '["[email protected]"]',
'subject': 'test subject',
'message': 'test message',
})
assert response.status_code == 200

def test_send_email_no_sendto(self):
url = reverse('send_email', kwargs={'course_id': str(self.course.id)})
response = self.client.post(url, {
Expand All @@ -3456,6 +3467,7 @@ def test_send_email_invalid_sendto(self):
url = reverse('send_email', kwargs={'course_id': str(self.course.id)})
response = self.client.post(url, {
'send_to': '["invalid_target", "staff"]',
'individual_learners_emails': '[]',
'subject': 'test subject',
'message': 'test message',
})
Expand Down Expand Up @@ -3519,7 +3531,7 @@ def test_send_email_with_schedule(self, mock_task_api):
response = self.client.post(url, self.full_test_message)

assert response.status_code == 200
_, _, _, arg_schedule = mock_task_api.call_args.args
_, _, _, arg_schedule, _ = mock_task_api.call_args.args
assert arg_schedule == expected_schedule

@patch("lms.djangoapps.instructor.views.api.task_api.submit_bulk_course_email")
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ def send_email(request, course_id):
return HttpResponseForbidden("Email is not enabled for this course.")

targets = json.loads(request.POST.get("send_to"))
emails = json.loads(request.POST.get("individual_learners_emails", []))
individual_emails = json.loads(request.POST.get("individual_learners_emails", "[]"))
subject = request.POST.get("subject")
message = request.POST.get("message")
# optional, this is a date and time in the form of an ISO8601 string
Expand Down Expand Up @@ -2747,7 +2747,7 @@ def send_email(request, course_id):
return HttpResponseBadRequest(repr(err))

# Submit the task, so that the correct InstructorTask object gets created (for monitoring purposes)
task_api.submit_bulk_course_email(request, course_id, email.id, schedule_dt, emails)
task_api.submit_bulk_course_email(request, course_id, email.id, schedule_dt, individual_emails)

response_payload = {
'course_id': str(course_id),
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/instructor_task/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def submit_delete_entrance_exam_state_for_student(request, usage_key, student):
return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)


def submit_bulk_course_email(request, course_key, email_id, schedule=None, emails=[]):
def submit_bulk_course_email(request, course_key, email_id, schedule=None, individual_emails=[]):
"""
Request to have bulk email sent as a background task.
Expand All @@ -324,7 +324,7 @@ def submit_bulk_course_email(request, course_key, email_id, schedule=None, email

task_type = InstructorTaskTypes.BULK_COURSE_EMAIL
task_class = send_bulk_course_email
task_input = {'email_id': email_id, 'to_option': targets, 'emails': emails}
task_input = {'email_id': email_id, 'to_option': targets, 'individual_emails': individual_emails}
task_key_stub = str(email_id)
# create the key value by using MD5 hash:
task_key = hashlib.md5(task_key_stub.encode('utf-8')).hexdigest()
Expand Down

0 comments on commit c0dc16b

Please sign in to comment.