Add Settings → Events (Presentations) defaults (interval, page-progress, auto-progress) persisted via /api/system-settings Seed defaults in init_defaults.py (10/true/true) Add Event.page_progress and Event.auto_progress (Alembic applied) CustomEventModal applies defaults on create and saves fields Scheduler publishes only currently active events per group, clears retained topics when none, normalizes times to UTC; include flags in payloads Docs: update README, copilot instructions, and DEV-CHANGELOG If you can split the commit, even better feat(dashboard): add presentation defaults UI feat(api): seed presentation defaults in init_defaults.py feat(model): add Event.page_progress and Event.auto_progress feat(scheduler): publish only active events; clear retained topics; UTC docs: update README and copilot-instructions chore: update DEV-CHANGELOG
70 lines
3.1 KiB
Python
70 lines
3.1 KiB
Python
from sqlalchemy import create_engine, text
|
||
import os
|
||
from dotenv import load_dotenv
|
||
import bcrypt
|
||
|
||
# .env laden
|
||
load_dotenv()
|
||
|
||
DB_URL = f"mysql+pymysql://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}@{os.getenv('DB_HOST')}:3306/{os.getenv('DB_NAME')}"
|
||
engine = create_engine(DB_URL, isolation_level="AUTOCOMMIT")
|
||
|
||
with engine.connect() as conn:
|
||
# Default-Gruppe mit id=1 anlegen, falls nicht vorhanden
|
||
result = conn.execute(
|
||
text("SELECT COUNT(*) FROM client_groups WHERE id=1"))
|
||
if result.scalar() == 0:
|
||
conn.execute(
|
||
text(
|
||
"INSERT INTO client_groups (id, name, is_active) VALUES (1, 'Nicht zugeordnet', 1)")
|
||
)
|
||
print("✅ Default-Gruppe mit id=1 angelegt.")
|
||
|
||
# Superadmin-Benutzer anlegen, falls nicht vorhanden
|
||
admin_user = os.getenv("DEFAULT_SUPERADMIN_USERNAME", "superadmin")
|
||
admin_pw = os.getenv("DEFAULT_SUPERADMIN_PASSWORD")
|
||
|
||
if not admin_pw:
|
||
print("⚠️ DEFAULT_SUPERADMIN_PASSWORD nicht gesetzt. Superadmin wird nicht erstellt.")
|
||
else:
|
||
# Passwort hashen mit bcrypt
|
||
hashed_pw = bcrypt.hashpw(admin_pw.encode(
|
||
'utf-8'), bcrypt.gensalt()).decode('utf-8')
|
||
# Prüfen, ob User existiert
|
||
result = conn.execute(text(
|
||
"SELECT COUNT(*) FROM users WHERE username=:username"), {"username": admin_user})
|
||
if result.scalar() == 0:
|
||
# Rolle: 'superadmin' gemäß UserRole enum
|
||
conn.execute(
|
||
text("INSERT INTO users (username, password_hash, role, is_active) VALUES (:username, :password_hash, 'superadmin', 1)"),
|
||
{"username": admin_user, "password_hash": hashed_pw}
|
||
)
|
||
print(f"✅ Superadmin-Benutzer '{admin_user}' angelegt.")
|
||
else:
|
||
print(f"ℹ️ Superadmin-Benutzer '{admin_user}' existiert bereits.")
|
||
|
||
# Default System Settings anlegen
|
||
default_settings = [
|
||
('supplement_table_url', '', 'URL für Vertretungsplan (Stundenplan-Änderungstabelle)'),
|
||
('supplement_table_enabled', 'false', 'Ob Vertretungsplan aktiviert ist'),
|
||
('presentation_interval', '10', 'Standard Intervall für Präsentationen (Sekunden)'),
|
||
('presentation_page_progress', 'true', 'Seitenfortschritt anzeigen (Page-Progress) für Präsentationen'),
|
||
('presentation_auto_progress', 'true', 'Automatischer Fortschritt (Auto-Progress) für Präsentationen'),
|
||
]
|
||
|
||
for key, value, description in default_settings:
|
||
result = conn.execute(
|
||
text("SELECT COUNT(*) FROM system_settings WHERE `key`=:key"),
|
||
{"key": key}
|
||
)
|
||
if result.scalar() == 0:
|
||
conn.execute(
|
||
text("INSERT INTO system_settings (`key`, value, description) VALUES (:key, :value, :description)"),
|
||
{"key": key, "value": value, "description": description}
|
||
)
|
||
print(f"✅ System-Einstellung '{key}' angelegt.")
|
||
else:
|
||
print(f"ℹ️ System-Einstellung '{key}' existiert bereits.")
|
||
|
||
print("✅ Initialisierung abgeschlossen.")
|