Skip to content

Commit

Permalink
✨ [#16] added show logs for every audit_log admin change page
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-maykin committed Oct 23, 2024
1 parent 5e02469 commit af3c6d6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/woo_publications/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

@admin.register(User)
class UserAdmin(AdminAuditLogMixin, HijackUserAdminMixin, _UserAdmin):
change_form_template = "admin/audit_log_change_view.html"

list_display = (
"username",
"email",
Expand Down
78 changes: 74 additions & 4 deletions src/woo_publications/logging/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
from timeline_logger.models import TimelineLog

from woo_publications.accounts.tests.factories import UserFactory
from woo_publications.publications.tests.factories import PublicationFactory
from woo_publications.metadata.tests.factories import (
InformationCategoryFactory,
ThemeFactory,
)
from woo_publications.publications.tests.factories import (
DocumentFactory,
PublicationFactory,
)

from ..constants import Events
from ..models import TimelineLogProxy
Expand Down Expand Up @@ -329,9 +336,7 @@ def test_admin_change_view_audit_log_button(self):
TimelineLog.objects.create(extra_data=[])

with self.subTest("publications has 'show logs' button and filters correctly"):
publication = PublicationFactory.create(
officiele_titel="title one",
)
publication = PublicationFactory.create()
reverse_url = reverse(
"admin:publications_publication_change",
kwargs={"object_id": publication.id},
Expand All @@ -345,3 +350,68 @@ def test_admin_change_view_audit_log_button(self):

self.assertEqual(response.status_code, 200)
self.assertNumLogsDisplayed(response, 1)

with self.subTest("documents has 'show logs' button and filters correctly"):
document = DocumentFactory.create()
reverse_url = reverse(
"admin:publications_document_change",
kwargs={"object_id": document.pk},
)

response = self.app.get(reverse_url)

self.assertEqual(response.status_code, 200)

response = response.click("Show logs")

self.assertEqual(response.status_code, 200)
self.assertNumLogsDisplayed(response, 1)

with self.subTest("themes has 'show logs' button and filters correctly"):
theme = ThemeFactory.create()
reverse_url = reverse(
"admin:metadata_theme_change",
kwargs={"object_id": theme.pk},
)

response = self.app.get(reverse_url)

self.assertEqual(response.status_code, 200)

response = response.click("Show logs")

self.assertEqual(response.status_code, 200)
self.assertNumLogsDisplayed(response, 1)

with self.subTest(
"information category has 'show logs' button and filters correctly"
):
information_category = InformationCategoryFactory.create()
reverse_url = reverse(
"admin:metadata_informationcategory_change",
kwargs={"object_id": information_category.pk},
)

response = self.app.get(reverse_url)

self.assertEqual(response.status_code, 200)

response = response.click("Show logs")

self.assertEqual(response.status_code, 200)
self.assertNumLogsDisplayed(response, 1)

with self.subTest("user has 'show logs' button and filters correctly"):
reverse_url = reverse(
"admin:accounts_user_change",
kwargs={"object_id": self.superuser.pk},
)

response = self.app.get(reverse_url)

self.assertEqual(response.status_code, 200)

response = response.click("Show logs")

self.assertEqual(response.status_code, 200)
self.assertNumLogsDisplayed(response, 1)
4 changes: 4 additions & 0 deletions src/woo_publications/metadata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

@admin.register(InformationCategory)
class InformationCategoryAdmin(AdminAuditLogMixin, OrderedModelAdmin):
change_form_template = "admin/audit_log_change_view.html"

list_display = (
"naam",
"identifier",
Expand Down Expand Up @@ -50,6 +52,8 @@ def show_actions(self, obj: InformationCategory) -> str:

@admin.register(Theme)
class ThemeAdmin(AdminAuditLogMixin, TreeAdmin):
change_form_template = "admin/audit_log_change_view.html"

list_display = ("naam", "identifier", "show_actions")
search_fields = ("identifier", "naam")
form = movenodeform_factory(Theme)
Expand Down
2 changes: 2 additions & 0 deletions src/woo_publications/publications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def show_actions(self, obj: Publication) -> str:

@admin.register(Document)
class DocumentAdmin(AdminAuditLogMixin, admin.ModelAdmin):
change_form_template = "admin/audit_log_change_view.html"

list_display = (
"officiele_titel",
"verkorte_titel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

}

{# Extended the object-tools-items to also display a redirect button for the audit logs. #}
{% block object-tools-items %}
<li>
<a href="{{ audit_log_url }}" title="{{ audit_log_label }}">{{ audit_log_label }}</a>
Expand Down

0 comments on commit af3c6d6

Please sign in to comment.