## Critical Issues (CRIT-001~003) - All Fixed
- JWT secret key validation with pydantic field_validator
- Login audit logging for success/failure attempts
- Frontend API path prefix removal
## High Priority Issues (HIGH-001~008) - All Fixed
- Project soft delete using is_active flag
- Redis session token bytes handling
- Rate limiting with slowapi (5 req/min for login)
- Attachment API permission checks
- Kanban view with drag-and-drop
- Workload heatmap UI (WorkloadPage, WorkloadHeatmap)
- TaskDetailModal integrating Comments/Attachments
- UserSelect component for task assignment
## Medium Priority Issues (MED-001~012) - All Fixed
- MED-001~005: DB commits, N+1 queries, datetime, error format, blocker flag
- MED-006: Project health dashboard (HealthService, ProjectHealthPage)
- MED-007: Capacity update API (PUT /api/users/{id}/capacity)
- MED-008: Schedule triggers (cron parsing, deadline reminders)
- MED-009: Watermark feature (image/PDF watermarking)
- MED-010~012: useEffect deps, DOM operations, PDF export
## New Files
- backend/app/api/health/ - Project health API
- backend/app/services/health_service.py
- backend/app/services/trigger_scheduler.py
- backend/app/services/watermark_service.py
- backend/app/core/rate_limiter.py
- frontend/src/pages/ProjectHealthPage.tsx
- frontend/src/components/ProjectHealthCard.tsx
- frontend/src/components/KanbanBoard.tsx
- frontend/src/components/WorkloadHeatmap.tsx
## Tests
- 113 new tests passing (health: 32, users: 14, triggers: 35, watermark: 32)
## OpenSpec Archives
- add-project-health-dashboard
- add-capacity-update-api
- add-schedule-triggers
- add-watermark-feature
- add-rate-limiting
- enhance-frontend-ux
- add-resource-management-ui
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
122 lines
4.0 KiB
Python
122 lines
4.0 KiB
Python
from typing import Optional
|
|
from datetime import datetime, timezone
|
|
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.models import User, Notification
|
|
from app.schemas.notification import (
|
|
NotificationResponse, NotificationListResponse, UnreadCountResponse
|
|
)
|
|
from app.middleware.auth import get_current_user
|
|
|
|
router = APIRouter(tags=["notifications"])
|
|
|
|
|
|
def notification_to_response(notification: Notification) -> NotificationResponse:
|
|
"""Convert Notification model to NotificationResponse."""
|
|
return NotificationResponse(
|
|
id=notification.id,
|
|
type=notification.type,
|
|
reference_type=notification.reference_type,
|
|
reference_id=notification.reference_id,
|
|
title=notification.title,
|
|
message=notification.message,
|
|
is_read=notification.is_read,
|
|
created_at=notification.created_at,
|
|
read_at=notification.read_at,
|
|
)
|
|
|
|
|
|
@router.get("/api/notifications", response_model=NotificationListResponse)
|
|
async def list_notifications(
|
|
is_read: Optional[bool] = Query(None, description="Filter by read status"),
|
|
limit: int = Query(50, ge=1, le=100, description="Number of notifications to return"),
|
|
offset: int = Query(0, ge=0, description="Offset for pagination"),
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user),
|
|
):
|
|
"""List notifications for the current user."""
|
|
query = db.query(Notification).filter(Notification.user_id == current_user.id)
|
|
|
|
if is_read is not None:
|
|
query = query.filter(Notification.is_read == is_read)
|
|
|
|
total = query.count()
|
|
unread_count = db.query(Notification).filter(
|
|
Notification.user_id == current_user.id,
|
|
Notification.is_read == False,
|
|
).count()
|
|
|
|
notifications = query.order_by(Notification.created_at.desc()).offset(offset).limit(limit).all()
|
|
|
|
return NotificationListResponse(
|
|
notifications=[notification_to_response(n) for n in notifications],
|
|
total=total,
|
|
unread_count=unread_count,
|
|
)
|
|
|
|
|
|
@router.get("/api/notifications/unread-count", response_model=UnreadCountResponse)
|
|
async def get_unread_count(
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user),
|
|
):
|
|
"""Get count of unread notifications."""
|
|
count = db.query(Notification).filter(
|
|
Notification.user_id == current_user.id,
|
|
Notification.is_read == False,
|
|
).count()
|
|
|
|
return UnreadCountResponse(unread_count=count)
|
|
|
|
|
|
@router.put("/api/notifications/{notification_id}/read", response_model=NotificationResponse)
|
|
async def mark_as_read(
|
|
notification_id: str,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user),
|
|
):
|
|
"""Mark a notification as read."""
|
|
notification = db.query(Notification).filter(
|
|
Notification.id == notification_id,
|
|
Notification.user_id == current_user.id,
|
|
).first()
|
|
|
|
if not notification:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Notification not found",
|
|
)
|
|
|
|
if not notification.is_read:
|
|
notification.is_read = True
|
|
# Use naive datetime for consistency with database storage
|
|
notification.read_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
|
db.commit()
|
|
db.refresh(notification)
|
|
|
|
return notification_to_response(notification)
|
|
|
|
|
|
@router.put("/api/notifications/read-all", response_model=dict)
|
|
async def mark_all_as_read(
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user),
|
|
):
|
|
"""Mark all notifications as read."""
|
|
# Use naive datetime for consistency with database storage
|
|
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
|
|
|
updated_count = db.query(Notification).filter(
|
|
Notification.user_id == current_user.id,
|
|
Notification.is_read == False,
|
|
).update({
|
|
Notification.is_read: True,
|
|
Notification.read_at: now,
|
|
})
|
|
|
|
db.commit()
|
|
|
|
return {"updated_count": updated_count}
|