-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added audit trail for changing validated name
- Loading branch information
Showing
4 changed files
with
203 additions
and
62 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
apps/badgrsocialauth/providers/eduid/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.2.25 on 2024-10-07 11:03 | ||
|
||
from django.db import migrations, models | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ValidatedNameAuditTrail', | ||
fields=[ | ||
('pkid', models.BigAutoField(editable=False, primary_key=True, serialize=False)), | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), | ||
('action_datetime', models.DateTimeField(auto_now=True)), | ||
('user', models.CharField(blank=True, max_length=254)), | ||
('old_validated_name', models.CharField(blank=True, max_length=255)), | ||
('new_validated_name', models.CharField(blank=True, max_length=255)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import logging | ||
import uuid | ||
|
||
import django.dispatch | ||
from django.db import models | ||
from django.dispatch import receiver | ||
|
||
|
||
class ValidatedNameAuditTrail(models.Model): | ||
pkid = models.BigAutoField(primary_key=True, editable=False) | ||
id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) | ||
action_datetime = models.DateTimeField(auto_now=True) | ||
user = models.CharField(max_length=254, blank=True) | ||
old_validated_name = models.CharField(max_length=255, blank=True) | ||
new_validated_name = models.CharField(max_length=255, blank=True) | ||
|
||
|
||
# Signals doc: https://docs.djangoproject.com/en/3.2/topics/signals/ | ||
val_name_audit_trail_signal = django.dispatch.Signal( | ||
providing_args=["user", "old_validated_name", "new_validated_name"] | ||
) # creates a custom signal and specifies the args required. | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(val_name_audit_trail_signal) | ||
def new_val_name_audit_trail( | ||
sender, user, old_validated_name, new_validated_name, **kwargs | ||
): | ||
try: | ||
if not old_validated_name == new_validated_name: | ||
if old_validated_name is None: | ||
audit_trail = ValidatedNameAuditTrail.objects.create( | ||
user=user, | ||
new_validated_name=new_validated_name, | ||
) | ||
elif new_validated_name is None: | ||
audit_trail = ValidatedNameAuditTrail.objects.create( | ||
user=user, | ||
old_validated_name=old_validated_name, | ||
) | ||
else: | ||
audit_trail = ValidatedNameAuditTrail.objects.create( | ||
user=user, | ||
old_validated_name=old_validated_name, | ||
new_validated_name=new_validated_name, | ||
) | ||
logger.info( | ||
f"val_name_audit_trail created {audit_trail.id} for user {audit_trail.user}" | ||
) | ||
except Exception as e: | ||
logger.error("val_name_audit_trail error: %s" % (e)) |
Oops, something went wrong.