Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added cached object to audit log filter #93

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/woo_publications/logging/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TimelineLogProxyAdmin(admin.ModelAdmin):
search_fields = (
"extra_data__acting_user__identifier",
"extra_data__acting_user__display_name",
"extra_data___cached_object_repr",
)
list_select_related = ("content_type", "user")
date_hierarchy = "timestamp"
Expand Down
19 changes: 19 additions & 0 deletions src/woo_publications/logging/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ def test_search_behaviour(self):
"identifier": "testsuite",
"display_name": "Automated tests",
},
"_cached_object_repr": "foobar",
},
)
# broken audit log entry
TimelineLogProxy.objects.create(
extra_data={
"event": Events.read,
"acting_user": {
"identifier": None,
"display_name": None,
},
"_cached_object_repr": None,
},
)

Expand All @@ -241,6 +253,13 @@ def test_search_behaviour(self):
self.assertNotContains(response, "1234")
self.assertContains(response, "testsuite")

with self.subTest("search on cached_object_repr"):
response = self.app.get(self.list_url, {"q": "foobar"})

self.assertEqual(response.status_code, 200)
self.assertNumLogsDisplayed(response, 1)
self.assertContains(response, "foobar")

def test_no_excessive_queries_for_content_object(self):
# create a 100 records to fill the admin - can't use bulk create because that
# skips the save method :)
Expand Down
Loading