Spaces:
Sleeping
Sleeping
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
- 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,
|
| 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 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
|
|
|
| 551 |
action="blink",
|
|
|
|
|
|
|
|
|
|
| 552 |
details=details,
|
| 553 |
-
|
| 554 |
-
|
| 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 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
|
|
|
|
|
|
| 567 |
action="blink",
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
|
|
|
| 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()
|