✨ Add comprehensive admin panel with user management
Features added: - Admin authentication system with is_admin field - Complete admin dashboard with user statistics - User management (create, edit, delete, toggle admin) - Protected admin routes with @admin_required decorator - Security features (prevent self-deletion, last admin protection) - Responsive admin UI with Bootstrap integration - Database migration script for admin field - Admin navigation link for authorized users Technical improvements: - Enhanced 3-column dashboard layout (tables | editor | saved queries) - Removed plus button and made right sidebar more compact - Admin user (admin/admin123) automatically created with admin privileges - Full CRUD operations for user management - Flash messages for user feedback - Form validation and error handling
This commit is contained in:
84
migrate_admin.py
Normal file
84
migrate_admin.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Migrations-Skript um das is_admin Feld zur User-Tabelle hinzuzufügen
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def migrate_database():
|
||||
"""Fügt das is_admin Feld zur User-Tabelle hinzu"""
|
||||
|
||||
# Finde die Datenbankdatei
|
||||
possible_paths = [
|
||||
'querybuilder.db',
|
||||
'instance/querybuilder.db',
|
||||
Path(__file__).parent / 'querybuilder.db',
|
||||
Path(__file__).parent / 'instance' / 'querybuilder.db'
|
||||
]
|
||||
|
||||
db_path = None
|
||||
for path in possible_paths:
|
||||
if os.path.exists(path):
|
||||
db_path = path
|
||||
break
|
||||
|
||||
if not db_path:
|
||||
print("❌ Keine Datenbankdatei gefunden!")
|
||||
return False
|
||||
|
||||
print(f"📁 Verwende Datenbank: {db_path}")
|
||||
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Prüfe ob Spalte bereits existiert
|
||||
cursor.execute("PRAGMA table_info(user)")
|
||||
columns = [row[1] for row in cursor.fetchall()]
|
||||
|
||||
if 'is_admin' in columns:
|
||||
print("✅ Spalte 'is_admin' existiert bereits!")
|
||||
|
||||
# Setze den ersten User (admin) als Administrator
|
||||
cursor.execute("UPDATE user SET is_admin = 1 WHERE username = 'admin'")
|
||||
if cursor.rowcount > 0:
|
||||
print("✅ Admin-User wurde als Administrator markiert!")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
# Füge is_admin Spalte hinzu
|
||||
print("➕ Füge 'is_admin' Spalte hinzu...")
|
||||
cursor.execute("ALTER TABLE user ADD COLUMN is_admin BOOLEAN NOT NULL DEFAULT 0")
|
||||
|
||||
# Setze den ersten User (admin) als Administrator
|
||||
cursor.execute("UPDATE user SET is_admin = 1 WHERE username = 'admin'")
|
||||
admin_updated = cursor.rowcount > 0
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print("✅ Migration erfolgreich abgeschlossen!")
|
||||
if admin_updated:
|
||||
print("✅ Admin-User wurde als Administrator markiert!")
|
||||
else:
|
||||
print("⚠️ Kein Admin-User gefunden - wird beim nächsten Start erstellt")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Fehler bei der Migration: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🔄 Starte Datenbank-Migration...")
|
||||
success = migrate_database()
|
||||
|
||||
if success:
|
||||
print("\n🎉 Migration abgeschlossen!")
|
||||
print("Der Admin-User kann jetzt auf das Admin-Panel zugreifen.")
|
||||
else:
|
||||
print("\n💥 Migration fehlgeschlagen!")
|
||||
print("Bitte überprüfen Sie die Fehlermeldungen oben.")
|
||||
Reference in New Issue
Block a user