diff --git a/changelog.d/2979.fixed.md b/changelog.d/2979.fixed.md new file mode 100644 index 0000000000..fb7ac7737d --- /dev/null +++ b/changelog.d/2979.fixed.md @@ -0,0 +1 @@ +Fix crash bug when reordering filters within a filter group in Alert Profiles diff --git a/python/nav/web/alertprofiles/views.py b/python/nav/web/alertprofiles/views.py index aa888d560d..fcd2181ff1 100644 --- a/python/nav/web/alertprofiles/views.py +++ b/python/nav/web/alertprofiles/views.py @@ -2050,7 +2050,7 @@ def filter_group_addfilter(request): def filter_group_remove_or_move_filter(request): """Deletes or moves around a filter within a filter group""" post = request.POST.copy() - for name in post: + for name in request.POST: if name.find("=") != -1: attribute, value = name.split("=") del post[name] diff --git a/tests/integration/web/alertprofiles_test.py b/tests/integration/web/alertprofiles_test.py index 9ef91afcf3..d68288e517 100644 --- a/tests/integration/web/alertprofiles_test.py +++ b/tests/integration/web/alertprofiles_test.py @@ -1029,6 +1029,23 @@ def test_alertprofiles_remove_filter_group(self, db, client, dummy_filter_group) assert dummy_filter_group.name in smart_str(response.content) assert FilterGroup.objects.filter(pk=dummy_filter_group.pk).count() == 1 + def test_alertprofiles_move_filter_within_group_should_not_crash( + self, db, client, dummy_filter_group + ): + """Regression test for #2979: Ensuring that pre-processing of request data + doesn't crash unexpectedly. + """ + url = reverse('alertprofiles-filter_groups-removefilter') + response = client.post( + url, + follow=True, + data={ + "moveup=23": "Move+up", + "id": dummy_filter_group.id, + }, + ) + assert response.status_code in (200, 404) + # # fixtures and helpers