Skip to content

Commit

Permalink
Draft: Notify on reward point granting when deleting evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
richardebeling committed Dec 21, 2024
1 parent b1cabd9 commit dd444a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions evap/staff/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions evap/staff/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dd444a3

Please sign in to comment.