Skip to content

Commit

Permalink
Merge pull request #100 from GeneriekPublicatiePlatformWoo/feature/16…
Browse files Browse the repository at this point in the history
…-inline-remove

Inline deletion audit logs
  • Loading branch information
sergei-maertens authored Oct 25, 2024
2 parents db3eb27 + f60d4af commit 9940f0a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/woo_publications/logging/admin_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def save_existing(self, form, obj, commit=True):

return super().save_existing(form, obj, commit)

def delete_existing(self, obj, commit=True):
if commit:
audit_admin_delete(
content_object=obj,
django_user=self.django_user,
object_data=serialize_instance(obj),
)

super().delete_existing(obj, commit)


def get_logs_link(obj: models.Model) -> tuple[str, str]:
"""
Expand Down
79 changes: 79 additions & 0 deletions src/woo_publications/publications/tests/test_admin_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,82 @@ def test_admin_inline_create_admin(self):
}

self.assertEqual(log.extra_data, expected_data)

def test_admin_inline_delete(self):
assert not TimelineLogProxy.objects.exists()

with freeze_time("2024-09-25T00:14:00-00:00"):
publication = PublicationFactory.create(
officiele_titel="title one",
verkorte_titel="one",
omschrijving="Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
)
document = DocumentFactory.create(
publicatie=publication,
identifier="document-1",
officiele_titel="DELETE THIS ITEM",
verkorte_titel="",
omschrijving="",
creatiedatum="2024-09-25",
)
reverse_url = reverse(
"admin:publications_publication_change",
kwargs={"object_id": publication.id},
)

response = self.app.get(reverse_url, user=self.user)

self.assertEqual(response.status_code, 200)

with self.subTest("read audit logging"):
log = TimelineLogProxy.objects.get()

expected_data = {
"event": Events.read,
"acting_user": {
"identifier": self.user.id,
"display_name": self.user.get_full_name(),
},
"_cached_object_repr": "title one",
}

self.assertEqual(log.extra_data, expected_data)

form = response.forms["publication_form"]
form["document_set-0-DELETE"] = True
response = form.submit(name="_save")

self.assertEqual(response.status_code, 302)

with self.subTest("update inline update logging"):
log = TimelineLogProxy.objects.filter(
object_id=str(document.pk),
extra_data___cached_object_repr="DELETE THIS ITEM",
).first()
assert log is not None

expected_data = {
"event": Events.delete.value,
"acting_user": {
"identifier": self.user.id,
"display_name": self.user.get_full_name(),
},
"object_data": {
"id": document.pk,
"identifier": "document-1",
"publicatie": publication.id,
"bestandsnaam": "unknown.bin",
"creatiedatum": "2024-09-25",
"omschrijving": "",
"document_uuid": None,
"bestandsomvang": 0,
"verkorte_titel": "",
"bestandsformaat": "unknown",
"officiele_titel": "DELETE THIS ITEM",
"document_service": None,
"registratiedatum": "2024-09-25T00:14:00Z",
},
"_cached_object_repr": "DELETE THIS ITEM",
}

self.assertEqual(log.extra_data, expected_data)

0 comments on commit 9940f0a

Please sign in to comment.