jebin2 commited on
Commit
c5e99dc
·
1 Parent(s): 28e48bc

Phase 1: Fix audit logging in blink.py

Browse files

- Replace direct AuditLog creation with AuditService.log_event()
- Ensures consistent audit logging across codebase
- Removed unused AuditLog import

Fixes critical audit logging inconsistency identified in audit

Files changed (1) hide show
  1. routers/blink.py +23 -20
routers/blink.py CHANGED
@@ -9,7 +9,7 @@ import ipaddress
9
  import logging
10
 
11
  from core.database import get_db
12
- from core.models import User, AuditLog, GeminiJob, Contact, ClientUser
13
  from services.encryption_service import decrypt_multiple_blocks
14
  from dependencies import get_geolocation
15
 
@@ -544,34 +544,37 @@ async def blink(
544
  "region": region
545
  }
546
 
547
- audit_log = AuditLog(
548
- log_type="client",
549
- user_id=server_user_id, # Set if authenticated, None if anonymous
550
- client_user_id=client_user_id,
 
551
  action="blink",
 
 
 
552
  details=details,
553
- ip_address=ip_address,
554
- user_agent=user_agent,
555
- refer_url=refer_url,
556
- status="success"
557
  )
558
- db.add(audit_log)
559
  records_created += 1
560
 
561
  # If no results but we have encrypted data, store a record
562
  if not decrypted_results and encrypted_data:
563
- audit_log = AuditLog(
564
- log_type="client",
565
- user_id=server_user_id, # Set if authenticated, None if anonymous
566
- client_user_id=client_user_id,
 
 
567
  action="blink",
568
- details={"encrypted_length": len(encrypted_data), "country": country, "region": region},
569
- ip_address=ip_address,
570
- user_agent=user_agent,
571
- refer_url=refer_url,
572
- status="success"
 
573
  )
574
- db.add(audit_log)
575
  records_created = 1
576
 
577
  await db.commit()
 
9
  import logging
10
 
11
  from core.database import get_db
12
+ from core.models import User, GeminiJob, Contact, ClientUser
13
  from services.encryption_service import decrypt_multiple_blocks
14
  from dependencies import get_geolocation
15
 
 
544
  "region": region
545
  }
546
 
547
+ # Use AuditService for consistent logging
548
+ from services.audit_service import AuditService
549
+
550
+ await AuditService.log_event(
551
+ db=db,
552
  action="blink",
553
+ status="success",
554
+ user_id=server_user_id,
555
+ client_user_id=client_user_id,
556
  details=details,
557
+ request=request,
558
+ log_type="client"
 
 
559
  )
 
560
  records_created += 1
561
 
562
  # If no results but we have encrypted data, store a record
563
  if not decrypted_results and encrypted_data:
564
+ # Use AuditService for consistent logging
565
+ from services.audit_service import AuditService
566
+
567
+ details = {"encrypted_length": len(encrypted_data), "country": country, "region": region}
568
+ await AuditService.log_event(
569
+ db=db,
570
  action="blink",
571
+ status="success",
572
+ user_id=server_user_id,
573
+ client_user_id=client_user_id,
574
+ details=details,
575
+ request=request,
576
+ log_type="client"
577
  )
 
578
  records_created = 1
579
 
580
  await db.commit()