Improve the frontend and repository layer

This commit is contained in:
Urtzi Alfaro
2025-10-23 07:44:54 +02:00
parent 8d30172483
commit 07c33fa578
112 changed files with 14726 additions and 2733 deletions

View File

@@ -26,6 +26,7 @@ from shared.routing.route_builder import RouteBuilder
from shared.database.base import create_database_manager
from shared.monitoring.metrics import track_endpoint_metrics
from shared.security import create_audit_logger, AuditSeverity, AuditAction
from shared.config.base import is_internal_service
logger = structlog.get_logger()
router = APIRouter()
@@ -64,7 +65,22 @@ def get_subscription_limit_service():
try:
from app.core.config import settings
database_manager = create_database_manager(settings.DATABASE_URL, "tenant-service")
redis_client = get_tenant_redis_client()
# Get Redis client properly (it's an async function)
import asyncio
try:
# Try to get the event loop, if we're in an async context
loop = asyncio.get_event_loop()
if loop.is_running():
# If we're in a running event loop, we can't use await here
# So we'll pass None and handle Redis initialization in the service
redis_client = None
else:
redis_client = asyncio.run(get_tenant_redis_client())
except RuntimeError:
# No event loop running, we can use async/await
redis_client = asyncio.run(get_tenant_redis_client())
return SubscriptionLimitService(database_manager, redis_client)
except Exception as e:
logger.error("Failed to create subscription limit service", error=str(e))
@@ -204,9 +220,10 @@ async def verify_tenant_access(
):
"""Verify if user has access to tenant - Enhanced version with detailed permissions"""
# Check if this is a service request
if user_id in ["training-service", "data-service", "forecasting-service", "auth-service"]:
# Check if this is an internal service request using centralized registry
if is_internal_service(user_id):
# Services have access to all tenants for their operations
logger.info("Service access granted", service=user_id, tenant_id=str(tenant_id))
return TenantAccessResponse(
has_access=True,
role="service",