Skip to content

Commit

Permalink
[#943] Added filter to hide AVG TimelineLogProxies from Submission ch…
Browse files Browse the repository at this point in the history
…ange view
  • Loading branch information
Bartvaderkin committed Nov 19, 2021
1 parent a65c129 commit 50831da
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/openforms/logging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions src/openforms/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
20 changes: 20 additions & 0 deletions src/openforms/submissions/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())

0 comments on commit 50831da

Please sign in to comment.