Spaces:
Sleeping
Sleeping
Fix notification role handling to support both enum and string role values
Browse files
src/app/services/notification_creator.py
CHANGED
|
@@ -47,7 +47,7 @@ Usage:
|
|
| 47 |
import logging
|
| 48 |
from sqlalchemy.orm import Session
|
| 49 |
from uuid import UUID
|
| 50 |
-
from typing import Optional, List, Dict, Any
|
| 51 |
from datetime import datetime
|
| 52 |
|
| 53 |
from app.models.notification import Notification, NotificationChannel, NotificationStatus
|
|
@@ -228,7 +228,7 @@ class NotificationCreator:
|
|
| 228 |
source_type: str,
|
| 229 |
source_id: Optional[UUID],
|
| 230 |
notification_type: str,
|
| 231 |
-
roles: Optional[List[AppRole]] = None,
|
| 232 |
channel: str = "in_app",
|
| 233 |
metadata: Optional[Dict[str, Any]] = None,
|
| 234 |
exclude_user_ids: Optional[List[UUID]] = None
|
|
@@ -279,7 +279,16 @@ class NotificationCreator:
|
|
| 279 |
|
| 280 |
# Filter by roles if specified
|
| 281 |
if roles:
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
query = query.filter(User.role.in_(role_values))
|
| 284 |
|
| 285 |
# Exclude specific users if specified
|
|
|
|
| 47 |
import logging
|
| 48 |
from sqlalchemy.orm import Session
|
| 49 |
from uuid import UUID
|
| 50 |
+
from typing import Optional, List, Dict, Any, Union
|
| 51 |
from datetime import datetime
|
| 52 |
|
| 53 |
from app.models.notification import Notification, NotificationChannel, NotificationStatus
|
|
|
|
| 228 |
source_type: str,
|
| 229 |
source_id: Optional[UUID],
|
| 230 |
notification_type: str,
|
| 231 |
+
roles: Optional[List[Union[str, AppRole]]] = None,
|
| 232 |
channel: str = "in_app",
|
| 233 |
metadata: Optional[Dict[str, Any]] = None,
|
| 234 |
exclude_user_ids: Optional[List[UUID]] = None
|
|
|
|
| 279 |
|
| 280 |
# Filter by roles if specified
|
| 281 |
if roles:
|
| 282 |
+
# Handle both string roles and AppRole enum objects
|
| 283 |
+
role_values = []
|
| 284 |
+
for role in roles:
|
| 285 |
+
if isinstance(role, str):
|
| 286 |
+
role_values.append(role)
|
| 287 |
+
elif hasattr(role, 'value'):
|
| 288 |
+
role_values.append(role.value)
|
| 289 |
+
else:
|
| 290 |
+
role_values.append(str(role))
|
| 291 |
+
|
| 292 |
query = query.filter(User.role.in_(role_values))
|
| 293 |
|
| 294 |
# Exclude specific users if specified
|