🎉 Refactor & Update Backend Files, Documentation 📚
This commit is contained in:
175
backend/utils/email_notification.py
Normal file
175
backend/utils/email_notification.py
Normal file
@@ -0,0 +1,175 @@
|
||||
"""
|
||||
Offline-kompatible E-Mail-Benachrichtigung für MYP-System
|
||||
========================================================
|
||||
|
||||
Da das System im Produktionsbetrieb offline läuft, werden alle E-Mail-Benachrichtigungen
|
||||
nur geloggt aber nicht tatsächlich versendet.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
from utils.logging_config import get_logger
|
||||
|
||||
logger = get_logger("email_notification")
|
||||
|
||||
class OfflineEmailNotification:
|
||||
"""
|
||||
Offline-E-Mail-Benachrichtigung die nur Logs erstellt.
|
||||
Simuliert E-Mail-Versand für Offline-Betrieb.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.enabled = False # Immer deaktiviert im Offline-Modus
|
||||
logger.info("📧 Offline-E-Mail-Benachrichtigung initialisiert (kein echter E-Mail-Versand)")
|
||||
|
||||
def send_email(self, to: str, subject: str, body: str, **kwargs) -> bool:
|
||||
"""
|
||||
Simuliert E-Mail-Versand durch Logging.
|
||||
|
||||
Args:
|
||||
to: E-Mail-Empfänger
|
||||
subject: E-Mail-Betreff
|
||||
body: E-Mail-Inhalt
|
||||
**kwargs: Zusätzliche Parameter
|
||||
|
||||
Returns:
|
||||
bool: Immer True (Simulation erfolgreich)
|
||||
"""
|
||||
logger.info(f"📧 [OFFLINE-SIMULATION] E-Mail würde versendet werden:")
|
||||
logger.info(f" 📮 An: {to}")
|
||||
logger.info(f" 📋 Betreff: {subject}")
|
||||
logger.info(f" 📝 Inhalt: {body[:100]}{'...' if len(body) > 100 else ''}")
|
||||
logger.info(f" 🕒 Zeitpunkt: {datetime.now().strftime('%d.%m.%Y %H:%M:%S')}")
|
||||
|
||||
if kwargs:
|
||||
logger.info(f" ⚙️ Zusätzliche Parameter: {kwargs}")
|
||||
|
||||
return True
|
||||
|
||||
def send_notification_email(self, recipient: str, notification_type: str,
|
||||
data: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
Sendet Benachrichtigungs-E-Mail (Offline-Simulation).
|
||||
|
||||
Args:
|
||||
recipient: E-Mail-Empfänger
|
||||
notification_type: Art der Benachrichtigung
|
||||
data: Daten für die Benachrichtigung
|
||||
|
||||
Returns:
|
||||
bool: Immer True (Simulation erfolgreich)
|
||||
"""
|
||||
subject = f"MYP-Benachrichtigung: {notification_type}"
|
||||
body = f"Benachrichtigung vom MYP-System:\n\n{data}"
|
||||
|
||||
return self.send_email(recipient, subject, body, notification_type=notification_type)
|
||||
|
||||
def send_maintenance_notification(self, recipient: str, task_title: str,
|
||||
task_description: str) -> bool:
|
||||
"""
|
||||
Sendet Wartungs-Benachrichtigung (Offline-Simulation).
|
||||
|
||||
Args:
|
||||
recipient: E-Mail-Empfänger
|
||||
task_title: Titel der Wartungsaufgabe
|
||||
task_description: Beschreibung der Wartungsaufgabe
|
||||
|
||||
Returns:
|
||||
bool: Immer True (Simulation erfolgreich)
|
||||
"""
|
||||
subject = f"MYP-Wartungsaufgabe: {task_title}"
|
||||
body = f"""
|
||||
Neue Wartungsaufgabe im MYP-System:
|
||||
|
||||
Titel: {task_title}
|
||||
Beschreibung: {task_description}
|
||||
Erstellt: {datetime.now().strftime('%d.%m.%Y %H:%M:%S')}
|
||||
|
||||
Bitte loggen Sie sich in das MYP-System ein, um weitere Details zu sehen.
|
||||
"""
|
||||
|
||||
return self.send_email(recipient, subject, body, task_type="maintenance")
|
||||
|
||||
# Globale Instanz für einfache Verwendung
|
||||
email_notifier = OfflineEmailNotification()
|
||||
|
||||
def send_email_notification(recipient: str, subject: str, body: str, **kwargs) -> bool:
|
||||
"""
|
||||
Haupt-Funktion für E-Mail-Versand (Offline-kompatibel).
|
||||
|
||||
Args:
|
||||
recipient: E-Mail-Empfänger
|
||||
subject: E-Mail-Betreff
|
||||
body: E-Mail-Inhalt
|
||||
**kwargs: Zusätzliche Parameter
|
||||
|
||||
Returns:
|
||||
bool: True wenn "erfolgreich" (geloggt)
|
||||
"""
|
||||
return email_notifier.send_email(recipient, subject, body, **kwargs)
|
||||
|
||||
def send_maintenance_email(recipient: str, task_title: str, task_description: str) -> bool:
|
||||
"""
|
||||
Sendet Wartungs-E-Mail (Offline-kompatibel).
|
||||
|
||||
Args:
|
||||
recipient: E-Mail-Empfänger
|
||||
task_title: Titel der Wartungsaufgabe
|
||||
task_description: Beschreibung der Wartungsaufgabe
|
||||
|
||||
Returns:
|
||||
bool: True wenn "erfolgreich" (geloggt)
|
||||
"""
|
||||
return email_notifier.send_maintenance_notification(recipient, task_title, task_description)
|
||||
|
||||
def send_guest_approval_email(recipient: str, otp_code: str, expires_at: str) -> bool:
|
||||
"""
|
||||
Sendet Gastauftrags-Genehmigung-E-Mail (Offline-kompatibel).
|
||||
|
||||
Args:
|
||||
recipient: E-Mail-Empfänger
|
||||
otp_code: OTP-Code für den Gastauftrag
|
||||
expires_at: Ablaufzeit des OTP-Codes
|
||||
|
||||
Returns:
|
||||
bool: True wenn "erfolgreich" (geloggt)
|
||||
"""
|
||||
subject = "MYP-Gastauftrag genehmigt"
|
||||
body = f"""
|
||||
Ihr Gastauftrag wurde genehmigt!
|
||||
|
||||
OTP-Code: {otp_code}
|
||||
Gültig bis: {expires_at}
|
||||
|
||||
Bitte verwenden Sie diesen Code am MYP-Terminal, um Ihren Druckauftrag zu starten.
|
||||
"""
|
||||
|
||||
return email_notifier.send_email(recipient, subject, body,
|
||||
otp_code=otp_code, expires_at=expires_at)
|
||||
|
||||
def send_guest_rejection_email(recipient: str, reason: str) -> bool:
|
||||
"""
|
||||
Sendet Gastauftrags-Ablehnungs-E-Mail (Offline-kompatibel).
|
||||
|
||||
Args:
|
||||
recipient: E-Mail-Empfänger
|
||||
reason: Grund für die Ablehnung
|
||||
|
||||
Returns:
|
||||
bool: True wenn "erfolgreich" (geloggt)
|
||||
"""
|
||||
subject = "MYP-Gastauftrag abgelehnt"
|
||||
body = f"""
|
||||
Ihr Gastauftrag wurde leider abgelehnt.
|
||||
|
||||
Grund: {reason}
|
||||
|
||||
Bei Fragen wenden Sie sich bitte an das MYP-Team.
|
||||
"""
|
||||
|
||||
return email_notifier.send_email(recipient, subject, body, rejection_reason=reason)
|
||||
|
||||
# Für Backward-Kompatibilität
|
||||
send_notification = send_email_notification
|
Reference in New Issue
Block a user