UMBRA/backend/app/models/settings.py
Kyle Pope 15c99152d3 Address QA review: model registry, NOT NULL constraint, variable naming, toggle defaults, lockout UX
- C3: Register User, UserSession, NtfySent, TOTPUsage, BackupCode in models/__init__.py
- C4: Enforce settings.user_id NOT NULL after backfill in migration 023, update model
- W4: Rename misleading current_user → current_settings in dashboard.py
- W5: Match NtfySettingsSection initial state defaults to backend (true/1/2)
- W8: Clear lockout banner on username/password input change in LockScreen

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 04:34:21 +08:00

47 lines
2.5 KiB
Python

from sqlalchemy import String, Integer, Float, Boolean, ForeignKey, func
from sqlalchemy.orm import Mapped, mapped_column
from datetime import datetime
from typing import Optional
from app.database import Base
class Settings(Base):
__tablename__ = "settings"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
# FK to users table — NOT NULL enforced by migration 023 after data backfill
user_id: Mapped[int] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
index=True,
)
accent_color: Mapped[str] = mapped_column(String(20), default="cyan")
upcoming_days: Mapped[int] = mapped_column(Integer, default=7)
preferred_name: Mapped[str | None] = mapped_column(String(100), nullable=True, default=None)
weather_city: Mapped[str | None] = mapped_column(String(100), nullable=True, default=None)
weather_lat: Mapped[float | None] = mapped_column(Float, nullable=True, default=None)
weather_lon: Mapped[float | None] = mapped_column(Float, nullable=True, default=None)
first_day_of_week: Mapped[int] = mapped_column(Integer, default=0) # 0=Sunday, 1=Monday
# ntfy push notification configuration
ntfy_server_url: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, default=None)
ntfy_topic: Mapped[Optional[str]] = mapped_column(String(255), nullable=True, default=None)
ntfy_auth_token: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, default=None)
ntfy_enabled: Mapped[bool] = mapped_column(Boolean, default=False, server_default="false")
# Per-type notification toggles (default on so they work immediately once master is enabled)
ntfy_events_enabled: Mapped[bool] = mapped_column(Boolean, default=True, server_default="true")
ntfy_reminders_enabled: Mapped[bool] = mapped_column(Boolean, default=True, server_default="true")
ntfy_todos_enabled: Mapped[bool] = mapped_column(Boolean, default=True, server_default="true")
ntfy_projects_enabled: Mapped[bool] = mapped_column(Boolean, default=True, server_default="true")
# Lead time controls
ntfy_event_lead_minutes: Mapped[int] = mapped_column(Integer, default=15, server_default="15")
ntfy_todo_lead_days: Mapped[int] = mapped_column(Integer, default=1, server_default="1")
ntfy_project_lead_days: Mapped[int] = mapped_column(Integer, default=2, server_default="2")
created_at: Mapped[datetime] = mapped_column(default=func.now())
updated_at: Mapped[datetime] = mapped_column(default=func.now(), onupdate=func.now())