Repository: e-valuation/EvaP

Issue:
Remind all
On the Todo list a button `Remind all` should be added, that allows to send reminders to all responsibles at once. This button opens a modal with a list of the responsibles, asking for confirmation. Confirming will then send all emails that would be sent by clicking the `Send reminder` buttons for all responsibles individually.


Discussion:

Resolving patch:
diff --git a/evap/staff/views.py b/evap/staff/views.py
--- a/evap/staff/views.py
+++ b/evap/staff/views.py
@@ -576,8 +576,17 @@ def semester_preparation_reminder(request, semester_id):
     responsible_list = [(responsible, [evaluation for evaluation in evaluations if responsible in evaluation.course.responsibles.all()],
                          responsible.delegates.all()) for responsible in responsibles]
 
-    template_data = dict(semester=semester, responsible_list=responsible_list)
-    return render(request, "staff_semester_preparation_reminder.html", template_data)
+    if request.method == "POST":
+        template = EmailTemplate.objects.get(name=EmailTemplate.EDITOR_REVIEW_REMINDER)
+        subject_params = {}
+        for responsible, evaluations, __ in responsible_list:
+            body_params = {"user": responsible, "evaluations": evaluations}
+            EmailTemplate.send_to_user(responsible, template, subject_params, body_params, use_cc=True, request=request)
+        messages.success(request, _("Successfully sent reminders to everyone."))
+        return HttpResponse()
+    else:
+        template_data = dict(semester=semester, responsible_list=responsible_list)
+        return render(request, "staff_semester_preparation_reminder.html", template_data)
 
 
 @manager_required


Test patch:
diff --git a/evap/staff/tests/test_views.py b/evap/staff/tests/test_views.py
--- a/evap/staff/tests/test_views.py
+++ b/evap/staff/tests/test_views.py
@@ -1,6 +1,7 @@
 import datetime
 import os
 import glob
+from unittest.mock import patch
 
 from django.conf import settings
 from django.contrib.auth.models import Group
@@ -512,6 +513,7 @@ def test_assign_questionnaires(self):
 class TestSemesterPreparationReminderView(WebTestWith200Check):
     url = '/staff/semester/1/preparation_reminder'
     test_users = ['manager']
+    csrf_checks = False
 
     @classmethod
     def setUpTestData(cls):
@@ -527,6 +529,22 @@ def test_preparation_reminder(self):
         self.assertContains(response, 'user_to_find')
         self.assertContains(response, 'name_to_find')
 
+    @patch("evap.staff.views.EmailTemplate.send_to_user")
+    def test_remind_all(self, send_to_user_mock):
+        user = mommy.make(UserProfile)
+        evaluation = mommy.make(Evaluation, course=mommy.make(Course, semester=self.semester, responsibles=[user]), state='prepared')
+
+        response = self.app.post(self.url, user='manager')
+        self.assertEqual(response.status_code, 200)
+
+        template = EmailTemplate.objects.get(name=EmailTemplate.EDITOR_REVIEW_REMINDER)
+        subject_params = {}
+        body_params = {"user": user, "evaluations": [evaluation]}
+        expected = (user, template, subject_params, body_params)
+
+        send_to_user_mock.assert_called_once()
+        self.assertEqual(send_to_user_mock.call_args_list[0][0][:4], expected)
+
 
 class TestSendReminderView(WebTest):
     url = '/staff/semester/1/responsible/3/send_reminder'