diff --git a/apps/badgrsocialauth/providers/eduid/signals.py b/apps/badgrsocialauth/providers/eduid/signals.py index 9afb1a6d..b757779a 100644 --- a/apps/badgrsocialauth/providers/eduid/signals.py +++ b/apps/badgrsocialauth/providers/eduid/signals.py @@ -28,19 +28,25 @@ def new_val_name_audit_trail( sender, user, old_validated_name, new_validated_name, **kwargs ): try: - if old_validated_name is None: - audit_trail = ValidatedNameAuditTrail.objects.create( - user=user, - new_validated_name=new_validated_name, + 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}" ) - 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))