feat(core): Ensure that model has user context

ref: #788 #759
This commit is contained in:
2025-06-05 13:22:28 +09:30
parent f42e255f37
commit 3915678675
2 changed files with 39 additions and 0 deletions

View File

@ -1,5 +1,6 @@
from django.apps import apps
from django.contrib.auth.models import ContentType
from django.core.exceptions import ValidationError
from django.db.models.signals import (
# post_delete,
post_save
@ -26,6 +27,14 @@ def audit_history(sender, instance, **kwargs):
audit_action = audit_model.Actions.DELETE
if instance.context.get('user', None) is None:
raise ValidationError(
code = 'model_missing_user_context',
message = f'Model {instance._meta.model_name}, is missing user context. ' \
'No audit history can be saved'
)
history = audit_model.objects.create(
organization = instance.organization,