feat(notifications): add Phase 4 Slice 2 — multi-channel notification system
Full notification infrastructure with in-app, email, Slack, and Teams channels: Backend: - NotificationConfig, NotificationLog, Notification models + migration - Notification service with event routing, channel delivery, retry logic - 9 API endpoints (config CRUD + in-app notifications) - APScheduler retry job with exponential backoff (30s, 2m, 10m) - Wired into escalation, proposal approval, and knowledge flywheel - Pydantic event key validation, cross-tenant protection on recipients Frontend: - TypeScript types + API client for all notification endpoints - NotificationsPanel: bell icon with unread badge, dropdown, mark-read - NotificationSettings: channel config, event toggles, test, delete confirm - Notifications tab on IntegrationsPage - ARIA attributes, Escape handler, settings link on panel Review fixes (13 issues resolved): - notify() no longer commits/rolls back caller's transaction (critical) - retry_failed_notifications returns count instead of None (critical) - NotificationSettings moved inside dedicated tab (critical) - target_user_ids scoped by account_id (security) - Email loop collects all failures before raising - Slack webhook validates response body - events_enabled rejects unknown event keys - link column widened to String(500) - Dead code removed from _auto_reinforce - Delete confirmation, ARIA, Escape key support Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
85
backend/app/schemas/notification.py
Normal file
85
backend/app/schemas/notification.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""Pydantic schemas for notification system."""
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
VALID_EVENTS = {
|
||||
"session.escalated",
|
||||
"session.high_priority",
|
||||
"proposal.pending",
|
||||
"proposal.approved",
|
||||
"knowledge_gap.detected",
|
||||
}
|
||||
|
||||
|
||||
class NotificationConfigCreate(BaseModel):
|
||||
channel: str = Field(..., pattern="^(email|slack_webhook|teams_webhook)$")
|
||||
webhook_url: str | None = None
|
||||
email_addresses: list[str] | None = None
|
||||
events_enabled: dict[str, bool] = Field(
|
||||
default_factory=lambda: {e: True for e in VALID_EVENTS}
|
||||
)
|
||||
|
||||
@field_validator("events_enabled")
|
||||
@classmethod
|
||||
def validate_event_keys(cls, v: dict[str, bool]) -> dict[str, bool]:
|
||||
invalid = set(v) - VALID_EVENTS
|
||||
if invalid:
|
||||
raise ValueError(f"Unknown event keys: {invalid}")
|
||||
return v
|
||||
|
||||
|
||||
class NotificationConfigUpdate(BaseModel):
|
||||
webhook_url: str | None = None
|
||||
email_addresses: list[str] | None = None
|
||||
is_active: bool | None = None
|
||||
events_enabled: dict[str, bool] | None = None
|
||||
|
||||
@field_validator("events_enabled")
|
||||
@classmethod
|
||||
def validate_event_keys(cls, v: dict[str, bool] | None) -> dict[str, bool] | None:
|
||||
if v is not None:
|
||||
invalid = set(v) - VALID_EVENTS
|
||||
if invalid:
|
||||
raise ValueError(f"Unknown event keys: {invalid}")
|
||||
return v
|
||||
|
||||
|
||||
class NotificationConfigResponse(BaseModel):
|
||||
id: UUID
|
||||
channel: str
|
||||
webhook_url: str | None
|
||||
email_addresses: list[str] | None
|
||||
is_active: bool
|
||||
events_enabled: dict[str, bool]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class NotificationResponse(BaseModel):
|
||||
id: UUID
|
||||
event: str
|
||||
title: str
|
||||
body: str | None
|
||||
link: str | None
|
||||
is_read: bool
|
||||
created_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class UnreadCountResponse(BaseModel):
|
||||
count: int
|
||||
|
||||
|
||||
class NotificationTestRequest(BaseModel):
|
||||
config_id: UUID
|
||||
|
||||
|
||||
class NotificationTestResponse(BaseModel):
|
||||
success: bool
|
||||
message: str
|
||||
Reference in New Issue
Block a user