-
Notifications
You must be signed in to change notification settings - Fork 168
2604 preparation reminder for internal users #2688
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
base: main
Are you sure you want to change the base?
Changes from all commits
ea812b1
b0508fb
12bf155
51bcd33
03a99f0
128b933
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1064,6 +1064,27 @@ def test_remind_all(self, email_template_mock) -> None: | |
| self.assertEqual(kwargs["body_params"], {"user": self.user, "evaluations": [self.evaluation]}) | ||
| self.assertEqual(kwargs["use_cc"], True) | ||
|
|
||
| @patch("evap.staff.views.EmailTemplate") | ||
| def test_remind_all_internal_only(self, email_template_mock) -> None: | ||
| self.user.email = "responsible@institution.example.com" | ||
| self.user.save() | ||
|
|
||
| external_responsible = baker.make(UserProfile, email="external@external.example.com") | ||
| baker.make( | ||
| Evaluation, | ||
| course=baker.make(Course, semester=self.semester, responsibles=[external_responsible]), | ||
| state=Evaluation.State.PREPARED, | ||
| ) | ||
|
|
||
| email_template_mock.objects.get.return_value = email_template_mock | ||
| email_template_mock.EDITOR_REVIEW_REMINDER = EmailTemplate.EDITOR_REVIEW_REMINDER | ||
|
|
||
| self.app.post(self.url, params={"internal_only": "true"}, user=self.manager, status=200) | ||
|
|
||
| recipients = [call[0][0] for call in email_template_mock.send_to_user.call_args_list] | ||
| self.assertIn(self.user, recipients) | ||
| self.assertNotIn(external_responsible, recipients) | ||
|
Comment on lines
+1079
to
+1086
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be less code to not patch the email templates and just check mail.outbox afterwards? If so, let's do that (otherwise, ignore). |
||
|
|
||
| def test_invalid_mode(self) -> None: | ||
| self.app.get(self.url, params={"mode": "invalid"}, user=self.manager, status=400) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -959,13 +959,16 @@ def semester_questionnaire_assign(request, semester_id): | |
| @manager_required | ||
| def semester_preparation_reminder(request: HttpRequest, semester_id: int) -> HttpResponse: | ||
| semester = get_object_or_404(Semester, id=semester_id) | ||
| internal_only = request.POST.get("internal_only") == "true" | ||
|
|
||
| evaluations = semester.evaluations.filter( | ||
| state__in=[Evaluation.State.PREPARED, Evaluation.State.EDITOR_APPROVED] | ||
| ).prefetch_related("course__programs") | ||
|
|
||
| prepared_evaluations = semester.evaluations.filter(state=Evaluation.State.PREPARED) | ||
| responsibles = UserProfile.objects.filter(courses_responsible_for__evaluations__in=prepared_evaluations).distinct() | ||
| if internal_only: | ||
| responsibles = responsibles.exclude(pk__in=[r.pk for r in responsibles if r.is_external]) | ||
|
Comment on lines
+970
to
+971
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Above, you access I think for maintainability, it makes sense to put this check inside this block. That way, we keep the queries simple, save one database roundtrip, don't build large SQL, and the world is greener. The code change would then just be if request.POST.get("internal_only") == "true" and responsible.is_external:
continue |
||
|
|
||
| responsible_list = [ | ||
| ( | ||
|
|
@@ -981,7 +984,7 @@ def semester_preparation_reminder(request: HttpRequest, semester_id: int) -> Htt | |
| for responsible, evaluations, __ in responsible_list: | ||
| body_params = {"user": responsible, "evaluations": evaluations} | ||
| template.send_to_user(responsible, subject_params={}, body_params=body_params, use_cc=True, request=request) | ||
| messages.success(request, _("Successfully sent reminders to everyone.")) | ||
| messages.success(request, _("Successfully sent reminders.")) | ||
|
Comment on lines
-984
to
+987
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. two different success messages for the two cases would be nice |
||
| return HttpResponse() | ||
| mode = request.GET.get("mode", "interactive") | ||
| if mode not in ["interactive", "text"]: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
idhere,remindAllInternalUsersButton, is never used. Let's remove it.While you're at it, the same is true for
remindAllButtonabove.