Test zu Fake geändert, weil Namensproblem
Dieser Commit ist enthalten in:
@@ -24,43 +24,47 @@ def licenses():
|
||||
|
||||
# Get filter parameters
|
||||
search = request.args.get('search', '').strip()
|
||||
filter_type = request.args.get('type', '')
|
||||
filter_status = request.args.get('status', '')
|
||||
filter_types = request.args.getlist('types[]') # Multi-select for types
|
||||
filter_statuses = request.args.getlist('statuses[]') # Multi-select for statuses
|
||||
sort = request.args.get('sort', 'created_at')
|
||||
order = request.args.get('order', 'desc')
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = 50
|
||||
|
||||
# Process type filter to determine show_test
|
||||
# Default: show only real data unless test_data is explicitly selected
|
||||
show_test = filter_type == 'test_data'
|
||||
# Get all licenses (both fake and real data)
|
||||
licenses_list = get_licenses(show_fake=True)
|
||||
|
||||
# Get licenses based on filters
|
||||
licenses_list = get_licenses(show_test=show_test)
|
||||
# Type filtering with OR logic
|
||||
if filter_types:
|
||||
filtered_by_type = []
|
||||
for license in licenses_list:
|
||||
# Check if license matches any selected type
|
||||
if 'full' in filter_types and license.get('license_type') == 'full' and not license.get('is_fake'):
|
||||
filtered_by_type.append(license)
|
||||
elif 'test' in filter_types and license.get('license_type') == 'test' and not license.get('is_fake'):
|
||||
filtered_by_type.append(license)
|
||||
licenses_list = filtered_by_type
|
||||
else:
|
||||
# If no types selected, show only real data by default
|
||||
licenses_list = [l for l in licenses_list if not l.get('is_fake')]
|
||||
|
||||
# Additional filtering based on type and status
|
||||
if filter_type:
|
||||
if filter_type == 'full':
|
||||
licenses_list = [l for l in licenses_list if l.get('license_type') == 'full' and not l.get('is_test')]
|
||||
elif filter_type == 'test':
|
||||
licenses_list = [l for l in licenses_list if l.get('license_type') == 'test' and not l.get('is_test')]
|
||||
elif filter_type == 'test_data':
|
||||
licenses_list = [l for l in licenses_list if l.get('is_test')]
|
||||
elif filter_type == 'live_data':
|
||||
licenses_list = [l for l in licenses_list if not l.get('is_test')]
|
||||
|
||||
# Status filtering
|
||||
if filter_status:
|
||||
# Status filtering with OR logic
|
||||
if filter_statuses:
|
||||
now = datetime.now()
|
||||
if filter_status == 'active':
|
||||
licenses_list = [l for l in licenses_list if l.get('is_active') and l.get('valid_until') and l.get('valid_until') > now]
|
||||
elif filter_status == 'expiring':
|
||||
expiry_threshold = now + timedelta(days=30)
|
||||
licenses_list = [l for l in licenses_list if l.get('valid_until') and now < l.get('valid_until') <= expiry_threshold]
|
||||
elif filter_status == 'expired':
|
||||
licenses_list = [l for l in licenses_list if l.get('valid_until') and l.get('valid_until') <= now]
|
||||
elif filter_status == 'inactive':
|
||||
licenses_list = [l for l in licenses_list if not l.get('is_active')]
|
||||
filtered_by_status = []
|
||||
for license in licenses_list:
|
||||
# Check if license matches any selected status
|
||||
if 'active' in filter_statuses and license.get('is_active') and license.get('valid_until') and license.get('valid_until') > now:
|
||||
filtered_by_status.append(license)
|
||||
elif 'expiring' in filter_statuses:
|
||||
expiry_threshold = now + timedelta(days=30)
|
||||
if license.get('valid_until') and now < license.get('valid_until') <= expiry_threshold:
|
||||
filtered_by_status.append(license)
|
||||
elif 'expired' in filter_statuses and license.get('valid_until') and license.get('valid_until') <= now:
|
||||
filtered_by_status.append(license)
|
||||
elif 'inactive' in filter_statuses and not license.get('is_active'):
|
||||
filtered_by_status.append(license)
|
||||
licenses_list = filtered_by_status
|
||||
|
||||
# Search filtering
|
||||
if search:
|
||||
@@ -79,10 +83,9 @@ def licenses():
|
||||
|
||||
return render_template("licenses.html",
|
||||
licenses=licenses_list,
|
||||
show_test=show_test,
|
||||
search=search,
|
||||
filter_type=filter_type,
|
||||
filter_status=filter_status,
|
||||
filter_types=filter_types,
|
||||
filter_statuses=filter_statuses,
|
||||
sort=sort,
|
||||
order=order,
|
||||
page=page,
|
||||
@@ -114,14 +117,14 @@ def edit_license(license_id):
|
||||
'valid_from': request.form['valid_from'],
|
||||
'valid_until': request.form['valid_until'],
|
||||
'is_active': 'is_active' in request.form,
|
||||
'is_test': 'is_test' in request.form,
|
||||
'is_fake': 'is_fake' in request.form,
|
||||
'device_limit': int(request.form.get('device_limit', 3))
|
||||
}
|
||||
|
||||
cur.execute("""
|
||||
UPDATE licenses
|
||||
SET license_key = %s, license_type = %s, valid_from = %s,
|
||||
valid_until = %s, is_active = %s, is_test = %s, device_limit = %s
|
||||
valid_until = %s, is_active = %s, is_fake = %s, device_limit = %s
|
||||
WHERE id = %s
|
||||
""", (
|
||||
new_values['license_key'],
|
||||
@@ -129,7 +132,7 @@ def edit_license(license_id):
|
||||
new_values['valid_from'],
|
||||
new_values['valid_until'],
|
||||
new_values['is_active'],
|
||||
new_values['is_test'],
|
||||
new_values['is_fake'],
|
||||
new_values['device_limit'],
|
||||
license_id
|
||||
))
|
||||
@@ -144,7 +147,7 @@ def edit_license(license_id):
|
||||
'valid_from': str(current_license.get('valid_from', '')),
|
||||
'valid_until': str(current_license.get('valid_until', '')),
|
||||
'is_active': current_license.get('is_active'),
|
||||
'is_test': current_license.get('is_test'),
|
||||
'is_fake': current_license.get('is_fake'),
|
||||
'device_limit': current_license.get('device_limit', 3)
|
||||
},
|
||||
new_values=new_values)
|
||||
@@ -283,7 +286,7 @@ def create_license():
|
||||
license_key = request.form["license_key"].upper() # Immer Großbuchstaben
|
||||
license_type = request.form["license_type"]
|
||||
valid_from = request.form["valid_from"]
|
||||
is_test = request.form.get("is_test") == "on" # Checkbox value
|
||||
is_fake = request.form.get("is_fake") == "on" # Checkbox value
|
||||
|
||||
# Berechne valid_until basierend auf Laufzeit
|
||||
duration = int(request.form.get("duration", 1))
|
||||
@@ -337,19 +340,19 @@ def create_license():
|
||||
|
||||
# Kunde einfügen (erbt Test-Status von Lizenz)
|
||||
cur.execute("""
|
||||
INSERT INTO customers (name, email, is_test, created_at)
|
||||
INSERT INTO customers (name, email, is_fake, created_at)
|
||||
VALUES (%s, %s, %s, NOW())
|
||||
RETURNING id
|
||||
""", (name, email, is_test))
|
||||
""", (name, email, is_fake))
|
||||
customer_id = cur.fetchone()[0]
|
||||
customer_info = {'name': name, 'email': email, 'is_test': is_test}
|
||||
customer_info = {'name': name, 'email': email, 'is_fake': is_fake}
|
||||
|
||||
# Audit-Log für neuen Kunden
|
||||
log_audit('CREATE', 'customer', customer_id,
|
||||
new_values={'name': name, 'email': email, 'is_test': is_test})
|
||||
new_values={'name': name, 'email': email, 'is_fake': is_fake})
|
||||
else:
|
||||
# Bestehender Kunde - hole Infos für Audit-Log
|
||||
cur.execute("SELECT name, email, is_test FROM customers WHERE id = %s", (customer_id,))
|
||||
cur.execute("SELECT name, email, is_fake FROM customers WHERE id = %s", (customer_id,))
|
||||
customer_data = cur.fetchone()
|
||||
if not customer_data:
|
||||
flash('Kunde nicht gefunden!', 'error')
|
||||
@@ -357,17 +360,17 @@ def create_license():
|
||||
customer_info = {'name': customer_data[0], 'email': customer_data[1]}
|
||||
|
||||
# Wenn Kunde Test-Kunde ist, Lizenz auch als Test markieren
|
||||
if customer_data[2]: # is_test des Kunden
|
||||
is_test = True
|
||||
if customer_data[2]: # is_fake des Kunden
|
||||
is_fake = True
|
||||
|
||||
# Lizenz hinzufügen
|
||||
cur.execute("""
|
||||
INSERT INTO licenses (license_key, customer_id, license_type, valid_from, valid_until, is_active,
|
||||
domain_count, ipv4_count, phone_count, device_limit, is_test)
|
||||
domain_count, ipv4_count, phone_count, device_limit, is_fake)
|
||||
VALUES (%s, %s, %s, %s, %s, TRUE, %s, %s, %s, %s, %s)
|
||||
RETURNING id
|
||||
""", (license_key, customer_id, license_type, valid_from, valid_until,
|
||||
domain_count, ipv4_count, phone_count, device_limit, is_test))
|
||||
domain_count, ipv4_count, phone_count, device_limit, is_fake))
|
||||
license_id = cur.fetchone()[0]
|
||||
|
||||
# Ressourcen zuweisen
|
||||
@@ -375,10 +378,10 @@ def create_license():
|
||||
# Prüfe Verfügbarkeit
|
||||
cur.execute("""
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM resource_pools WHERE resource_type = 'domain' AND status = 'available' AND is_test = %s) as domains,
|
||||
(SELECT COUNT(*) FROM resource_pools WHERE resource_type = 'ipv4' AND status = 'available' AND is_test = %s) as ipv4s,
|
||||
(SELECT COUNT(*) FROM resource_pools WHERE resource_type = 'phone' AND status = 'available' AND is_test = %s) as phones
|
||||
""", (is_test, is_test, is_test))
|
||||
(SELECT COUNT(*) FROM resource_pools WHERE resource_type = 'domain' AND status = 'available' AND is_fake = %s) as domains,
|
||||
(SELECT COUNT(*) FROM resource_pools WHERE resource_type = 'ipv4' AND status = 'available' AND is_fake = %s) as ipv4s,
|
||||
(SELECT COUNT(*) FROM resource_pools WHERE resource_type = 'phone' AND status = 'available' AND is_fake = %s) as phones
|
||||
""", (is_fake, is_fake, is_fake))
|
||||
available = cur.fetchone()
|
||||
|
||||
if available[0] < domain_count:
|
||||
@@ -392,9 +395,9 @@ def create_license():
|
||||
if domain_count > 0:
|
||||
cur.execute("""
|
||||
SELECT id FROM resource_pools
|
||||
WHERE resource_type = 'domain' AND status = 'available' AND is_test = %s
|
||||
WHERE resource_type = 'domain' AND status = 'available' AND is_fake = %s
|
||||
LIMIT %s FOR UPDATE
|
||||
""", (is_test, domain_count))
|
||||
""", (is_fake, domain_count))
|
||||
for (resource_id,) in cur.fetchall():
|
||||
cur.execute("""
|
||||
UPDATE resource_pools
|
||||
@@ -417,9 +420,9 @@ def create_license():
|
||||
if ipv4_count > 0:
|
||||
cur.execute("""
|
||||
SELECT id FROM resource_pools
|
||||
WHERE resource_type = 'ipv4' AND status = 'available' AND is_test = %s
|
||||
WHERE resource_type = 'ipv4' AND status = 'available' AND is_fake = %s
|
||||
LIMIT %s FOR UPDATE
|
||||
""", (is_test, ipv4_count))
|
||||
""", (is_fake, ipv4_count))
|
||||
for (resource_id,) in cur.fetchall():
|
||||
cur.execute("""
|
||||
UPDATE resource_pools
|
||||
@@ -442,9 +445,9 @@ def create_license():
|
||||
if phone_count > 0:
|
||||
cur.execute("""
|
||||
SELECT id FROM resource_pools
|
||||
WHERE resource_type = 'phone' AND status = 'available' AND is_test = %s
|
||||
WHERE resource_type = 'phone' AND status = 'available' AND is_fake = %s
|
||||
LIMIT %s FOR UPDATE
|
||||
""", (is_test, phone_count))
|
||||
""", (is_fake, phone_count))
|
||||
for (resource_id,) in cur.fetchall():
|
||||
cur.execute("""
|
||||
UPDATE resource_pools
|
||||
@@ -480,7 +483,7 @@ def create_license():
|
||||
'valid_from': valid_from,
|
||||
'valid_until': valid_until,
|
||||
'device_limit': device_limit,
|
||||
'is_test': is_test
|
||||
'is_fake': is_fake
|
||||
})
|
||||
|
||||
flash(f'Lizenz {license_key} erfolgreich erstellt!', 'success')
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren