Spaces:
Sleeping
Sleeping
track
Browse files- core/models.py +1 -1
- routers/blink.py +13 -14
core/models.py
CHANGED
|
@@ -73,7 +73,7 @@ class ClientUser(Base):
|
|
| 73 |
__tablename__ = "client_users"
|
| 74 |
|
| 75 |
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
| 76 |
-
user_id = Column(String(50), ForeignKey("users.user_id"), index=True, nullable=
|
| 77 |
client_user_id = Column(String(100), index=True, nullable=True) # Client-side temp identifier
|
| 78 |
|
| 79 |
# IP tracking for network/location correlation
|
|
|
|
| 73 |
__tablename__ = "client_users"
|
| 74 |
|
| 75 |
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
| 76 |
+
user_id = Column(String(50), ForeignKey("users.user_id"), index=True, nullable=True) # Nullable for anonymous tracking
|
| 77 |
client_user_id = Column(String(100), index=True, nullable=True) # Client-side temp identifier
|
| 78 |
|
| 79 |
# IP tracking for network/location correlation
|
routers/blink.py
CHANGED
|
@@ -2,8 +2,7 @@
|
|
| 2 |
Blink Router - Admin endpoints for viewing and tracking data.
|
| 3 |
Uses AuditLog for unified client/server event tracking.
|
| 4 |
"""
|
| 5 |
-
from fastapi import APIRouter, Depends, HTTPException, status, Query, Request
|
| 6 |
-
from fastapi.responses import JSONResponse
|
| 7 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 8 |
from sqlalchemy import select, func
|
| 9 |
import ipaddress
|
|
@@ -498,17 +497,17 @@ async def blink(
|
|
| 498 |
# Determine server user_id (if authenticated)
|
| 499 |
server_user_id = current_user.user_id if current_user else None
|
| 500 |
|
| 501 |
-
#
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
|
| 513 |
# Store each decrypted result as separate audit log entries
|
| 514 |
records_created = 0
|
|
@@ -556,7 +555,7 @@ async def blink(
|
|
| 556 |
logger.info(f"Successfully processed blink for client: {client_user_id}, records: {records_created}, auth: {auth_status}")
|
| 557 |
|
| 558 |
# Return 204 No Content for silent tracking
|
| 559 |
-
return
|
| 560 |
|
| 561 |
except HTTPException:
|
| 562 |
raise
|
|
|
|
| 2 |
Blink Router - Admin endpoints for viewing and tracking data.
|
| 3 |
Uses AuditLog for unified client/server event tracking.
|
| 4 |
"""
|
| 5 |
+
from fastapi import APIRouter, Depends, HTTPException, status, Query, Request, Response
|
|
|
|
| 6 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 7 |
from sqlalchemy import select, func
|
| 8 |
import ipaddress
|
|
|
|
| 497 |
# Determine server user_id (if authenticated)
|
| 498 |
server_user_id = current_user.user_id if current_user else None
|
| 499 |
|
| 500 |
+
# Always create a ClientUser entry (user_id is None for anonymous users)
|
| 501 |
+
new_client_user = ClientUser(
|
| 502 |
+
user_id=server_user_id, # None if anonymous, user_id if authenticated
|
| 503 |
+
client_user_id=client_user_id,
|
| 504 |
+
ipv4_address=ipv4_address,
|
| 505 |
+
ipv6_address=ipv6_address,
|
| 506 |
+
device_info={"user_agent": user_agent} if user_agent else None
|
| 507 |
+
)
|
| 508 |
+
db.add(new_client_user)
|
| 509 |
+
auth_status = "authenticated" if current_user else "anonymous"
|
| 510 |
+
logger.info(f"Created ClientUser entry: user_id={server_user_id}, client_user_id={client_user_id}, auth: {auth_status}")
|
| 511 |
|
| 512 |
# Store each decrypted result as separate audit log entries
|
| 513 |
records_created = 0
|
|
|
|
| 555 |
logger.info(f"Successfully processed blink for client: {client_user_id}, records: {records_created}, auth: {auth_status}")
|
| 556 |
|
| 557 |
# Return 204 No Content for silent tracking
|
| 558 |
+
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
| 559 |
|
| 560 |
except HTTPException:
|
| 561 |
raise
|