Skip to content

Commit bee6399

Browse files
Make it impossible to set event types to empty
This would result in no notifications ever being sent
1 parent e74c05a commit bee6399

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/api.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,11 @@ Notification profile endpoints
713713
}
714714
}
715715
716+
.. note::
717+
``event_types`` cannot be ``null`` or ``[]``, because all events have an event
718+
type set, which would therefore result in no notifications ever being sent.
719+
For not filtering by ``event_types`` the key needs to be removed.
720+
716721

717722
- ``/api/v1/notificationprofiles/filters/<int:pk>/``:
718723

@@ -1490,6 +1495,11 @@ Notification profile endpoints
14901495
}
14911496
}
14921497
1498+
.. note::
1499+
``event_types`` cannot be ``null`` or ``[]``, because all events have an event
1500+
type set, which would therefore result in no notifications ever being sent.
1501+
For not filtering by ``event_types`` the key needs to be removed.
1502+
14931503

14941504
- ``/api/v2/notificationprofiles/filters/<int:pk>/``:
14951505

src/argus/notificationprofile/primitive_serializers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class FilterBlobSerializer(serializers.Serializer):
3131
required=False,
3232
)
3333

34+
def validate_event_types(self, value):
35+
if not value:
36+
raise serializers.ValidationError("Event types cannot be empty, remove it completely from filter instead.")
37+
return value
38+
3439

3540
class FilterPreviewSerializer(serializers.Serializer):
3641
sourceSystemIds = serializers.ListField(child=serializers.IntegerField(min_value=1), allow_empty=True)

tests/notificationprofile/test_views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ def test_should_create_filter_with_event_types(self):
403403
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
404404
self.assertTrue(Filter.objects.filter(pk=response.data["pk"]).exists())
405405

406+
def test_should_not_create_filter_with_empty_event_types(self):
407+
filter_name = "test-filter"
408+
response = self.user1_rest_client.post(
409+
path=self.ENDPOINT,
410+
data={
411+
"name": filter_name,
412+
"filter": {"event_types": []},
413+
},
414+
)
415+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
416+
406417
def test_should_update_filter_name_with_valid_values(self):
407418
filter1_pk = self.filter1.pk
408419
filter1_path = f"{self.ENDPOINT}{filter1_pk}/"

0 commit comments

Comments
 (0)