Ergänzung Datenschutzerklärung und Impressum, Fristenformular in Einstellungen
This commit is contained in:
@@ -26,16 +26,18 @@ from app.mail import (
|
||||
from app.maintenance import describe, run_cleanup
|
||||
from app.models import EmailChange, User
|
||||
from app.schemas import MailCheckOut, MailTestIn, MessageOut
|
||||
from app.runtime_settings import BY_KEY, describe_durations, set_duration
|
||||
from app.schemas_admin import (
|
||||
AdminSettingsIn,
|
||||
AdminSettingsOut,
|
||||
AdminStatsOut,
|
||||
AdminUserOut,
|
||||
DeleteUserIn,
|
||||
DurationOut,
|
||||
EmailChangeIn,
|
||||
UserCreateIn,
|
||||
)
|
||||
from app.security import check_rate_limit, normalize_email, utcnow
|
||||
from app.security import bucket_key, check_rate_limit, normalize_email, utcnow
|
||||
from app.users import (
|
||||
EMAIL_CHANGE_HOURS,
|
||||
WELCOME_DAYS,
|
||||
@@ -66,18 +68,17 @@ def _settings_out(db) -> AdminSettingsOut:
|
||||
return AdminSettingsOut(
|
||||
allow_self_registration=self_registration_enabled(db),
|
||||
locked_by_env=registration_locked_by_env(),
|
||||
auto_deactivate_months=months_setting(
|
||||
db, "auto_deactivate_months", DEFAULT_DEACTIVATE_MONTHS
|
||||
),
|
||||
auto_delete_months=months_setting(
|
||||
db, "auto_delete_months", DEFAULT_DELETE_MONTHS
|
||||
),
|
||||
auto_archive_months=months_setting(
|
||||
db, "auto_archive_months", DEFAULT_ARCHIVE_MONTHS
|
||||
),
|
||||
archive_delete_months=months_setting(
|
||||
db, "archive_delete_months", DEFAULT_ARCHIVE_DELETE_MONTHS
|
||||
),
|
||||
durations=[DurationOut(**entry) for entry in describe_durations(db)],
|
||||
fixed={
|
||||
"Zähler der Missbrauchsabwehr": "24 Stunden",
|
||||
"Fehlgeschlagene Produktabfragen":
|
||||
f"{settings.product_miss_days} Tage (PRODUCT_MISS_DAYS)",
|
||||
"Aufräumlauf":
|
||||
f"alle {settings.cleanup_interval_hours} Stunden "
|
||||
"(CLEANUP_INTERVAL_HOURS)",
|
||||
"Zugriffsprotokolle des Webservers":
|
||||
"Sache der Protokollrotation auf dem Server, nicht der Anwendung",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -102,14 +103,12 @@ def write_settings(payload: AdminSettingsIn, db: DbSession, admin: AdminUser):
|
||||
"true" if payload.allow_self_registration else "false",
|
||||
)
|
||||
|
||||
if payload.auto_deactivate_months is not None:
|
||||
set_setting(db, "auto_deactivate_months", str(payload.auto_deactivate_months))
|
||||
if payload.auto_delete_months is not None:
|
||||
set_setting(db, "auto_delete_months", str(payload.auto_delete_months))
|
||||
if payload.auto_archive_months is not None:
|
||||
set_setting(db, "auto_archive_months", str(payload.auto_archive_months))
|
||||
if payload.archive_delete_months is not None:
|
||||
set_setting(db, "archive_delete_months", str(payload.archive_delete_months))
|
||||
for key, value in (payload.durations or {}).items():
|
||||
if key not in BY_KEY:
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST, f"Unbekannte Frist: {key}"
|
||||
)
|
||||
set_duration(db, key, value)
|
||||
|
||||
db.commit()
|
||||
return _settings_out(db)
|
||||
@@ -222,7 +221,8 @@ def add_user(
|
||||
background: BackgroundTasks,
|
||||
):
|
||||
if not check_rate_limit(
|
||||
db, f"admin-create:{client_ip(request)}", limit=30, window_minutes=60
|
||||
db, bucket_key(db, "admin-create", client_ip(request)),
|
||||
limit=30, window_minutes=60,
|
||||
):
|
||||
db.commit()
|
||||
raise HTTPException(status.HTTP_429_TOO_MANY_REQUESTS, "Zu viele Anlagen.")
|
||||
@@ -241,7 +241,8 @@ def add_user(
|
||||
|
||||
background.add_task(
|
||||
send_welcome, email, token,
|
||||
admin.display_name or admin.email.split("@")[0], WELCOME_DAYS,
|
||||
admin.display_name or admin.email.split("@")[0],
|
||||
get_duration(db, "welcome_days"),
|
||||
)
|
||||
return _user_out(user, {}, {}, {})
|
||||
|
||||
@@ -268,16 +269,19 @@ def resend_welcome(
|
||||
"nutzt die Person „Passwort vergessen“ auf der Anmeldeseite.",
|
||||
)
|
||||
|
||||
if not check_rate_limit(db, f"admin-welcome:{user.id}", limit=5, window_minutes=60):
|
||||
if not check_rate_limit(
|
||||
db, bucket_key(db, "admin-welcome", user.id), limit=5, window_minutes=60
|
||||
):
|
||||
db.commit()
|
||||
raise HTTPException(status.HTTP_429_TOO_MANY_REQUESTS, "Zu viele Versuche.")
|
||||
|
||||
token = issue_token(db, user, "welcome", hours=WELCOME_DAYS * 24)
|
||||
days = get_duration(db, "welcome_days")
|
||||
token = issue_token(db, user, "welcome", hours=days * 24)
|
||||
db.commit()
|
||||
|
||||
background.add_task(
|
||||
send_welcome, user.email, token,
|
||||
admin.display_name or admin.email.split("@")[0], WELCOME_DAYS,
|
||||
admin.display_name or admin.email.split("@")[0], days,
|
||||
)
|
||||
return MessageOut(detail=f"Willkommensnachricht erneut an {user.email} versendet.")
|
||||
|
||||
@@ -310,12 +314,13 @@ def change_email(
|
||||
change, raw_new, raw_old = start_email_change(db, user, target, admin.id)
|
||||
db.commit()
|
||||
|
||||
change_hours = get_duration(db, "email_change_hours")
|
||||
background.add_task(
|
||||
send_email_change_verify, target, raw_new, old_email, EMAIL_CHANGE_HOURS
|
||||
send_email_change_verify, target, raw_new, old_email, change_hours
|
||||
)
|
||||
if change.requires_old and raw_old:
|
||||
background.add_task(
|
||||
send_email_change_verify_old, old_email, raw_old, target, EMAIL_CHANGE_HOURS
|
||||
send_email_change_verify_old, old_email, raw_old, target, change_hours
|
||||
)
|
||||
detail = (
|
||||
f"Bestätigungslinks an {target} und {old_email} versendet. "
|
||||
@@ -324,7 +329,7 @@ def change_email(
|
||||
)
|
||||
else:
|
||||
background.add_task(
|
||||
send_email_change_notice, old_email, target, EMAIL_CHANGE_HOURS
|
||||
send_email_change_notice, old_email, target, change_hours
|
||||
)
|
||||
detail = (
|
||||
f"Bestätigungslink an {target} versendet, Hinweis an {old_email}. "
|
||||
|
||||
Reference in New Issue
Block a user