Backend: - Add 2FA authentication with TOTP support - Add API keys management system - Add audit logging for security events - Add file upload/management system - Add notifications system with preferences - Add session management - Add webhooks integration - Add analytics endpoints - Add export functionality - Add password policy enforcement - Add new database migrations for core tables Frontend: - Add module position system (top/bottom sidebar sections) - Add search and notifications module configuration tabs - Add mobile logo replacing hamburger menu - Center page title absolutely when no tabs present - Align sidebar footer toggles with navigation items - Add lighter icon color in dark theme for mobile - Add API keys management page - Add notifications page with context - Add admin analytics and audit logs pages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""Notification database model for in-app notifications."""
|
|
|
|
import json
|
|
import uuid
|
|
from sqlalchemy import Column, String, Boolean, ForeignKey, Text
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.types import DateTime
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class Notification(Base):
|
|
"""Notification model for in-app user notifications."""
|
|
|
|
__tablename__ = "notifications"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
|
|
# Recipient
|
|
user_id = Column(String(36), ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
|
|
# Notification content
|
|
title = Column(String(200), nullable=False)
|
|
message = Column(Text, nullable=True)
|
|
type = Column(String(50), default="info") # info, success, warning, error, system
|
|
|
|
# Link (optional) - where to navigate when clicked
|
|
link = Column(String(500), nullable=True)
|
|
|
|
# Extra data (JSON string)
|
|
extra_data = Column(Text, nullable=True)
|
|
|
|
# Status
|
|
is_read = Column(Boolean, default=False, nullable=False, index=True)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime, server_default=func.now(), nullable=False, index=True)
|
|
read_at = Column(DateTime, nullable=True)
|
|
|
|
@property
|
|
def parsed_extra_data(self) -> dict | None:
|
|
"""Get extra_data as parsed dict."""
|
|
if self.extra_data:
|
|
try:
|
|
return json.loads(self.extra_data)
|
|
except json.JSONDecodeError:
|
|
return None
|
|
return None
|
|
|
|
def __repr__(self):
|
|
return f"<Notification(id={self.id}, user_id={self.user_id}, title='{self.title[:30]}')>"
|