Skip to content

Commit

Permalink
[#3889] Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Apr 5, 2024
1 parent a8ad94f commit fb82f6a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/openforms/logging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def fmt_url(self) -> str:
def content_admin_url(self) -> str:
if not (self.object_id and self.content_type_id):
return ""
breakpoint()

ct = self.content_type
return reverse(
f"admin:{ct.app_label}_{ct.model}_change", args=(self.object_id,)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}
{% blocktrans trimmed with lead=log.fmt_lead user=log.fmt_user timelinelog=log.pk %}
{{ lead }}: User {{ user }} viewed outgoing request log {{ timelinelog }} in the admin
{% blocktrans trimmed with lead=log.fmt_lead user=log.fmt_user requestlog=log.content_object %}
{{ lead }}: User {{ user }} viewed outgoing request log {{ requestlog.method }} {{ requestlog.url }} ({{ requestlog.status_code }}) in the admin
{% endblocktrans %}
38 changes: 25 additions & 13 deletions src/openforms/logging/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import json
from datetime import datetime, timezone as dt_timezone

from django.contrib.auth.models import Permission
from django.test import TestCase, tag
from django.urls import reverse
from django.utils import timezone
from django.utils.formats import localize
from django.utils.translation import gettext_lazy as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa
Expand Down Expand Up @@ -54,14 +57,10 @@ def test_superuser_cant_delete_logs_with_bulk_action(self):
html_form = changelist.forms["changelist-form"]

# It is not possible to select the "delete_selected" option
self.assertEqual(
[
option
for option in html_form.fields.get("action")[0].options
if option[0] == "delete_selected"
],
[],
)
options = {
value for value, *_ in html_form.fields.get("action")[0].options if value
}
self.assertEqual(options, {"export_admin_action"})

def test_superuser_cant_delete_individual_logs(self):
submission = SubmissionFactory.create(completed_on=timezone.now())
Expand Down Expand Up @@ -102,6 +101,8 @@ class TimelineLogExportsTest(TestCase):
def test_bare_timelinelog_export(self):
user = StaffUserFactory.create()
bare_log = TimelineLogProxyFactory.create(user=user)
bare_log.timestamp = datetime(2024, 1, 1, tzinfo=dt_timezone.utc)
bare_log.save()

dataset = TimelineLogProxyResource().export()

Expand All @@ -110,20 +111,24 @@ def test_bare_timelinelog_export(self):
[
{
"message": bare_log.message().strip(),
"user": bare_log.fmt_user,
"user": _("Staff user {user}").format(user=user),
"related_object": None,
"timestamp": bare_log.timestamp.isoformat(),
"timestamp": "2024-01-01T00:00:00+00:00",
"event": None,
}
],
)

def test_timelinelog_export(self):
submission = SubmissionFactory.create()
submission.created_on = datetime(2024, 1, 1, tzinfo=dt_timezone.utc)
submission.save()
user = StaffUserFactory.create()
log = TimelineLogProxyFactory.create(
content_object=submission, user=user, extra_data={"log_event": "test_event"}
)
log.timestamp = datetime(2024, 1, 1, tzinfo=dt_timezone.utc)
log.save()

dataset = TimelineLogProxyResource().export()

Expand All @@ -132,9 +137,16 @@ def test_timelinelog_export(self):
[
{
"message": log.message().strip(),
"user": log.fmt_user,
"related_object": str(submission),
"timestamp": log.timestamp.isoformat(),
"user": _("Staff user {user}").format(user=user),
"related_object": _("{pk} - started on {started}").format(
pk=submission.pk,
started=localize(
timezone.localtime(
datetime(2024, 1, 1, tzinfo=dt_timezone.utc)
)
),
),
"timestamp": "2024-01-01T00:00:00+00:00",
"event": "test_event",
}
],
Expand Down
12 changes: 12 additions & 0 deletions src/openforms/utils/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

@disable_admin_mfa()
class OutgoingRequestLogAdminTests(WebTest):
def test_view_404(self):
user = UserFactory.create(is_superuser=True, is_staff=True)

self.app.get(
reverse(
"admin:log_outgoing_requests_outgoingrequestslog_change",
kwargs={"object_id": 123456},
),
user=user,
status=404,
)

def test_viewing_outgoing_request_log_details_in_admin_creates_log(self):
user = UserFactory.create(is_superuser=True, is_staff=True)
outgoing_request_log = OutgoingRequestsLog.objects.create(
Expand Down

0 comments on commit fb82f6a

Please sign in to comment.