multi-user: users, per-user profiles/filters/notifications, tab UI, apply forensics

* DB: users + user_profiles/filters/notifications/preferences; applications gets
  user_id + forensics_json + profile_snapshot_json; new errors table
  with 14d retention; schema versioning via MIGRATIONS list
* auth: password hashes in DB (argon2); env vars seed first admin; per-user
  sessions; CSRF bound to user id
* apply: personal info/WBS moved out of env into the request body; providers
  take an ApplyContext with Profile + submit_forms; full Playwright recorder
  (step log, console, page errors, network, screenshots, final HTML)
* web: five top-level tabs (Wohnungen/Bewerbungen/Logs/Fehler/Einstellungen);
  settings sub-tabs profil/filter/benachrichtigungen/account/benutzer;
  per-user matching, auto-apply and notifications (UI/Telegram/SMTP); red
  auto-apply switch on Wohnungen tab; forensics detail view for bewerbungen
  and fehler; retention background thread

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Moritz 2026-04-21 10:52:41 +02:00
parent e663386a19
commit c630b500ef
36 changed files with 2763 additions and 1113 deletions

View file

@ -1,6 +1,12 @@
"""
apply service config.
Personal info and WBS fields used to live here as env vars; they now come in
with every /apply request as a Profile. The only remaining settings are
browser + service-level knobs.
"""
import logging
import sys
from datetime import datetime as dt
from os import getenv
from dotenv import load_dotenv
@ -8,103 +14,43 @@ logger = logging.getLogger("flat-apply")
load_dotenv()
def get_env_or_fail(key: str, default: str = None, required: bool = True) -> str:
def get_env_or_fail(key: str, default: str | None = None, required: bool = True) -> str:
value = getenv(key, default)
if required and value is None:
logger.error(f"Missing required environment variable: {key}")
sys.exit(1)
return value
def get_bool_env(key: str, default: str = "False", required: bool = True) -> bool:
return get_env_or_fail(key, default, required).lower() in ("true", "1", "yes", "on")
def get_int_env(key: str, default: str = None, required: bool = True) -> int:
value_str = get_env_or_fail(key, default, required)
def get_bool_env(key: str, default: str = "False") -> bool:
return (getenv(key, default) or "").lower() in ("true", "1", "yes", "on")
def get_int_env(key: str, default: str) -> int:
v = getenv(key, default) or default
try:
return int(value_str)
return int(v)
except ValueError:
logger.error(f"Environment variable {key} must be an integer. Got: {value_str}")
logger.error(f"Env var {key} must be int, got {v!r}")
sys.exit(1)
def get_date_env(key: str, fmt: str = "%Y-%m-%d", default: str = None, required: bool = True) -> dt:
value_str = get_env_or_fail(key, default, required)
try:
return dt.strptime(value_str, fmt)
except ValueError:
logger.error(f"Environment variable {key} must be a date in format {fmt}. Got: {value_str}")
sys.exit(1)
# --- General Settings ---
LANGUAGE: str = get_env_or_fail("LANGUAGE", "de", False)
# --- Browser -----------------------------------------------------------------
HEADLESS: bool = get_bool_env("HEADLESS", "True")
BROWSER_WIDTH: int = get_int_env("BROWSER_WIDTH", "600")
BROWSER_HEIGHT: int = get_int_env("BROWSER_HEIGHT", "800")
BROWSER_LOCALE: str = getenv("BROWSER_LOCALE", "de-DE")
POST_SUBMISSION_SLEEP_MS: int = get_int_env("POST_SUBMISSION_SLEEP_MS", "0")
# --- Browser Settings ---
HEADLESS: bool = get_bool_env("HEADLESS", "True", True)
BROWSER_WIDTH: int = get_int_env("BROWSER_WIDTH", "600", False)
BROWSER_HEIGHT: int = get_int_env("BROWSER_HEIGHT", "800", False)
BROWSER_LOCALE: str = get_env_or_fail("BROWSER_LOCALE", "de-DE", False)
POST_SUBMISSION_SLEEP_MS: int = get_int_env("POST_SUBMISSION_SLEEP_MS", "0", False)
# --- Automation Mode ---
SUBMIT_FORMS: bool = get_bool_env("SUBMIT_FORMS", "False")
# --- HTTP Server ---
HTTP_HOST: str = get_env_or_fail("HTTP_HOST", "0.0.0.0", False)
HTTP_PORT: int = get_int_env("HTTP_PORT", "8000", False)
# --- Personal Information ---
SALUTATION: str = get_env_or_fail("SALUTATION")
LASTNAME: str = get_env_or_fail("LASTNAME")
FIRSTNAME: str = get_env_or_fail("FIRSTNAME")
EMAIL: str = get_env_or_fail("EMAIL")
TELEPHONE: str = get_env_or_fail("TELEPHONE")
STREET: str = get_env_or_fail("STREET")
HOUSE_NUMBER: str = get_env_or_fail("HOUSE_NUMBER")
POSTCODE: str = get_env_or_fail("POSTCODE")
CITY: str = get_env_or_fail("CITY")
# --- WBS Information ---
IS_POSSESSING_WBS: bool = get_bool_env("IS_POSSESSING_WBS", "False")
WBS_TYPE: str = get_env_or_fail("WBS_TYPE", "0", False)
WBS_VALID_TILL: dt = get_date_env("WBS_VALID_TILL", default="1970-01-01", required=False)
WBS_ROOMS: int = get_int_env("WBS_ROOMS", "0", False)
ADULT_COUNT: int = get_int_env("WBS_ADULTS", "0", False)
CHILDREN_COUNT: int = get_int_env("WBS_CHILDREN", "0", False)
PERSON_COUNT: int = ADULT_COUNT + CHILDREN_COUNT
IS_PRIO_WBS: bool = get_bool_env("IS_PRIO_WBS", "False")
# --- Secrets ---
IMMOMIO_EMAIL: str = get_env_or_fail("IMMOMIO_EMAIL", required=False)
IMMOMIO_PASSWORD: str = get_env_or_fail("IMMOMIO_PASSWORD", required=False)
# --- Service -----------------------------------------------------------------
INTERNAL_API_KEY: str = get_env_or_fail("INTERNAL_API_KEY")
def log_settings():
def log_settings() -> None:
logger.debug("--- Settings ---")
logger.debug(f"LANGUAGE: {LANGUAGE}")
logger.debug(f"HEADLESS: {HEADLESS}")
logger.debug(f"BROWSER_WIDTH: {BROWSER_WIDTH}")
logger.debug(f"BROWSER_HEIGHT: {BROWSER_HEIGHT}")
logger.debug(f"BROWSER_LOCALE: {BROWSER_LOCALE}")
logger.debug(f"POST_SUBMISSION_SLEEP_MS: {POST_SUBMISSION_SLEEP_MS}")
logger.debug(f"HEADLESS: {HEADLESS}")
logger.debug(f"SUBMIT_FORMS: {SUBMIT_FORMS}")
logger.debug(f"HTTP_HOST: {HTTP_HOST}")
logger.debug(f"HTTP_PORT: {HTTP_PORT}")
logger.debug(f"SALUTATION: {SALUTATION}")
logger.debug(f"LASTNAME: {LASTNAME}")
logger.debug(f"FIRSTNAME: {FIRSTNAME}")
logger.debug(f"EMAIL: {EMAIL}")
logger.debug(f"TELEPHONE: {TELEPHONE}")
logger.debug(f"STREET: {STREET}")
logger.debug(f"HOUSE_NUMBER: {HOUSE_NUMBER}")
logger.debug(f"POSTCODE: {POSTCODE}")
logger.debug(f"CITY: {CITY}")
logger.debug(f"IS_POSSESSING_WBS: {IS_POSSESSING_WBS}")
logger.debug(f"WBS_TYPE: {WBS_TYPE}")
logger.debug(f"WBS_VALID_TILL: {WBS_VALID_TILL}")
logger.debug(f"WBS_ROOMS: {WBS_ROOMS}")
logger.debug(f"WBS_ADULTS: {ADULT_COUNT}")
logger.debug(f"WBS_CHILDREN: {CHILDREN_COUNT}")
logger.debug(f"PERSON_COUNT: {PERSON_COUNT}")
logger.debug(f"IS_PRIO_WBS: {IS_PRIO_WBS}")
logger.debug(f"IMMOMIO_EMAIL: {IMMOMIO_EMAIL}")
masked_password = "***" if IMMOMIO_PASSWORD else "None"
logger.debug(f"IMMOMIO_PASSWORD: {masked_password}")