changes to the Trialver5sion processing to just use the functioning add and modul configuration

This commit is contained in:
2026-09-07 22:27:29 +02:00
parent dab6b8c5ba
commit 6ae75e9b84
2 changed files with 73 additions and 42 deletions
+17 -33
View File
@@ -2180,7 +2180,7 @@ def book_option_package():
return redirect(url_for("booking_payment", packages=packages_raw, flow=booking_flow))
ALL_MODULE_KEYS = ["library", "inventory", "student_cards", "terminplan", "testversion"]
ALL_MODULE_KEYS = ["library", "inventory", "student_cards", "terminplan"]
PACKAGE_MODULE_MAP = {
"buecherei": ["library"],
"inventarsystem": ["inventory"],
@@ -2189,7 +2189,6 @@ PACKAGE_MODULE_MAP = {
"startpaket": ["library", "inventory", "student_cards"],
"advanced": ["library", "inventory", "student_cards", "terminplan"],
"komplettpaket": ["library", "inventory", "student_cards", "terminplan"],
"testversion": ["testversion", "Testversion", "trial", "Testversionen", "Testversionen"],
}
@@ -2229,22 +2228,18 @@ def background_booking_provisioning(
address,
price,
software_name="Invario Inventarsystem",
is_trial=False, # Neu: Flag für Testversion
trial_days=14, # Neu: Laufzeit der Testversion in Tagen
trial_prefix="testversion-" # Neu: Präfix für Testversionen
is_trial=False,
trial_days=14,
):
"""
Hintergrund-Worker, der die Tenant-Bereitstellung über das Host-Watcher-Triggersystem auslöst.
Unterstützt reguläre Buchungen sowie Testversionen (mit 'testversion-' Präfix & Trial-Laufzeit).
Unterstützt reguläre Buchungen sowie Testversionen mit zeitlich begrenzter Modulfreischaltung.
"""
with app_instance.app_context():
req_client, req_col = _get_collection("instance_requests")
try:
# 1. Präfix für Testversionen verarbeiten
effective_subdomain = subdomain
if is_trial:
if not effective_subdomain.startswith(trial_prefix):
effective_subdomain = f"{trial_prefix}{effective_subdomain}"
# 2. Status auf "in_progress" setzen
req_col.update_one(
@@ -2272,7 +2267,8 @@ def background_booking_provisioning(
admin_password = generate_secure_password()
# Generiere den korrekten Modul-String
module_config_str = build_module_config_string(package_list)
# Trial tenants use the regular instance path, with every module enabled.
module_config_str = " ".join(f"{module}=on" for module in ALL_MODULE_KEYS) if is_trial else build_module_config_string(package_list)
# 4. Ablaufdatum berechnen (bei Testversion)
now = datetime.now(timezone.utc)
@@ -2282,25 +2278,16 @@ def background_booking_provisioning(
os.makedirs(TRIGGER_DIR, exist_ok=True)
trigger_file = os.path.join(TRIGGER_DIR, f"{effective_subdomain}.json")
trigger_payload = {
"action": "add",
"request_id": str(prov_id),
"slug": effective_subdomain,
"port": next_port,
"password": admin_password,
"module_config": module_config_str,
}
if is_trial:
trigger_payload = {
"action": "trial",
"request_id": str(prov_id),
"slug": effective_subdomain,
"port": next_port,
"days": trial_days,
"password": admin_password,
"module_config": module_config_str
}
else:
trigger_payload = {
"action": "add",
"request_id": str(prov_id),
"slug": effective_subdomain,
"port": next_port,
"password": admin_password,
"module_config": module_config_str
}
trigger_payload["expires_at"] = expires_at
with open(trigger_file, "w") as f:
json.dump(trigger_payload, f)
@@ -2328,9 +2315,6 @@ def background_booking_provisioning(
instance_doc["trial_days"] = trial_days
instance_doc["expires_at"] = expires_at
if is_trial:
instance_doc["admin_password"] = "admin123"
inst_client, inst_col = _get_collection("instances")
try:
created_inst_id = str(inst_col.insert_one(instance_doc).inserted_id)
@@ -2458,7 +2442,7 @@ def booking_payment():
packages_str = _sanitize_text(request.values.get("packages") or request.values.get("package") or "", 200).lower()
booking_flow = _sanitize_text(request.values.get("flow") or "payment", 24).lower()
is_trial = (booking_flow == "testversion") or request.values.get("testversion", "").strip().lower() in {"1", "on", "true", "yes"}
is_trial = booking_flow in {"trial", "testversion"} or request.values.get("testversion", "").strip().lower() in {"1", "on", "true", "yes"}
trial_days = int(request.values.get("trial_days") or 14)
if booking_flow not in BOOKING_FLOW_MAP and booking_flow != "trial":
@@ -2594,7 +2578,7 @@ def booking_payment():
flash(f"Gesprächstermin für {selected_package} wurde an das Team gesendet.", "success")
return redirect(url_for("user_chat"))
if booking_flow in ["payment", "testversion"]:
if booking_flow in ["payment", "testversion", "trial"]:
# CORRECTED: Syntax error in the f-string is fixed below (uses single quotes inside double quotes)
booking_number = f"{'TRIAL' if is_trial else 'BOOK'}-{datetime.utcnow().strftime('%Y%m%d%H%M%S')}"