Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
f3a5b2f
1
Parent(s): 1818cda
backend stabilization
Browse files- alembic/versions/909517d9e971_add_link_to_notifications.py +26 -0
- api/v1/dashboard.py +6 -2
- api/v1/messages.py +3 -2
- api/v1/tickets.py +25 -11
- core/tasks.py +10 -5
- frontend/apps/customer/src/components/TopBar.tsx +39 -5
- frontend/apps/internal/src/components/TopBar.tsx +36 -1
- main.py +7 -4
- models/notification.py +1 -0
alembic/versions/909517d9e971_add_link_to_notifications.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""add_link_to_notifications
|
| 2 |
+
|
| 3 |
+
Revision ID: 909517d9e971
|
| 4 |
+
Revises: 1536118577ca
|
| 5 |
+
Create Date: 2026-04-08 10:10:55.034686
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from typing import Sequence, Union
|
| 9 |
+
|
| 10 |
+
from alembic import op
|
| 11 |
+
import sqlalchemy as sa
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# revision identifiers, used by Alembic.
|
| 15 |
+
revision: str = '909517d9e971'
|
| 16 |
+
down_revision: Union[str, None] = '1536118577ca'
|
| 17 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 18 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def upgrade() -> None:
|
| 22 |
+
op.add_column('notifications', sa.Column('link', sa.String(length=512), nullable=True))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def downgrade() -> None:
|
| 26 |
+
op.drop_column('notifications', 'link')
|
api/v1/dashboard.py
CHANGED
|
@@ -7,6 +7,7 @@ from typing import Any, Dict, List, Optional
|
|
| 7 |
from fastapi import APIRouter, Depends
|
| 8 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 9 |
from sqlalchemy import select, func, or_, Float, desc
|
|
|
|
| 10 |
|
| 11 |
from core.deps import get_db, get_current_user, get_arq_pool
|
| 12 |
from core.llm import get_llm
|
|
@@ -157,7 +158,8 @@ async def get_my_tickets(
|
|
| 157 |
.options(
|
| 158 |
joinedload(Ticket.creator),
|
| 159 |
joinedload(Ticket.assignee),
|
| 160 |
-
joinedload(Ticket.resolver)
|
|
|
|
| 161 |
)
|
| 162 |
.where(
|
| 163 |
((Ticket.created_by == current_user.id) | (Ticket.assigned_to == current_user.id)),
|
|
@@ -202,7 +204,8 @@ async def get_agent_queue(
|
|
| 202 |
.options(
|
| 203 |
joinedload(Ticket.creator),
|
| 204 |
joinedload(Ticket.assignee),
|
| 205 |
-
joinedload(Ticket.resolver)
|
|
|
|
| 206 |
)
|
| 207 |
.where(
|
| 208 |
Ticket.deleted_at.is_(None)
|
|
@@ -234,6 +237,7 @@ async def get_ai_insights(
|
|
| 234 |
from sqlalchemy import desc
|
| 235 |
|
| 236 |
is_super_admin = (current_user.role == UserRole.SC_ADMIN)
|
|
|
|
| 237 |
is_global = (is_super_admin and workspace_id == "all")
|
| 238 |
|
| 239 |
# 1. Global Tactical Mode (Super-Admin Only)
|
|
|
|
| 7 |
from fastapi import APIRouter, Depends
|
| 8 |
from sqlalchemy.ext.asyncio import AsyncSession
|
| 9 |
from sqlalchemy import select, func, or_, Float, desc
|
| 10 |
+
from sqlalchemy.orm import joinedload
|
| 11 |
|
| 12 |
from core.deps import get_db, get_current_user, get_arq_pool
|
| 13 |
from core.llm import get_llm
|
|
|
|
| 158 |
.options(
|
| 159 |
joinedload(Ticket.creator),
|
| 160 |
joinedload(Ticket.assignee),
|
| 161 |
+
joinedload(Ticket.resolver),
|
| 162 |
+
joinedload(Ticket.feedback)
|
| 163 |
)
|
| 164 |
.where(
|
| 165 |
((Ticket.created_by == current_user.id) | (Ticket.assigned_to == current_user.id)),
|
|
|
|
| 204 |
.options(
|
| 205 |
joinedload(Ticket.creator),
|
| 206 |
joinedload(Ticket.assignee),
|
| 207 |
+
joinedload(Ticket.resolver),
|
| 208 |
+
joinedload(Ticket.feedback)
|
| 209 |
)
|
| 210 |
.where(
|
| 211 |
Ticket.deleted_at.is_(None)
|
|
|
|
| 237 |
from sqlalchemy import desc
|
| 238 |
|
| 239 |
is_super_admin = (current_user.role == UserRole.SC_ADMIN)
|
| 240 |
+
is_staff = current_user.role in [UserRole.SC_ADMIN, UserRole.SC_LEAD, UserRole.SC_AGENT]
|
| 241 |
is_global = (is_super_admin and workspace_id == "all")
|
| 242 |
|
| 243 |
# 1. Global Tactical Mode (Super-Admin Only)
|
api/v1/messages.py
CHANGED
|
@@ -135,7 +135,7 @@ async def send_message(
|
|
| 135 |
from arq.connections import RedisSettings
|
| 136 |
settings = get_settings()
|
| 137 |
redis = await create_pool(RedisSettings.from_dsn(settings.REDIS_URL))
|
| 138 |
-
await redis.enqueue_job("notify_mentions", str(current_user.workspace_id), ticket.title, mentions)
|
| 139 |
await redis.close()
|
| 140 |
except Exception as e:
|
| 141 |
print(f"FAILED TO QUEUE MENTION NOTIFICATION: {e}")
|
|
@@ -154,7 +154,8 @@ async def send_message(
|
|
| 154 |
str(ticket.created_by),
|
| 155 |
str(ticket.workspace_id),
|
| 156 |
"💬 Expert Response",
|
| 157 |
-
f"An expert has replied to your ticket: '{ticket.title}'"
|
|
|
|
| 158 |
)
|
| 159 |
except Exception as e:
|
| 160 |
logger.error(f"Failed to queue customer response notification: {e}")
|
|
|
|
| 135 |
from arq.connections import RedisSettings
|
| 136 |
settings = get_settings()
|
| 137 |
redis = await create_pool(RedisSettings.from_dsn(settings.REDIS_URL))
|
| 138 |
+
await redis.enqueue_job("notify_mentions", str(current_user.workspace_id), ticket.title, mentions, ticket_id=str(ticket.id))
|
| 139 |
await redis.close()
|
| 140 |
except Exception as e:
|
| 141 |
print(f"FAILED TO QUEUE MENTION NOTIFICATION: {e}")
|
|
|
|
| 154 |
str(ticket.created_by),
|
| 155 |
str(ticket.workspace_id),
|
| 156 |
"💬 Expert Response",
|
| 157 |
+
f"An expert has replied to your ticket: '{ticket.title}'",
|
| 158 |
+
link=f"/dashboard?ticket={ticket.id}"
|
| 159 |
)
|
| 160 |
except Exception as e:
|
| 161 |
logger.error(f"Failed to queue customer response notification: {e}")
|
api/v1/tickets.py
CHANGED
|
@@ -270,7 +270,8 @@ async def create_ticket(
|
|
| 270 |
str(new_ticket.created_by),
|
| 271 |
str(new_ticket.workspace_id),
|
| 272 |
"🎟️ Ticket Created",
|
| 273 |
-
f"We've received your request: '{new_ticket.title}'. Our team has been notified."
|
|
|
|
| 274 |
)
|
| 275 |
|
| 276 |
logger.info(f"Ticket created: {new_ticket.id} by user {current_user.id} in workspace {current_user.workspace_id}")
|
|
@@ -318,7 +319,7 @@ async def search_tickets(
|
|
| 318 |
Ticket,
|
| 319 |
(1 - Ticket.embedding.cosine_distance(query_vector)).label("sim_score")
|
| 320 |
)
|
| 321 |
-
.options(joinedload(Ticket.creator), joinedload(Ticket.assignee))
|
| 322 |
.where(
|
| 323 |
Ticket.deleted_at.is_(None),
|
| 324 |
Ticket.embedding.isnot(None)
|
|
@@ -341,7 +342,7 @@ async def search_tickets(
|
|
| 341 |
func.plainto_tsquery('english', q)
|
| 342 |
).label("vis_score")
|
| 343 |
)
|
| 344 |
-
.options(joinedload(Ticket.creator), joinedload(Ticket.assignee))
|
| 345 |
.join(Attachment, Ticket.id == Attachment.ticket_id)
|
| 346 |
.where(
|
| 347 |
Attachment.search_vector.op("@@")(func.plainto_tsquery('english', q))
|
|
@@ -366,7 +367,7 @@ async def search_tickets(
|
|
| 366 |
func.plainto_tsquery('english', q)
|
| 367 |
).label("kw_score")
|
| 368 |
)
|
| 369 |
-
.options(joinedload(Ticket.creator), joinedload(Ticket.assignee))
|
| 370 |
.where(
|
| 371 |
Ticket.search_vector.op("@@")(func.plainto_tsquery('english', q))
|
| 372 |
)
|
|
@@ -755,7 +756,8 @@ async def update_ticket(
|
|
| 755 |
str(update_data["assigned_to"]),
|
| 756 |
str(ticket.workspace_id),
|
| 757 |
"Ticket Reassigned",
|
| 758 |
-
f"Ticket '{ticket.title}' has been reassigned to you by {current_user.full_name or 'Admin'}."
|
|
|
|
| 759 |
)
|
| 760 |
# B) Notify Customer (Creator) if not self-assigning by customer
|
| 761 |
if ticket.created_by != update_data["assigned_to"]:
|
|
@@ -764,7 +766,8 @@ async def update_ticket(
|
|
| 764 |
str(ticket.created_by),
|
| 765 |
str(ticket.workspace_id),
|
| 766 |
"👷 Expert Assigned",
|
| 767 |
-
f"An expert has been assigned to your ticket '{ticket.title}' and is reviewing it now."
|
|
|
|
| 768 |
)
|
| 769 |
|
| 770 |
audit = AuditLog(
|
|
@@ -819,9 +822,18 @@ async def delete_ticket(
|
|
| 819 |
if current_user.role not in [UserRole.SC_ADMIN, UserRole.SC_LEAD]:
|
| 820 |
raise HTTPException(status_code=403, detail="Permission denied")
|
| 821 |
|
| 822 |
-
stmt =
|
| 823 |
-
Ticket
|
| 824 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
)
|
| 826 |
if current_user.role != UserRole.SC_ADMIN:
|
| 827 |
stmt = stmt.where(Ticket.workspace_id == current_user.workspace_id)
|
|
@@ -1004,7 +1016,8 @@ async def escalate_ticket(
|
|
| 1004 |
user_id=manager_user.id,
|
| 1005 |
workspace_id=ticket.workspace_id,
|
| 1006 |
title="🚨 Manual Escalation Alert",
|
| 1007 |
-
message=f"Ticket '{ticket.title}' has been manually escalated by {current_user.full_name}. Priority: P0."
|
|
|
|
| 1008 |
)
|
| 1009 |
|
| 1010 |
# Notify Creator: We're on it!
|
|
@@ -1013,7 +1026,8 @@ async def escalate_ticket(
|
|
| 1013 |
str(ticket.created_by),
|
| 1014 |
str(ticket.workspace_id),
|
| 1015 |
"⚡ Priority Boosted",
|
| 1016 |
-
f"Your ticket '{ticket.title}' has been prioritized for immediate leadership review."
|
|
|
|
| 1017 |
)
|
| 1018 |
|
| 1019 |
logger.info(f"Ticket {ticket.id} manually escalated by {current_user.id}")
|
|
|
|
| 270 |
str(new_ticket.created_by),
|
| 271 |
str(new_ticket.workspace_id),
|
| 272 |
"🎟️ Ticket Created",
|
| 273 |
+
f"We've received your request: '{new_ticket.title}'. Our team has been notified.",
|
| 274 |
+
link=f"/dashboard?ticket={new_ticket.id}"
|
| 275 |
)
|
| 276 |
|
| 277 |
logger.info(f"Ticket created: {new_ticket.id} by user {current_user.id} in workspace {current_user.workspace_id}")
|
|
|
|
| 319 |
Ticket,
|
| 320 |
(1 - Ticket.embedding.cosine_distance(query_vector)).label("sim_score")
|
| 321 |
)
|
| 322 |
+
.options(joinedload(Ticket.creator), joinedload(Ticket.assignee), joinedload(Ticket.feedback))
|
| 323 |
.where(
|
| 324 |
Ticket.deleted_at.is_(None),
|
| 325 |
Ticket.embedding.isnot(None)
|
|
|
|
| 342 |
func.plainto_tsquery('english', q)
|
| 343 |
).label("vis_score")
|
| 344 |
)
|
| 345 |
+
.options(joinedload(Ticket.creator), joinedload(Ticket.assignee), joinedload(Ticket.feedback))
|
| 346 |
.join(Attachment, Ticket.id == Attachment.ticket_id)
|
| 347 |
.where(
|
| 348 |
Attachment.search_vector.op("@@")(func.plainto_tsquery('english', q))
|
|
|
|
| 367 |
func.plainto_tsquery('english', q)
|
| 368 |
).label("kw_score")
|
| 369 |
)
|
| 370 |
+
.options(joinedload(Ticket.creator), joinedload(Ticket.assignee), joinedload(Ticket.feedback))
|
| 371 |
.where(
|
| 372 |
Ticket.search_vector.op("@@")(func.plainto_tsquery('english', q))
|
| 373 |
)
|
|
|
|
| 756 |
str(update_data["assigned_to"]),
|
| 757 |
str(ticket.workspace_id),
|
| 758 |
"Ticket Reassigned",
|
| 759 |
+
f"Ticket '{ticket.title}' has been reassigned to you by {current_user.full_name or 'Admin'}.",
|
| 760 |
+
link=f"/dashboard?ticket={ticket.id}"
|
| 761 |
)
|
| 762 |
# B) Notify Customer (Creator) if not self-assigning by customer
|
| 763 |
if ticket.created_by != update_data["assigned_to"]:
|
|
|
|
| 766 |
str(ticket.created_by),
|
| 767 |
str(ticket.workspace_id),
|
| 768 |
"👷 Expert Assigned",
|
| 769 |
+
f"An expert has been assigned to your ticket '{ticket.title}' and is reviewing it now.",
|
| 770 |
+
link=f"/dashboard?ticket={ticket.id}"
|
| 771 |
)
|
| 772 |
|
| 773 |
audit = AuditLog(
|
|
|
|
| 822 |
if current_user.role not in [UserRole.SC_ADMIN, UserRole.SC_LEAD]:
|
| 823 |
raise HTTPException(status_code=403, detail="Permission denied")
|
| 824 |
|
| 825 |
+
stmt = (
|
| 826 |
+
select(Ticket)
|
| 827 |
+
.options(
|
| 828 |
+
joinedload(Ticket.creator),
|
| 829 |
+
joinedload(Ticket.assignee),
|
| 830 |
+
joinedload(Ticket.resolver),
|
| 831 |
+
joinedload(Ticket.feedback)
|
| 832 |
+
)
|
| 833 |
+
.where(
|
| 834 |
+
Ticket.id == ticket_id,
|
| 835 |
+
Ticket.deleted_at.is_(None)
|
| 836 |
+
)
|
| 837 |
)
|
| 838 |
if current_user.role != UserRole.SC_ADMIN:
|
| 839 |
stmt = stmt.where(Ticket.workspace_id == current_user.workspace_id)
|
|
|
|
| 1016 |
user_id=manager_user.id,
|
| 1017 |
workspace_id=ticket.workspace_id,
|
| 1018 |
title="🚨 Manual Escalation Alert",
|
| 1019 |
+
message=f"Ticket '{ticket.title}' has been manually escalated by {current_user.full_name}. Priority: P0.",
|
| 1020 |
+
link=f"/dashboard?ticket={ticket.id}"
|
| 1021 |
)
|
| 1022 |
|
| 1023 |
# Notify Creator: We're on it!
|
|
|
|
| 1026 |
str(ticket.created_by),
|
| 1027 |
str(ticket.workspace_id),
|
| 1028 |
"⚡ Priority Boosted",
|
| 1029 |
+
f"Your ticket '{ticket.title}' has been prioritized for immediate leadership review.",
|
| 1030 |
+
link=f"/dashboard?ticket={ticket.id}"
|
| 1031 |
)
|
| 1032 |
|
| 1033 |
logger.info(f"Ticket {ticket.id} manually escalated by {current_user.id}")
|
core/tasks.py
CHANGED
|
@@ -272,7 +272,7 @@ async def index_kb_article(ctx, article_id: UUID):
|
|
| 272 |
await db.rollback()
|
| 273 |
logger.error(f"FAILURE: Unified KB indexing crashed for {article_id}: {str(e)}")
|
| 274 |
|
| 275 |
-
async def send_triple_notification(ctx, user_id: UUID, workspace_id: UUID, title: str, message: str):
|
| 276 |
"""Send notification to DB, real-time WebSocket, and simulated Email."""
|
| 277 |
async with async_session_factory() as db:
|
| 278 |
# 1. Fetch User Email (Security Audit: Ensure we have a valid recipient)
|
|
@@ -285,7 +285,8 @@ async def send_triple_notification(ctx, user_id: UUID, workspace_id: UUID, title
|
|
| 285 |
workspace_id=workspace_id,
|
| 286 |
user_id=user_id,
|
| 287 |
title=title,
|
| 288 |
-
message=message
|
|
|
|
| 289 |
)
|
| 290 |
db.add(notification)
|
| 291 |
await db.commit()
|
|
@@ -296,6 +297,7 @@ async def send_triple_notification(ctx, user_id: UUID, workspace_id: UUID, title
|
|
| 296 |
"id": str(notification.id),
|
| 297 |
"title": title,
|
| 298 |
"message": message,
|
|
|
|
| 299 |
"created_at": datetime.utcnow().isoformat()
|
| 300 |
})
|
| 301 |
|
|
@@ -306,11 +308,12 @@ async def send_triple_notification(ctx, user_id: UUID, workspace_id: UUID, title
|
|
| 306 |
|
| 307 |
logger.info(f"Triple notification sent to user {user_id} ({user_email})")
|
| 308 |
|
| 309 |
-
async def notify_mentions(ctx, workspace_id: UUID, title: str, mentions: list):
|
| 310 |
"""
|
| 311 |
Background task to notify multiple users about a mention.
|
| 312 |
mentions: list of dicts [{"user_id": "...", "name": "..."}]
|
| 313 |
"""
|
|
|
|
| 314 |
for mention in mentions:
|
| 315 |
user_id = UUID(mention["user_id"]) if isinstance(mention["user_id"], str) else mention["user_id"]
|
| 316 |
await send_triple_notification(
|
|
@@ -318,7 +321,8 @@ async def notify_mentions(ctx, workspace_id: UUID, title: str, mentions: list):
|
|
| 318 |
user_id=user_id,
|
| 319 |
workspace_id=workspace_id,
|
| 320 |
title=title,
|
| 321 |
-
message=f"You were mentioned in a ticket message: {title}"
|
|
|
|
| 322 |
)
|
| 323 |
logger.info(f"Mention notifications sent to {len(mentions)} users")
|
| 324 |
|
|
@@ -372,7 +376,8 @@ async def monitor_sla_thresholds(ctx):
|
|
| 372 |
manager_user.id,
|
| 373 |
ticket.workspace_id,
|
| 374 |
"🚨 SLA Escalation Alert",
|
| 375 |
-
f"Ticket '{ticket.title}' of priority {str(ticket.priority)} has exceeded its SLA threshold. This is an official system escalation."
|
|
|
|
| 376 |
)
|
| 377 |
# MARK AS ESCALATED to avoid duplicates
|
| 378 |
ticket.is_escalated = now
|
|
|
|
| 272 |
await db.rollback()
|
| 273 |
logger.error(f"FAILURE: Unified KB indexing crashed for {article_id}: {str(e)}")
|
| 274 |
|
| 275 |
+
async def send_triple_notification(ctx, user_id: UUID, workspace_id: UUID, title: str, message: str, link: Optional[str] = None):
|
| 276 |
"""Send notification to DB, real-time WebSocket, and simulated Email."""
|
| 277 |
async with async_session_factory() as db:
|
| 278 |
# 1. Fetch User Email (Security Audit: Ensure we have a valid recipient)
|
|
|
|
| 285 |
workspace_id=workspace_id,
|
| 286 |
user_id=user_id,
|
| 287 |
title=title,
|
| 288 |
+
message=message,
|
| 289 |
+
link=link
|
| 290 |
)
|
| 291 |
db.add(notification)
|
| 292 |
await db.commit()
|
|
|
|
| 297 |
"id": str(notification.id),
|
| 298 |
"title": title,
|
| 299 |
"message": message,
|
| 300 |
+
"link": link,
|
| 301 |
"created_at": datetime.utcnow().isoformat()
|
| 302 |
})
|
| 303 |
|
|
|
|
| 308 |
|
| 309 |
logger.info(f"Triple notification sent to user {user_id} ({user_email})")
|
| 310 |
|
| 311 |
+
async def notify_mentions(ctx, workspace_id: UUID, title: str, mentions: list, ticket_id: Optional[UUID] = None):
|
| 312 |
"""
|
| 313 |
Background task to notify multiple users about a mention.
|
| 314 |
mentions: list of dicts [{"user_id": "...", "name": "..."}]
|
| 315 |
"""
|
| 316 |
+
link = f"/dashboard?ticket={ticket_id}" if ticket_id else None
|
| 317 |
for mention in mentions:
|
| 318 |
user_id = UUID(mention["user_id"]) if isinstance(mention["user_id"], str) else mention["user_id"]
|
| 319 |
await send_triple_notification(
|
|
|
|
| 321 |
user_id=user_id,
|
| 322 |
workspace_id=workspace_id,
|
| 323 |
title=title,
|
| 324 |
+
message=f"You were mentioned in a ticket message: {title}",
|
| 325 |
+
link=link
|
| 326 |
)
|
| 327 |
logger.info(f"Mention notifications sent to {len(mentions)} users")
|
| 328 |
|
|
|
|
| 376 |
manager_user.id,
|
| 377 |
ticket.workspace_id,
|
| 378 |
"🚨 SLA Escalation Alert",
|
| 379 |
+
f"Ticket '{ticket.title}' of priority {str(ticket.priority)} has exceeded its SLA threshold. This is an official system escalation.",
|
| 380 |
+
link=f"/dashboard?ticket={ticket.id}"
|
| 381 |
)
|
| 382 |
# MARK AS ESCALATED to avoid duplicates
|
| 383 |
ticket.is_escalated = now
|
frontend/apps/customer/src/components/TopBar.tsx
CHANGED
|
@@ -78,6 +78,35 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onSelectTicket,
|
|
| 78 |
}
|
| 79 |
};
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
const handleSearch = async () => {
|
| 82 |
setIsSearching(true);
|
| 83 |
setShowSearchDropdown(true);
|
|
@@ -236,11 +265,16 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onSelectTicket,
|
|
| 236 |
<div style={{ padding: 40, textAlign: "center", color: COLORS.gray400, fontSize: 13 }}>No recent activity.</div>
|
| 237 |
) : (
|
| 238 |
notifications.map(n => (
|
| 239 |
-
<div
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray800, marginBottom: 2 }}>{n.title}</div>
|
| 245 |
<div style={{ fontSize: 12, color: COLORS.gray600, lineHeight: 1.4, marginBottom: 6 }}>{n.message}</div>
|
| 246 |
<div style={{ fontSize: 10, color: COLORS.gray400 }}>{new Date(n.created_at).toLocaleString()}</div>
|
|
|
|
| 78 |
}
|
| 79 |
};
|
| 80 |
|
| 81 |
+
const handleNotifClick = async (n: any) => {
|
| 82 |
+
setIsNotifOpen(false);
|
| 83 |
+
if (!n.link) return;
|
| 84 |
+
|
| 85 |
+
// Parse deep links (e.g., /dashboard?ticket=UUID)
|
| 86 |
+
const url = new URL(n.link, window.location.origin);
|
| 87 |
+
const ticketId = url.searchParams.get('ticket');
|
| 88 |
+
|
| 89 |
+
if (ticketId) {
|
| 90 |
+
try {
|
| 91 |
+
const res = await api.get(`tickets/${ticketId}/`);
|
| 92 |
+
onSelectTicket?.(res.data);
|
| 93 |
+
} catch (err) {
|
| 94 |
+
console.error("Failed to fetch ticket from notification link:", err);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
// Handle Deep Linking on Load
|
| 100 |
+
useEffect(() => {
|
| 101 |
+
const params = new URLSearchParams(window.location.search);
|
| 102 |
+
const ticketId = params.get('ticket');
|
| 103 |
+
if (ticketId) {
|
| 104 |
+
api.get(`tickets/${ticketId}/`)
|
| 105 |
+
.then(res => onSelectTicket?.(res.data))
|
| 106 |
+
.catch(err => console.error("URL-based ticket load failed:", err));
|
| 107 |
+
}
|
| 108 |
+
}, []);
|
| 109 |
+
|
| 110 |
const handleSearch = async () => {
|
| 111 |
setIsSearching(true);
|
| 112 |
setShowSearchDropdown(true);
|
|
|
|
| 265 |
<div style={{ padding: 40, textAlign: "center", color: COLORS.gray400, fontSize: 13 }}>No recent activity.</div>
|
| 266 |
) : (
|
| 267 |
notifications.map(n => (
|
| 268 |
+
<div
|
| 269 |
+
key={n.id}
|
| 270 |
+
onClick={() => handleNotifClick(n)}
|
| 271 |
+
style={{
|
| 272 |
+
padding: "12px 16px", borderRadius: 10, marginBottom: 4,
|
| 273 |
+
background: n.is_read ? "transparent" : "#EFF6FF",
|
| 274 |
+
borderLeft: n.is_read ? "3px solid transparent" : `3px solid ${COLORS.brand}`,
|
| 275 |
+
cursor: n.link ? "pointer" : "default"
|
| 276 |
+
}}
|
| 277 |
+
>
|
| 278 |
<div style={{ fontSize: 13, fontWeight: 700, color: COLORS.gray800, marginBottom: 2 }}>{n.title}</div>
|
| 279 |
<div style={{ fontSize: 12, color: COLORS.gray600, lineHeight: 1.4, marginBottom: 6 }}>{n.message}</div>
|
| 280 |
<div style={{ fontSize: 10, color: COLORS.gray400 }}>{new Date(n.created_at).toLocaleString()}</div>
|
frontend/apps/internal/src/components/TopBar.tsx
CHANGED
|
@@ -89,6 +89,35 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onTicketSelect
|
|
| 89 |
}
|
| 90 |
};
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
// We only search on Enter now, so we remove the useEffect watcher
|
| 93 |
|
| 94 |
return (
|
|
@@ -166,7 +195,13 @@ export const TopBar: React.FC<TopBarProps> = ({ title, subtitle, onTicketSelect
|
|
| 166 |
<div className={styles.notifEmpty}>No new system alerts</div>
|
| 167 |
) : (
|
| 168 |
notifications.map(n => (
|
| 169 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
<div className={styles.notifTitle}>{n.title}</div>
|
| 171 |
<div className={styles.notifMsg}>{n.message}</div>
|
| 172 |
<div className={styles.notifTime}>{new Date(n.created_at).toLocaleString()}</div>
|
|
|
|
| 89 |
}
|
| 90 |
};
|
| 91 |
|
| 92 |
+
const handleNotifClick = async (n: any) => {
|
| 93 |
+
setShowNotifications(false);
|
| 94 |
+
if (!n.link) return;
|
| 95 |
+
|
| 96 |
+
// Parse deep links (e.g., /dashboard?ticket=UUID)
|
| 97 |
+
try {
|
| 98 |
+
const url = new URL(n.link, window.location.origin);
|
| 99 |
+
const ticketId = url.searchParams.get('ticket');
|
| 100 |
+
|
| 101 |
+
if (ticketId) {
|
| 102 |
+
const res = await api.get(`tickets/${ticketId}/`);
|
| 103 |
+
onTicketSelect?.(res.data);
|
| 104 |
+
}
|
| 105 |
+
} catch (err) {
|
| 106 |
+
console.error("Failed to parse or fetch notification link:", err);
|
| 107 |
+
}
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
// Handle Deep Linking on Load
|
| 111 |
+
useEffect(() => {
|
| 112 |
+
const params = new URLSearchParams(window.location.search);
|
| 113 |
+
const ticketId = params.get('ticket');
|
| 114 |
+
if (ticketId) {
|
| 115 |
+
api.get(`tickets/${ticketId}/`)
|
| 116 |
+
.then(res => onTicketSelect?.(res.data))
|
| 117 |
+
.catch(err => console.error("URL-based ticket load failed:", err));
|
| 118 |
+
}
|
| 119 |
+
}, []);
|
| 120 |
+
|
| 121 |
// We only search on Enter now, so we remove the useEffect watcher
|
| 122 |
|
| 123 |
return (
|
|
|
|
| 195 |
<div className={styles.notifEmpty}>No new system alerts</div>
|
| 196 |
) : (
|
| 197 |
notifications.map(n => (
|
| 198 |
+
<div
|
| 199 |
+
key={n.id}
|
| 200 |
+
className={styles.notifItem}
|
| 201 |
+
data-read={n.is_read}
|
| 202 |
+
onClick={() => handleNotifClick(n)}
|
| 203 |
+
style={{ cursor: n.link ? 'pointer' : 'default' }}
|
| 204 |
+
>
|
| 205 |
<div className={styles.notifTitle}>{n.title}</div>
|
| 206 |
<div className={styles.notifMsg}>{n.message}</div>
|
| 207 |
<div className={styles.notifTime}>{new Date(n.created_at).toLocaleString()}</div>
|
main.py
CHANGED
|
@@ -56,9 +56,14 @@ app = FastAPI(
|
|
| 56 |
lifespan=lifespan,
|
| 57 |
docs_url="/docs",
|
| 58 |
redoc_url="/redoc",
|
| 59 |
-
strict_slashes=
|
| 60 |
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# --- OPENTELEMETRY TRACING ---
|
| 63 |
setup_telemetry(app)
|
| 64 |
|
|
@@ -128,6 +133,4 @@ app.include_router(nexus_stream.router, prefix=f"{settings.API_V1_STR}/nexus", t
|
|
| 128 |
app.include_router(system.router, prefix=f"{settings.API_V1_STR}/system", tags=["System Diagnostics"])
|
| 129 |
app.include_router(websockets.router, tags=["websockets"])
|
| 130 |
|
| 131 |
-
|
| 132 |
-
def health_check():
|
| 133 |
-
return {"status": "ok"}
|
|
|
|
| 56 |
lifespan=lifespan,
|
| 57 |
docs_url="/docs",
|
| 58 |
redoc_url="/redoc",
|
| 59 |
+
strict_slashes=True,
|
| 60 |
)
|
| 61 |
|
| 62 |
+
@app.get("/health", tags=["System"])
|
| 63 |
+
@app.get("/health/", tags=["System"])
|
| 64 |
+
def health_check():
|
| 65 |
+
return {"status": "ok"}
|
| 66 |
+
|
| 67 |
# --- OPENTELEMETRY TRACING ---
|
| 68 |
setup_telemetry(app)
|
| 69 |
|
|
|
|
| 133 |
app.include_router(system.router, prefix=f"{settings.API_V1_STR}/system", tags=["System Diagnostics"])
|
| 134 |
app.include_router(websockets.router, tags=["websockets"])
|
| 135 |
|
| 136 |
+
|
|
|
|
|
|
models/notification.py
CHANGED
|
@@ -18,6 +18,7 @@ class Notification(Base):
|
|
| 18 |
title = Column(String(255), nullable=False)
|
| 19 |
message = Column(Text, nullable=False)
|
| 20 |
is_read = Column(Boolean, default=False)
|
|
|
|
| 21 |
created_at = Column(
|
| 22 |
DateTime(timezone=False),
|
| 23 |
default=datetime.utcnow,
|
|
|
|
| 18 |
title = Column(String(255), nullable=False)
|
| 19 |
message = Column(Text, nullable=False)
|
| 20 |
is_read = Column(Boolean, default=False)
|
| 21 |
+
link = Column(String(512), nullable=True) # Optional URL/Route to navigate to
|
| 22 |
created_at = Column(
|
| 23 |
DateTime(timezone=False),
|
| 24 |
default=datetime.utcnow,
|