From d00e147068958cfd15f3c6f18275f54ce8e84f85 Mon Sep 17 00:00:00 2001 From: hamed Date: Wed, 1 Nov 2023 14:33:24 +0300 Subject: [PATCH 1/2] add actor email --- auditlog/context.py | 5 ++++- auditlog/migrations/0016_add_actor_email.py | 17 +++++++++++++++++ auditlog/models.py | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 auditlog/migrations/0016_add_actor_email.py diff --git a/auditlog/context.py b/auditlog/context.py index 644c6ce5..ed209319 100644 --- a/auditlog/context.py +++ b/auditlog/context.py @@ -23,7 +23,9 @@ def set_actor(actor, remote_addr=None): auditlog_value.set(context_data) # Connect signal for automatic logging - set_actor = partial(_set_actor, user=actor, signal_duid=context_data["signal_duid"]) + set_actor = partial( + _set_actor, user=actor, signal_duid=context_data["signal_duid"], + ) pre_save.connect( set_actor, sender=LogEntry, @@ -61,6 +63,7 @@ def _set_actor(user, sender, instance, signal_duid, **kwargs): and instance.actor is None ): instance.actor = user + instance.actor_email = user.email instance.remote_addr = auditlog["remote_addr"] diff --git a/auditlog/migrations/0016_add_actor_email.py b/auditlog/migrations/0016_add_actor_email.py new file mode 100644 index 00000000..98e0582e --- /dev/null +++ b/auditlog/migrations/0016_add_actor_email.py @@ -0,0 +1,17 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("auditlog", "0015_alter_logentry_changes"), + ] + + operations = [ + migrations.AddField( + model_name="logentry", + name="actor_email", + field=models.CharField( + null=True, verbose_name="actor email", blank=True, max_length=254, + ), + ), + ] diff --git a/auditlog/models.py b/auditlog/models.py index e0c637db..75e04b87 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -377,9 +377,11 @@ class Action: additional_data = models.JSONField( blank=True, null=True, verbose_name=_("additional data") ) + actor_email = models.CharField(blank=True, null=True, max_length=254) objects = LogEntryManager() + class Meta: get_latest_by = "timestamp" ordering = ["-timestamp"] From 45e30646ab41fb7f74c400a15693d2a5a9b16266 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 05:06:03 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- auditlog/context.py | 4 +++- auditlog/migrations/0016_add_actor_email.py | 5 ++++- auditlog/models.py | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/auditlog/context.py b/auditlog/context.py index ed209319..81fe1eb2 100644 --- a/auditlog/context.py +++ b/auditlog/context.py @@ -24,7 +24,9 @@ def set_actor(actor, remote_addr=None): # Connect signal for automatic logging set_actor = partial( - _set_actor, user=actor, signal_duid=context_data["signal_duid"], + _set_actor, + user=actor, + signal_duid=context_data["signal_duid"], ) pre_save.connect( set_actor, diff --git a/auditlog/migrations/0016_add_actor_email.py b/auditlog/migrations/0016_add_actor_email.py index 98e0582e..176e376c 100644 --- a/auditlog/migrations/0016_add_actor_email.py +++ b/auditlog/migrations/0016_add_actor_email.py @@ -11,7 +11,10 @@ class Migration(migrations.Migration): model_name="logentry", name="actor_email", field=models.CharField( - null=True, verbose_name="actor email", blank=True, max_length=254, + null=True, + verbose_name="actor email", + blank=True, + max_length=254, ), ), ] diff --git a/auditlog/models.py b/auditlog/models.py index 75e04b87..89f91086 100644 --- a/auditlog/models.py +++ b/auditlog/models.py @@ -381,7 +381,6 @@ class Action: objects = LogEntryManager() - class Meta: get_latest_by = "timestamp" ordering = ["-timestamp"]