feat: System-Email-Benachrichtigungen bei Freigaben und Benutzer-Erstellung

Automatische E-Mail-Benachrichtigungen ueber die konfigurierte
System-Email bei folgenden Ereignissen:

- Datei/Ordner mit Benutzer geteilt -> Empfaenger wird benachrichtigt
- Share-Link heruntergeladen -> Ersteller wird benachrichtigt (mit IP)
- Kalender mit Benutzer geteilt -> Empfaenger wird benachrichtigt
- Adressbuch mit Benutzer geteilt -> Empfaenger wird benachrichtigt
- Passwort-Eintrag/-Ordner geteilt -> Empfaenger wird benachrichtigt
- Admin erstellt neuen Benutzer -> Neuer Benutzer wird benachrichtigt

Alle Benachrichtigungen sind fail-safe (try/except), damit die
eigentliche Aktion nie durch Email-Fehler blockiert wird.
Emails werden nur gesendet wenn System-SMTP konfiguriert ist UND
der Empfaenger eine Email-Adresse hat.

Neuer Service: app/services/system_mail.py mit zentralem Helper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Hacker
2026-04-11 18:31:19 +02:00
parent 61ce2ec244
commit e811210977
6 changed files with 204 additions and 0 deletions
+9
View File
@@ -269,6 +269,7 @@ def share_calendar(cal_id):
existing = CalendarShare.query.filter_by(
calendar_id=cal_id, shared_with_id=target.id
).first()
is_new = not existing
if existing:
existing.permission = permission
else:
@@ -278,6 +279,14 @@ def share_calendar(cal_id):
db.session.add(share)
db.session.commit()
if is_new:
try:
from app.services.system_mail import notify_calendar_shared
notify_calendar_shared(cal.name, user.username, target, permission)
except Exception:
pass
return jsonify({'message': f'Kalender mit {username} geteilt'}), 200
+9
View File
@@ -246,6 +246,7 @@ def share_addressbook(book_id):
existing = AddressBookShare.query.filter_by(
address_book_id=book_id, shared_with_id=target.id
).first()
is_new = not existing
if existing:
existing.permission = permission
else:
@@ -255,6 +256,14 @@ def share_addressbook(book_id):
db.session.add(share)
db.session.commit()
if is_new:
try:
from app.services.system_mail import notify_contacts_shared
notify_contacts_shared(book.name, user.username, target, permission)
except Exception:
pass
return jsonify({'message': f'Adressbuch mit {username} geteilt'}), 200
+17
View File
@@ -368,6 +368,7 @@ def set_permission(file_id):
existing = FilePermission.query.filter_by(
file_id=file_id, user_id=target_user_id
).first()
is_new = not existing
if existing:
existing.permission = permission
else:
@@ -375,6 +376,15 @@ def set_permission(file_id):
db.session.add(perm)
db.session.commit()
# Notify user via email
if is_new:
try:
from app.services.system_mail import notify_file_shared_with_user
notify_file_shared_with_user(f.name, user.username, target)
except Exception:
pass
return jsonify({'message': 'Berechtigung gesetzt'}), 200
@@ -536,6 +546,13 @@ def share_download(token):
link.download_count += 1
db.session.commit()
# Notify creator about download
try:
from app.services.system_mail import notify_share_link_accessed
notify_share_link_accessed(link, f.name, request.remote_addr)
except Exception:
pass
return send_file(str(filepath), mimetype=f.mime_type, as_attachment=True,
download_name=f.name)
+9
View File
@@ -240,6 +240,7 @@ def share_password():
shareable_type=shareable_type, shareable_id=shareable_id,
shared_with_id=target.id
).first()
is_new = not existing
if existing:
existing.permission = permission
else:
@@ -254,6 +255,14 @@ def share_password():
db.session.add(share)
db.session.commit()
if is_new:
try:
from app.services.system_mail import notify_password_shared
notify_password_shared(shareable_type, user.username, target, permission)
except Exception:
pass
return jsonify({'message': f'Mit {username} geteilt'}), 200
+8
View File
@@ -58,6 +58,14 @@ def create_user():
db.session.add(user)
db.session.commit()
# Notify new user via email
try:
from app.services.system_mail import notify_user_created
notify_user_created(user, request.current_user.username)
except Exception:
pass
return jsonify(user.to_dict(include_email=True)), 201