-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from hmpf/filter-by-event-type-list
* Change filtering by event type to a list When filtering notifications we have the choice to filter one event type This change makes it to filter by a list, so that we can get notifications about events of multiple types * Change docs to show filtering by event type list * Amend tests to filtering by event type list * Add more tests for filtering by event types * Add tests for posting filter with event types * Migrate: change filter.event_type from str to list * Hide event_type from V1 Filter API, it should never have been visible anyway. * Move FilterPreviewSerializer to where it belongs --------- Co-authored-by: Johanna England <[email protected]>
- Loading branch information
Showing
17 changed files
with
313 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add filtering of events by a list of event types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Removed `"event_type"` from the V1 Filter API, it should only have been | ||
available in V2 (since it was new) and it has never been in use by the | ||
frontend. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/argus/notificationprofile/migrations/0017_change_event_type_to_event_types.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.11 on 2024-05-14 07:51 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def change_event_type_to_a_list_in_filter(apps, schema_editor): | ||
Filter = apps.get_model("argus_notificationprofile", "Filter") | ||
|
||
for filter_ in Filter.objects.filter(filter__event_type__isnull=False): | ||
if filter_.filter["event_type"]: | ||
filter_.filter["event_types"] = [filter_.filter["event_type"]] | ||
filter_.save() | ||
del filter_.filter["event_type"] | ||
filter_.save() | ||
|
||
|
||
def change_event_types_to_a_string_in_filter(apps, schema_editor): | ||
# will lose data | ||
Filter = apps.get_model("argus_notificationprofile", "Filter") | ||
|
||
for filter_ in Filter.objects.filter(filter__event_types__isnull=False): | ||
if filter_.filter["event_types"]: | ||
filter_.filter["event_type"] = filter_.filter["event_types"][0] | ||
filter_.save() | ||
del filter_.filter["event_types"] | ||
filter_.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("argus_notificationprofile", "0016_noop"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
change_event_type_to_a_list_in_filter, | ||
change_event_types_to_a_string_in_filter, | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,6 @@ | ||
from rest_framework import serializers | ||
|
||
from argus.incident.constants import INCIDENT_LEVELS | ||
from argus.incident.models import Event | ||
|
||
|
||
class FilterBlobSerializer(serializers.Serializer): | ||
sourceSystemIds = serializers.ListField( | ||
child=serializers.IntegerField(min_value=1), | ||
allow_empty=True, | ||
required=False, | ||
) | ||
tags = serializers.ListField( | ||
child=serializers.CharField(min_length=3), | ||
allow_empty=True, | ||
required=False, | ||
) | ||
open = serializers.BooleanField(required=False, allow_null=True) | ||
acked = serializers.BooleanField(required=False, allow_null=True) | ||
stateful = serializers.BooleanField(required=False, allow_null=True) | ||
maxlevel = serializers.IntegerField( | ||
required=False, allow_null=True, max_value=max(INCIDENT_LEVELS), min_value=min(INCIDENT_LEVELS) | ||
) | ||
event_type = serializers.ChoiceField(choices=Event.Type.choices, required=False, allow_null=True) | ||
|
||
|
||
class FilterPreviewSerializer(serializers.Serializer): | ||
sourceSystemIds = serializers.ListField(child=serializers.IntegerField(min_value=1), allow_empty=True) | ||
tags = serializers.ListField(child=serializers.CharField(min_length=3), allow_empty=True) | ||
class CustomMultipleChoiceField(serializers.MultipleChoiceField): | ||
def to_internal_value(self, value): | ||
return list(super().to_internal_value(value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import connection | ||
from django.db.migrations.executor import MigrationExecutor | ||
|
||
|
||
class Migrator: | ||
def __init__(self, connection=connection): | ||
self.executor = MigrationExecutor(connection) | ||
|
||
def migrate(self, app_label: str, migration: str): | ||
target = [(app_label, migration)] | ||
self.executor.loader.build_graph() | ||
self.executor.migrate(target) | ||
self.apps = self.executor.loader.project_state(target).apps |
Empty file.
Oops, something went wrong.