Skip to content

Commit

Permalink
[#3889] Add more fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Apr 3, 2024
1 parent e99afaf commit 06aec02
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/openforms/logging/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TimelineLogProxyResource(resources.ModelResource):
user = Field(attribute="user")
related_object = Field(attribute="content_object")
message = Field(attribute="message")
event = Field(attribute="extra_data")

class Meta:
model = TimelineLogProxy
Expand All @@ -32,6 +33,11 @@ def dehydrate_message(self, obj: TimelineLogProxy) -> str:
def dehydrate_timestamp(self, obj: TimelineLogProxy) -> str:
return obj.timestamp.isoformat()

def dehydrate_event(self, obj: TimelineLogProxy) -> str | None:
if not obj.extra_data:
return None
return obj.extra_data.get("log_event")


@admin.register(TimelineLogProxy)
class TimelineLogProxyAdmin(ExportActionModelAdmin):
Expand Down
28 changes: 25 additions & 3 deletions src/openforms/logging/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,31 @@ def test_deleted_submission_doesnt_crash_logs(self):


class TimelineLogExportsTest(TestCase):
def test_timelinelog_exports(self):
def test_bare_timelinelog_export(self):
user = StaffUserFactory.create()
bare_log = TimelineLogProxyFactory.create(user=user)

dataset = TimelineLogProxyResource().export()

self.assertEqual(
json.loads(dataset.json),
[
{
"message": bare_log.message().strip(),
"user": bare_log.fmt_user,
"related_object": None,
"timestamp": bare_log.timestamp.isoformat(),
"event": None,
}
],
)

def test_timelinelog_export(self):
submission = SubmissionFactory.create()
user = StaffUserFactory.create()
log = TimelineLogProxyFactory.create(content_object=submission, user=user)
log = TimelineLogProxyFactory.create(
content_object=submission, user=user, extra_data={"log_event": "test_event"}
)

dataset = TimelineLogProxyResource().export()

Expand All @@ -112,8 +133,9 @@ def test_timelinelog_exports(self):
{
"message": log.message().strip(),
"user": log.fmt_user,
"related_object": str(log.content_object),
"related_object": str(submission),
"timestamp": log.timestamp.isoformat(),
"event": "test_event",
}
],
)

0 comments on commit 06aec02

Please sign in to comment.