Source code for s365b.notify.settings

"""Notification settings (stored in the database, edited in the web UI)."""

from __future__ import annotations

from typing import Literal

from pydantic import Field

from s365b.core.settings_store import SettingsGroup

[docs] Method = Literal["graph", "smtp"]
[docs] SEVERITY_ORDER = {"info": 0, "warning": 1, "error": 2}
[docs] class NotificationSettings(SettingsGroup): """Who gets email, and how it is sent. The SMTP password is stored separately, encrypted (``save_secrets`` with the same key). Attributes: enabled: Send email at all. Events are recorded either way. recipients: Addresses of the backup admins. min_severity: Lowest severity emailed immediately. throttle_hours: The same alert (same de-duplication key) is sent at most once per this many hours. subject_prefix: Prefix for subjects; empty means ``[<product name>]``. method: Primary sending method. fallback: Method used when the primary fails, or ``none``. graph_sender: Mailbox the Notifications app sends as (Graph). smtp_host: SMTP relay host. smtp_port: SMTP port. smtp_security: ``starttls``, implicit ``tls``, or ``none`` (trusted internal relay only). smtp_username: SMTP user; empty for no authentication. smtp_from: From address for SMTP. """
[docs] key = "notifications"
[docs] enabled: bool = False
[docs] recipients: list[str] = Field(default_factory=list)
[docs] min_severity: Literal["info", "warning", "error"] = "warning"
[docs] throttle_hours: int = Field(6, ge=0, le=168)
[docs] subject_prefix: str = Field("", max_length=64)
[docs] method: Method = "graph"
[docs] fallback: Literal["none", "graph", "smtp"] = "none"
[docs] graph_sender: str = ""
[docs] smtp_host: str = ""
[docs] smtp_port: int = Field(587, ge=1, le=65535)
[docs] smtp_security: Literal["starttls", "tls", "none"] = "starttls"
[docs] smtp_username: str = ""
[docs] smtp_from: str = ""