Skip to content

Commit 49986c7

Browse files
use current user as actor for delete events
1 parent 45608da commit 49986c7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

dojo/product_type/signals.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22

33
from auditlog.models import LogEntry
4+
from crum import get_current_user
45
from django.conf import settings
56
from django.contrib.auth import get_user_model
67
from django.contrib.contenttypes.models import ContentType
@@ -58,6 +59,12 @@ def product_type_post_delete(sender, instance, **kwargs):
5859
).order_by("-id").first():
5960
user = le.actor
6061

62+
# Since adding pghistory as auditlog option, this signal here runs before the django-auditlog signal
63+
# Fallback to the current user of the request (Which might be not available for ASYNC_OBJECT_DELETE scenario's)
64+
if not user:
65+
current_user = get_current_user()
66+
user = current_user
67+
6168
# Update description with user if found
6269
if user:
6370
description = _('The product type "%(name)s" was deleted by %(user)s') % {

unittests/test_notifications.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ def setUp(self):
407407
self.client.credentials(HTTP_AUTHORIZATION="Token " + token.key)
408408

409409
@patch("dojo.notifications.helper.NotificationManager._process_notifications")
410-
@override_settings(ENABLE_AUDITLOG=True)
411410
def test_auditlog_on(self, mock):
412411
prod_type = Product_Type.objects.create(name="notif prod type API")
413412
self.client.delete(reverse("product_type-detail", args=(prod_type.pk,)), format="json")

0 commit comments

Comments
 (0)