From 74ede00f514b44236e08ac6cf9ac0dc6da8efa45 Mon Sep 17 00:00:00 2001 From: ezkat <50319957+ezkat@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:51:11 +0200 Subject: [PATCH 1/2] Don't send notification on blocked reservation type --- resources/models/reservation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/models/reservation.py b/resources/models/reservation.py index db9b7f85c..3e3489ecd 100644 --- a/resources/models/reservation.py +++ b/resources/models/reservation.py @@ -756,6 +756,9 @@ def send_reservation_mail(self, notification_type, user=None, attachments=None, staff_email=None, extra_context={}, is_reminder = False): + if self.type == Reservation.TYPE_BLOCKED: + return + notification_template = self.get_notification_template(notification_type) if self.user and not user: # If user isn't given use self.user. user = self.user From 5c7a5c33e8b1dc55aef4f117e857bdd269ef718a Mon Sep 17 00:00:00 2001 From: ezkat <50319957+ezkat@users.noreply.github.com> Date: Wed, 13 Dec 2023 08:39:08 +0200 Subject: [PATCH 2/2] Add test --- resources/tests/test_reservation_api.py | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/resources/tests/test_reservation_api.py b/resources/tests/test_reservation_api.py index 787e38e5a..971d53d01 100644 --- a/resources/tests/test_reservation_api.py +++ b/resources/tests/test_reservation_api.py @@ -226,6 +226,16 @@ def reservation_created_notification(): body='Normal reservation created body.', ) +@pytest.fixture +def reservation_created_by_official_notification(): + with translation.override('fi'): # Staff user preferred language is always fallback. (fi) + return NotificationTemplate.objects.create( + type=NotificationType.RESERVATION_CREATED_BY_OFFICIAL, + is_default_template=True, + short_message = 'Virkailija on luonut varauksen lyhyt viesti.', + subject = 'Virkailija on luonut varauksen aihe.', + body = 'Virkailija on luonut varauksen viesti.' + ) @pytest.fixture def reservation_modified_by_official_notification(): @@ -3314,3 +3324,21 @@ def test_reservation_reminder_create( response = api_client.post(list_url, data=reservation_data, HTTP_ACCEPT_LANGUAGE='en') assert response.status_code == 201 assert ReservationReminder.objects.count() == 1 + + +@override_settings(RESPA_MAILS_ENABLED=True) +@pytest.mark.django_db +def test_no_notification_on_reservation_type_blocked( + resource_in_unit, reservation_data, + staff_api_client, staff_user, list_url, + reservation_created_by_official_notification): + UnitAuthorization.objects.create(subject=resource_in_unit.unit, + level=UnitAuthorizationLevel.manager, authorized=staff_user) + + reservation_data['resource'] = resource_in_unit.pk + reservation_data['reserver_name'] = 'Staff reservation normal' + reservation_data['type'] = Reservation.TYPE_BLOCKED + + response = staff_api_client.post(list_url, data=reservation_data, format='json') + assert response.status_code == 201 + assert len(mail.outbox) == 0 \ No newline at end of file