We have a custom User model that includes user email / name into the string representation:
def __str__(self):
if self.first_name and self.last_name:
return f"{self.last_name} {self.first_name} ({self.email})"
else:
return self.email
Due to django-auditlog's grabbing instances' string representation for its object_repr, this isn't enough to reduce the amount of PII we're writing onto our logs:
auditlog.register(
User,
+ mask_fields={"first_name", "last_name", "email"},
)
We are putting in a workaround with signals at the time being, but it would be nice if similar projects can eliminate the same kind of limitation through a feature in the official package, using something like:
auditlog.register(
User,
+ mask_fields={"first_name", "last_name", "email"},
+ object_repr_field="pk",
)
For reference, our workaround looks like this:
@receiver(post_log, sender=User)
def anonymize_user_object_repr(sender, instance, log_entry, log_created, **kwargs):
if log_created and log_entry and log_entry.object_repr:
log_entry.object_repr = instance.pk
log_entry.save(update_fields=["object_repr"])
I have skimmed the classes involved on django-auditlog and it looks to me like some small changes in LogEntryManager and AuditLogModelRegistry could be sufficient to support the feature and spare the need for a workaround for our project and potentially others.
I'm happy to provide a pull request if this feature seems sensible.
We have a custom User model that includes user email / name into the string representation:
Due to
django-auditlog's grabbing instances' string representation for itsobject_repr, this isn't enough to reduce the amount of PII we're writing onto our logs:auditlog.register( User, + mask_fields={"first_name", "last_name", "email"}, )We are putting in a workaround with signals at the time being, but it would be nice if similar projects can eliminate the same kind of limitation through a feature in the official package, using something like:
auditlog.register( User, + mask_fields={"first_name", "last_name", "email"}, + object_repr_field="pk", )For reference, our workaround looks like this:
I have skimmed the classes involved on
django-auditlogand it looks to me like some small changes inLogEntryManagerandAuditLogModelRegistrycould be sufficient to support the feature and spare the need for a workaround for our project and potentially others.I'm happy to provide a pull request if this feature seems sensible.