diff --git a/evap/staff/tests/test_views.py b/evap/staff/tests/test_views.py index cd7132bc5..ba7a2e842 100644 --- a/evap/staff/tests/test_views.py +++ b/evap/staff/tests/test_views.py @@ -2386,6 +2386,25 @@ def test_invalid_deletion(self): self.app.post(self.url, user=self.manager, params=self.post_params, status=400) self.assertTrue(Evaluation.objects.filter(pk=self.evaluation.pk).exists()) + @patch.object(Evaluation, "can_be_deleted_by_manager", True) + def test_reward_point_granting_message(self): + already_evaluated = baker.make(Evaluation, course__semester=self.evaluation.course.semester) + SemesterActivation.objects.create(semester=self.evaluation.course.semester, is_active=True) + student = baker.make(UserProfile, evaluations_participating_in=[self.evaluation]) + + baker.make( + UserProfile, + email=iter(f"{name}@institution.example.com" for name in ["a", "b", "c", "d", "e"]), + evaluations_participating_in=[self.evaluation, already_evaluated], + evaluations_voted_for=[already_evaluated], + _quantity=5, + ) + + with patch("evap.staff.views.logger") as mock: + page = self.app.post(self.url, user=self.manager, params=self.post_params, status=200) + + mock.info.assert_called_with(f"Deletion of evaluation {self.evaluation} has created 5 reward point grantings") + class TestSingleResultEditView(WebTestStaffModeWith200Check): @classmethod diff --git a/evap/staff/views.py b/evap/staff/views.py index 54a7a915a..6aba3c3d3 100644 --- a/evap/staff/views.py +++ b/evap/staff/views.py @@ -1,5 +1,6 @@ import csv import itertools +import logging from collections import OrderedDict, defaultdict, namedtuple from collections.abc import Container from dataclasses import dataclass @@ -135,6 +136,8 @@ from evap.student.views import render_vote_page from evap.tools import unordered_groupby +logger = logging.getLogger(__name__) + @manager_required def index(request): @@ -671,6 +674,8 @@ def semester_make_active(request): @require_POST @manager_required def semester_delete(request): + # TODO(rebeling): Do we expect reward point granting here? Do we want to notify? I don't see why it couldn't happen + semester = get_object_from_dict_pk_entry_or_logged_40x(Semester, request.POST, "semester_id") if not semester.can_be_deleted_by_manager: @@ -1422,6 +1427,11 @@ def helper_single_result_edit(request, evaluation): def evaluation_delete(request): evaluation = get_object_from_dict_pk_entry_or_logged_40x(Evaluation, request.POST, "evaluation_id") + # See comment in helper_evaluation_edit + @receiver(RewardPointGranting.granted_by_evaluation_deletion, weak=True) + def notify_reward_points(grantings, **_kwargs): + logger.info(f"Deletion of evaluation {evaluation} has created {len(grantings)} reward point grantings") + if not evaluation.can_be_deleted_by_manager: raise SuspiciousOperation("Deleting evaluation not allowed") if evaluation.is_single_result: