Repository: ephios-dev/ephios

Issue:
Send custom mails for events to responsibles as well
As a planner, I want to receive a copy of any custom mail that is sent out for this event so that I stay informed what has been communicated,


Discussion:

Resolving patch:
diff --git a/ephios/core/services/notifications/types.py b/ephios/core/services/notifications/types.py
--- a/ephios/core/services/notifications/types.py
+++ b/ephios/core/services/notifications/types.py
@@ -466,6 +466,21 @@ def send(cls, event: Event, content: str):
                     ),
                 )
             )
+        for responsible in get_users_with_perms(
+            event, with_superusers=False, only_with_perms_in=["change_event"]
+        ):
+            notifications.append(
+                Notification(
+                    slug=cls.slug,
+                    user=responsible,
+                    data=dict(
+                        email=responsible.email,
+                        event_id=event.id,
+                        content=content,
+                        event_title=event.title,
+                    ),
+                )
+            )
         Notification.objects.bulk_create(notifications)
 
     @classmethod


Test patch:
diff --git a/tests/core/test_event_notifications.py b/tests/core/test_event_notifications.py
--- a/tests/core/test_event_notifications.py
+++ b/tests/core/test_event_notifications.py
@@ -45,7 +45,9 @@ def test_mail_participants(self, django_app, event, volunteer, planner, groups):
         form["mail_content"] = "hey there"
         response = form.submit()
         assert response.status_code == 302
-        assert Notification.objects.count() == 1
+        assert Notification.objects.count() == 1 + len(
+            get_users_with_perms(event, only_with_perms_in=["change_event"])
+        )
 
     def test_mail_participants_content_required(
         self, django_app, event, volunteer, planner, groups
diff --git a/tests/core/test_notifications.py b/tests/core/test_notifications.py
--- a/tests/core/test_notifications.py
+++ b/tests/core/test_notifications.py
@@ -76,8 +76,7 @@ def test_participation_notification_sending(self, event, qualified_volunteer):
         ParticipationConfirmedNotification.send(participation)
         ParticipationRejectedNotification.send(participation)
         ResponsibleParticipationRequestedNotification(participation).send()
-        CustomEventParticipantNotification.send(event, "hi")
-        assert Notification.objects.count() == 3 + len(
+        assert Notification.objects.count() == 2 + len(
             get_users_with_perms(event, only_with_perms_in=["change_event"])
         )
         call_command("send_notifications")
@@ -155,3 +154,16 @@ def test_consequence_notifications(self, volunteer, workinghours_consequence):
         assert Notification.objects.count() == 2
         call_command("send_notifications")
         assert Notification.objects.count() == 0
+
+    def test_responsibles_receive_custom_notification(
+        self, django_app, qualified_volunteer, planner, event
+    ):
+        self._enable_all_notifications(qualified_volunteer)
+        participation = LocalParticipation.objects.create(
+            shift=event.shifts.first(),
+            user=qualified_volunteer,
+            state=AbstractParticipation.States.CONFIRMED,
+        )
+        CustomEventParticipantNotification.send(event, "test notification")
+        assert planner.has_perm("change_event", event)
+        assert Notification.objects.get(user=planner)