Kunden & Lizenzen Fix

Dieser Commit ist enthalten in:
2025-06-19 19:14:33 +02:00
Ursprung b822504413
Commit afa2b52494
4 geänderte Dateien mit 73 neuen und 44 gelöschten Zeilen

Datei anzeigen

@@ -227,10 +227,12 @@ def get_license_devices(license_id):
})
return jsonify({
'success': True,
'license_key': license_data['license_key'],
'device_limit': license_data['device_limit'],
'devices': devices,
'device_count': len(devices)
'device_count': len(devices),
'active_count': len([d for d in devices if d['is_active']])
})
except Exception as e:
@@ -331,7 +333,7 @@ def deactivate_device(license_id, device_id):
cur.execute("""
SELECT dr.device_name, dr.hardware_id, l.license_key
FROM device_registrations dr
JOIN licenses l ON dr.license_key = l.license_key
JOIN licenses l ON dr.license_id = l.id
WHERE dr.id = %s AND l.id = %s
""", (device_id, license_id))
@@ -398,7 +400,7 @@ def bulk_delete_licenses():
cur.execute("DELETE FROM sessions WHERE license_key = %s", (license_key,))
# Lösche Geräte-Registrierungen
cur.execute("DELETE FROM device_registrations WHERE license_key = %s", (license_key,))
cur.execute("DELETE FROM device_registrations WHERE license_id = %s", (license_id,))
# Lösche Lizenz
cur.execute("DELETE FROM licenses WHERE id = %s", (license_id,))
@@ -543,6 +545,7 @@ def get_license_resources(license_id):
grouped[res_type].append(resource)
return jsonify({
'success': True,
'license_key': license_data['license_key'],
'resources': resources,
'grouped': grouped,

Datei anzeigen

@@ -318,7 +318,7 @@ def api_customer_licenses(customer_id):
if not customer:
return jsonify({'error': 'Kunde nicht gefunden'}), 404
# Hole alle Lizenzen des Kunden
# Hole alle Lizenzen des Kunden - vereinfachte Version ohne komplexe Subqueries
cur.execute("""
SELECT
l.id,
@@ -330,36 +330,18 @@ def api_customer_licenses(customer_id):
l.valid_until,
l.device_limit,
l.created_at,
(SELECT COUNT(*) FROM sessions s WHERE s.license_id = l.id AND s.is_active = true) as active_sessions,
(SELECT COUNT(DISTINCT hardware_id) FROM device_registrations dr WHERE dr.license_id = l.id) as registered_devices,
CASE
WHEN l.valid_until < CURRENT_DATE THEN 'abgelaufen'
WHEN l.valid_until < CURRENT_DATE + INTERVAL '30 days' THEN 'läuft bald ab'
WHEN l.is_active = false THEN 'inaktiv'
ELSE 'aktiv'
END as status,
-- License Server Status
(SELECT COUNT(*) FROM license_heartbeats lh WHERE lh.license_id = l.id AND lh.timestamp > NOW() - INTERVAL '5 minutes') as recent_heartbeats,
(SELECT MAX(timestamp) FROM license_heartbeats lh WHERE lh.license_id = l.id) as last_heartbeat,
(SELECT COUNT(DISTINCT hardware_id) FROM license_heartbeats lh WHERE lh.license_id = l.id AND lh.timestamp > NOW() - INTERVAL '15 minutes') as active_server_devices,
(SELECT COUNT(*) FROM anomaly_detections ad WHERE ad.license_id = l.id AND ad.resolved = false) as unresolved_anomalies,
l.domain_count,
l.ipv4_count,
l.phone_count,
(SELECT COUNT(*) FROM device_registrations WHERE license_id = l.id AND is_active = TRUE) as active_devices,
-- Actual resource counts
(SELECT COUNT(*) FROM license_resources lr
JOIN resource_pools rp ON lr.resource_id = rp.id
WHERE lr.license_id = l.id AND lr.is_active = true AND rp.resource_type = 'domain') as actual_domain_count,
(SELECT COUNT(*) FROM license_resources lr
JOIN resource_pools rp ON lr.resource_id = rp.id
WHERE lr.license_id = l.id AND lr.is_active = true AND rp.resource_type = 'ipv4') as actual_ipv4_count,
(SELECT COUNT(*) FROM license_resources lr
JOIN resource_pools rp ON lr.resource_id = rp.id
WHERE lr.license_id = l.id AND lr.is_active = true AND rp.resource_type = 'phone') as actual_phone_count
COALESCE(l.domain_count, 0) as domain_count,
COALESCE(l.ipv4_count, 0) as ipv4_count,
COALESCE(l.phone_count, 0) as phone_count
FROM licenses l
WHERE l.customer_id = %s
ORDER BY l.created_at DESC
ORDER BY l.created_at DESC, l.id DESC
""", (customer_id,))
licenses = []
@@ -404,28 +386,28 @@ def api_customer_licenses(customer_id):
'id': row[0],
'license_key': row[1],
'license_type': row[2],
'is_active': row[3], # Korrigiert von 'is_active' zu 'is_active'
'is_active': row[3],
'is_test': row[4],
'valid_from': row[5].strftime('%Y-%m-%d') if row[5] else None,
'valid_until': row[6].strftime('%Y-%m-%d') if row[6] else None,
'device_limit': row[7],
'created_at': row[8].strftime('%Y-%m-%d %H:%M:%S') if row[8] else None,
'active_sessions': row[9],
'registered_devices': row[10],
'status': row[11],
'domain_count': row[16],
'ipv4_count': row[17],
'phone_count': row[18],
'active_devices': row[19],
'actual_domain_count': row[20],
'actual_ipv4_count': row[21],
'actual_phone_count': row[22],
'status': row[9],
'domain_count': row[10],
'ipv4_count': row[11],
'phone_count': row[12],
'active_sessions': 0, # Platzhalter
'registered_devices': 0, # Platzhalter
'active_devices': 0, # Platzhalter
'actual_domain_count': len(resources['domains']),
'actual_ipv4_count': len(resources['ipv4s']),
'actual_phone_count': len(resources['phones']),
'resources': resources,
# License Server Data
'recent_heartbeats': row[12],
'last_heartbeat': row[13].strftime('%Y-%m-%d %H:%M:%S') if row[13] else None,
'active_server_devices': row[14],
'unresolved_anomalies': row[15]
# License Server Data (Platzhalter bis Implementation)
'recent_heartbeats': 0,
'last_heartbeat': None,
'active_server_devices': 0,
'unresolved_anomalies': 0
})
return jsonify({
@@ -439,8 +421,10 @@ def api_customer_licenses(customer_id):
})
except Exception as e:
logging.error(f"Fehler beim Laden der Kundenlizenzen: {str(e)}")
return jsonify({'error': 'Fehler beim Laden der Daten'}), 500
import traceback
error_msg = f"Fehler beim Laden der Kundenlizenzen: {str(e)}\nTraceback: {traceback.format_exc()}"
logging.error(error_msg)
return jsonify({'error': f'Fehler beim Laden der Daten: {str(e)}', 'details': error_msg}), 500
finally:
cur.close()
conn.close()