Fix orchestrator issues
This commit is contained in:
@@ -34,7 +34,8 @@ route_builder = RouteBuilder('notifications')
|
||||
|
||||
# Dependency injection for enhanced notification service
|
||||
def get_enhanced_notification_service():
|
||||
database_manager = create_database_manager()
|
||||
from app.core.config import settings
|
||||
database_manager = create_database_manager(settings.DATABASE_URL, "notification")
|
||||
return EnhancedNotificationService(database_manager)
|
||||
|
||||
|
||||
@@ -47,7 +48,6 @@ def get_enhanced_notification_service():
|
||||
response_model=NotificationResponse,
|
||||
status_code=201
|
||||
)
|
||||
@require_user_role(["member", "admin", "owner"])
|
||||
@track_endpoint_metrics("notification_send")
|
||||
async def send_notification(
|
||||
notification_data: Dict[str, Any],
|
||||
@@ -55,11 +55,23 @@ async def send_notification(
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
notification_service: EnhancedNotificationService = Depends(get_enhanced_notification_service)
|
||||
):
|
||||
"""Send a single notification with enhanced validation and features"""
|
||||
"""Send a single notification with enhanced validation and features - allows service-to-service calls"""
|
||||
|
||||
try:
|
||||
# Allow service-to-service calls (skip role check for service tokens)
|
||||
is_service_call = current_user.get("type") == "service"
|
||||
|
||||
if not is_service_call:
|
||||
# Check user role for non-service calls
|
||||
user_role = current_user.get("role", "").lower()
|
||||
if user_role not in ["member", "admin", "owner"]:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Insufficient permissions"
|
||||
)
|
||||
|
||||
# Check permissions for broadcast notifications (Admin+ only)
|
||||
if notification_data.get("broadcast", False):
|
||||
if notification_data.get("broadcast", False) and not is_service_call:
|
||||
user_role = current_user.get("role", "").lower()
|
||||
if user_role not in ["admin", "owner"]:
|
||||
raise HTTPException(
|
||||
@@ -111,10 +123,14 @@ async def send_notification(
|
||||
detail=f"Invalid priority: {notification_data['priority']}"
|
||||
)
|
||||
|
||||
# Use tenant_id from path parameter (especially for service calls)
|
||||
effective_tenant_id = str(tenant_id) if is_service_call else current_user.get("tenant_id")
|
||||
effective_sender_id = current_user.get("user_id", "system")
|
||||
|
||||
# Create notification using enhanced service
|
||||
notification = await notification_service.create_notification(
|
||||
tenant_id=current_user.get("tenant_id"),
|
||||
sender_id=current_user["user_id"],
|
||||
tenant_id=effective_tenant_id,
|
||||
sender_id=effective_sender_id,
|
||||
notification_type=notification_type,
|
||||
message=notification_data["message"],
|
||||
recipient_id=notification_data.get("recipient_id"),
|
||||
@@ -131,18 +147,20 @@ async def send_notification(
|
||||
|
||||
logger.info("Notification sent successfully",
|
||||
notification_id=notification.id,
|
||||
tenant_id=current_user.get("tenant_id"),
|
||||
tenant_id=effective_tenant_id,
|
||||
type=notification_type.value,
|
||||
priority=priority.value)
|
||||
priority=priority.value,
|
||||
is_service_call=is_service_call)
|
||||
|
||||
return NotificationResponse.from_orm(notification)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
effective_tenant_id = str(tenant_id) if current_user.get("type") == "service" else current_user.get("tenant_id")
|
||||
logger.error("Failed to send notification",
|
||||
tenant_id=current_user.get("tenant_id"),
|
||||
sender_id=current_user["user_id"],
|
||||
tenant_id=effective_tenant_id,
|
||||
sender_id=current_user.get("user_id", "system"),
|
||||
error=str(e))
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
@@ -25,7 +25,8 @@ route_builder = RouteBuilder('notifications')
|
||||
|
||||
# Dependency injection for enhanced notification service
|
||||
def get_enhanced_notification_service():
|
||||
database_manager = create_database_manager()
|
||||
from app.core.config import settings
|
||||
database_manager = create_database_manager(settings.DATABASE_URL, "notification")
|
||||
return EnhancedNotificationService(database_manager)
|
||||
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user