mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 11:12:35 +02:00
Add tests, docs, and ruff fixes for per-user email notifications - Fix missing timezone import in email_service.py (F821) - Fix unused lambda arg in main.py asyncio done_callback (ARG005) - Fix E302 blank line spacing for mark_printer_stopped_by_user - Fix F821/UP037 forward reference in user_email_pref model - Fix SettingsPage test for duplicate "Notifications" text - Add backend unit tests for permissions, schemas, and templates - Add backend integration tests for user-notifications API - Add frontend tests for NotificationsPage - Add user_email_pref model import to test conftest - Update CHANGELOG and README
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
"""User email notification preference model."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from backend.app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from backend.app.models.user import User
|
|
|
|
|
|
class UserEmailPreference(Base):
|
|
"""Stores per-user email notification preferences for their own print jobs."""
|
|
|
|
__tablename__ = "user_email_preferences"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, unique=True, index=True
|
|
)
|
|
|
|
# Print lifecycle notifications (only for jobs submitted by this user)
|
|
notify_print_start: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
notify_print_complete: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
notify_print_failed: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
notify_print_stopped: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationship
|
|
user: Mapped[User] = relationship(back_populates="email_preferences")
|