From 50831da9aa9589913bbf2e40ca0945a6e8fff504 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Fri, 19 Nov 2021 11:20:30 +0100 Subject: [PATCH] [#943] Added filter to hide AVG TimelineLogProxies from Submission change view --- src/openforms/logging/models.py | 8 +++++++- src/openforms/submissions/admin.py | 2 ++ src/openforms/submissions/tests/test_admin.py | 20 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/openforms/logging/models.py b/src/openforms/logging/models.py index febd97f5d2..e70409afdf 100644 --- a/src/openforms/logging/models.py +++ b/src/openforms/logging/models.py @@ -19,6 +19,12 @@ class TimelineLogProxyQueryset(models.QuerySet): def filter_event(self, event: str): return self.filter(extra_data__log_event=event) + def has_tag(self, tag: str): + return self.filter(extra_data__contains={tag: True}) + + def exclude_tag(self, tag: str): + return self.exclude(extra_data__contains={tag: True}) + class TimelineLogProxy(TimelineLog): objects = TimelineLogProxyQueryset.as_manager() @@ -139,7 +145,7 @@ def message(self) -> str: class AVGTimelineLogProxyManager(models.Manager): def get_queryset(self): qs = super().get_queryset() - return qs.filter(extra_data__contains={TimelineLogTags.AVG: True}) + return qs.has_tag(TimelineLogTags.AVG) class AVGTimelineLogProxy(TimelineLogProxy): diff --git a/src/openforms/submissions/admin.py b/src/openforms/submissions/admin.py index e4aa3f0c05..a86ace9af7 100644 --- a/src/openforms/submissions/admin.py +++ b/src/openforms/submissions/admin.py @@ -9,6 +9,7 @@ from privates.views import PrivateMediaView from openforms.appointments.models import AppointmentInfo +from openforms.logging.constants import TimelineLogTags from openforms.logging.logevent import ( submission_details_view_admin, submission_export_list as log_export_submissions, @@ -116,6 +117,7 @@ class SubmissionLogInline(GenericTabularInline): def get_queryset(self, request): qs = super().get_queryset(request) + qs = qs.exclude_tag(TimelineLogTags.AVG) return qs.prefetch_related( "content_object", "content_object__form" ).select_related("user") diff --git a/src/openforms/submissions/tests/test_admin.py b/src/openforms/submissions/tests/test_admin.py index ef95ce811b..f9b8fc8b6e 100644 --- a/src/openforms/submissions/tests/test_admin.py +++ b/src/openforms/submissions/tests/test_admin.py @@ -8,6 +8,7 @@ from openforms.accounts.tests.factories import UserFactory from openforms.forms.tests.factories import FormDefinitionFactory, FormStepFactory +from openforms.logging.logevent import submission_start from openforms.logging.models import TimelineLogProxy from ..constants import RegistrationStatuses @@ -217,3 +218,22 @@ def test_retry_processing_submissions_only_resends_failed_submissions( on_completion_retry_mock.assert_called_once_with(failed.id) on_completion_retry_mock.return_value.delay.assert_called_once() + + def test_change_view_displays_logs_if_not_avg(self): + # add regular submission log + submission_start(self.submission_1) + + # viewing this generates an AVG log + response = self.app.get( + reverse( + "admin:submissions_submission_change", args=(self.submission_1.pk,) + ), + user=self.user, + ) + start_log, avg_log = TimelineLogProxy.objects.all() + + # regular log visible + self.assertContains(response, start_log.get_message()) + + # avg log not visible + self.assertNotContains(response, avg_log.get_message())