From f176560c0253c49bb11438057a5cd972384e3931 Mon Sep 17 00:00:00 2001 From: DGSoft Date: Tue, 14 Oct 2025 21:33:11 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20comprehensive=20admin=20panel?= =?UTF-8?q?=20with=20user=20management?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .env.example | 18 +++ .github/copilot-instructions.md | 54 +++++++ .gitignore | 63 +++++++++ app/__init__.py | 2 +- app/__pycache__/__init__.cpython-313.pyc | Bin 2841 -> 2971 bytes app/templates/admin/create_user.html | 88 ++++++++++++ app/templates/admin/dashboard.html | 173 +++++++++++++++++++++++ app/templates/admin/edit_user.html | 145 +++++++++++++++++++ app/templates/admin/users.html | 154 ++++++++++++++++++++ app/templates/base.html | 8 ++ instance/querybuilder.db | Bin 24576 -> 24576 bytes migrate_admin.py | 84 +++++++++++ 12 files changed, 788 insertions(+), 1 deletion(-) create mode 100644 .env.example create mode 100644 .github/copilot-instructions.md create mode 100644 .gitignore create mode 100644 app/templates/admin/create_user.html create mode 100644 app/templates/admin/dashboard.html create mode 100644 app/templates/admin/edit_user.html create mode 100644 app/templates/admin/users.html create mode 100644 migrate_admin.py diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cc924cb --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# Flask Konfiguration +SECRET_KEY=your-secret-key-here +FLASK_ENV=development +FLASK_DEBUG=True + +# Oracle Datenbank Konfiguration +ORACLE_HOST=your-oracle-host.com +ORACLE_PORT=1521 +ORACLE_SERVICE_NAME=ORCL +ORACLE_USERNAME=your_username +ORACLE_PASSWORD=your_password + +# PostgreSQL Datenbank Konfiguration (optional) +POSTGRES_HOST=your-postgres-host.com +POSTGRES_PORT=5432 +POSTGRES_DATABASE=your_database +POSTGRES_USERNAME=your_username +POSTGRES_PASSWORD=your_password \ No newline at end of file diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..b410b5b --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,54 @@ + +- [x] Verify that the copilot-instructions.md file in the .github directory is created. ✓ Completed + +- [x] Clarify Project Requirements - Python Flask web server with authentication, SQL query builder interface with table list on left, query input and results on right, ability to save and retrieve queries via API as JSON/CSV + + +- [x] Scaffold the Project - ✓ Flask project structure created with authentication, database models, routes, templates, and static files + + +- [x] Customize the Project - ✓ Completed with full query builder functionality, authentication, and API endpoints + + +- [x] Install Required Extensions - ✓ No additional extensions needed + + +- [x] Compile the Project - ✓ Completed - Python environment configured and all dependencies installed successfully + + +- [ ] Create and Run Task + + +- [ ] Launch the Project + + +- [ ] Ensure Documentation is Complete + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5731387 --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Flask +instance/ +.webassets-cache + +# Environment variables +.env + +# IDE +.vscode/ +.idea/ +*.swp +*.swo + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Database +*.db +*.sqlite +*.sqlite3 + +# Logs +*.log + +# Virtual Environment +.venv/ +venv/ +ENV/ +env/ +.env + +# Temporary files +*.tmp +*.temp \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index b2ea99c..01286a3 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -46,7 +46,7 @@ def create_app(): from app.models import User admin = User.query.filter_by(username='admin').first() if not admin: - admin = User(username='admin', email='admin@example.com') + admin = User(username='admin', email='admin@example.com', is_admin=True) admin.set_password('admin123') db.session.add(admin) db.session.commit() diff --git a/app/__pycache__/__init__.cpython-313.pyc b/app/__pycache__/__init__.cpython-313.pyc index 7ec576de39a1ddd09acee78b804d5ef2f3716c87..48c7f9360456073d847ccafce7ddac7b52230f17 100644 GIT binary patch delta 799 zcmZuvO^ee|6ixc_HL3luX{TdGG&ndkGukpAWtwW$5oDm_DrsipqC^szK%17AR-_=K zf5C^KxN+e^H=?+8<4SirD<#-JAR;5PbmO~i!OF~ooZNfQx#!*o@9FHbeDW}nkQsU| zy!f@dBEC(=Sy`khqTk`cy9M?$o3Lanxt*yi0jDuG*+aRw%~~ldZNw%yDWDX2h?KaE ztdmpqq|I5GNzRzd1G z${DP=K~3iO1Y0OfB<>DFUCuF-pSAMVoPh$$n#M5>r^@WO`rlgBqe`=Ov}Ozcy0xiW z9oK#pZc1Krmspkj;C_~LHj*5-?FY@<-2q>6`n_FRlKZ&T>|*bZe{aB*oUT6*N+T8d z%@@x%bcAzsjfnT!j^BzTKWvWJiPg&LnywK;c&VhFZnua#{hk*VM+%%KL!rhhWM14{ z5+g);oS;@X36KIv11JDl3L!iLjXV%HEWA%Xh|kfG(}^RkE8jTrE2r*r>XXVF z=?g>#c`V)FKlS#r4KkF>c4QQj((>dfF~hMMR+UZTJ8pk;_oQ;3is^z>LH z_CpUheRo8MG0JEfUIW2QtK+y$pmBxfl}9qJt3U{Dr{@KCG3<-a0B8WPbQB-iLFc6H i6@%dwj4h?h?T*`Tc~|fzc`sM_0-HK$kUz4@f#xrsk)e(N delta 692 zcmbO&K2wbEGcPX}0}$Mq@-AZ^+eSWaMlLoWml=pZAKI+Uc%CsWlp#nJqy!a&G6wSn z^II}0FyN49GG&D5z^Q^cSO9K<`s8)YQj_N~^G|kW7M^^7nb%s-ThvP|j|HfkB}fm| zZV)fX5K}BzC|KB%F~}HXR(&38D60lkO-d*O&=@5KpaPL#QA;L}T#zXi1H=%Hj^=^M z2bsZG2s+3T!G^IyS&?+hfBV$du$!%;aCcCm*G73$uXLn>|n|zR6lurn#wn!LA6oX=I@+)?8 zE>O7efkaX#YjZ4^e2&9pvM8r3^F)-0Dtp?)=Qh`MKQXChy^_@(~0o)nqMF z2U0~~(?DTXBn2dHF=ytLXfoYmFD*_jiqA{|OBXW%WfT;O3_uDvbMg~Y;z80ypujYn z+{9JnB>|FQOUW-u%_}Qn2XcyJK!hBK0J-fJH`qLoR;a#}3`L+2hM37=lbfGXnv-f* XWH;H4+lp0 +
+
+
+

Neuen Benutzer erstellen

+ + Zurück + +
+ +
+
+
+
+ + +
Der Benutzername muss eindeutig sein
+
+ +
+ + +
Die E-Mail-Adresse muss eindeutig sein
+
+ +
+ + +
Mindestens 6 Zeichen erforderlich
+
+ +
+
+ + +
+ Administratoren können andere Benutzer verwalten und haben Vollzugriff +
+
+
+ +
+ + + Abbrechen + +
+
+
+
+ + +
+
+
Wichtige Hinweise
+
+
+
    +
  • Alle mit * markierten Felder sind Pflichtfelder
  • +
  • Der Benutzername und die E-Mail-Adresse müssen eindeutig sein
  • +
  • Das Passwort sollte sicher gewählt werden
  • +
  • Administrator-Rechte gewähren Vollzugriff auf alle Funktionen
  • +
  • Neue Benutzer können sich sofort mit ihren Anmeldedaten einloggen
  • +
+
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/app/templates/admin/dashboard.html b/app/templates/admin/dashboard.html new file mode 100644 index 0000000..c633caa --- /dev/null +++ b/app/templates/admin/dashboard.html @@ -0,0 +1,173 @@ +{% extends "base.html" %} + +{% block title %}Admin Dashboard{% endblock %} + +{% block content %} +
+
+
+
+

Admin Dashboard

+ + Zurück zum Dashboard + +
+ + +
+
+
+
+
+
+

{{ users|length }}

+ Benutzer gesamt +
+ +
+
+
+
+
+
+
+
+
+

{{ users|selectattr('is_admin')|list|length }}

+ Administratoren +
+ +
+
+
+
+
+
+
+
+
+

{{ users|rejectattr('is_admin')|list|length }}

+ Standard-Benutzer +
+ +
+
+
+
+
+
+
+
+
+

{{ (users|selectattr('created_at')|map(attribute='created_at')|list|length) }}

+ Aktive Benutzer +
+ +
+
+
+
+
+ + + + + +
+
+
+
+
Letzte Benutzer
+
+
+ {% if users %} +
+ + + + + + + + + + + + {% for user in users[:5] %} + + + + + + + + {% endfor %} + +
BenutzernameE-MailRolleErstellt amAktionen
+ {{ user.username }} + {% if user.id == current_user.id %} + Sie + {% endif %} + {{ user.email }} + {% if user.is_admin %} + Administrator + {% else %} + Benutzer + {% endif %} + {{ user.created_at.strftime('%d.%m.%Y %H:%M') }} + + + +
+
+ + {% else %} +
+ +
Keine Benutzer gefunden
+

Erstellen Sie den ersten Benutzer über den Button oben.

+
+ {% endif %} +
+
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html new file mode 100644 index 0000000..644d186 --- /dev/null +++ b/app/templates/admin/edit_user.html @@ -0,0 +1,145 @@ +{% extends "base.html" %} + +{% block title %}Benutzer bearbeiten{% endblock %} + +{% block content %} +
+
+
+
+

Benutzer bearbeiten

+ + Zurück + +
+ +
+
+
+ {{ user.username }} + {% if user.id == current_user.id %} + Sie + {% endif %} + {% if user.is_admin %} + Administrator + {% endif %} +
+
+
+
+
+ + +
Der Benutzername muss eindeutig sein
+
+ +
+ + +
Die E-Mail-Adresse muss eindeutig sein
+
+ +
+ + +
Nur ausfüllen wenn Sie das Passwort ändern möchten (mindestens 6 Zeichen)
+
+ +
+
+ + + {% if user.id == current_user.id %} +
+ Sie können Ihre eigenen Admin-Rechte nicht ändern +
+ {% else %} +
+ Administratoren können andere Benutzer verwalten und haben Vollzugriff +
+ {% endif %} +
+
+ +
+ + + Abbrechen + +
+
+
+
+ + +
+
+
Benutzer-Informationen
+
+
+
+
Benutzer-ID:
+
{{ user.id }}
+
+
+
Erstellt am:
+
{{ user.created_at.strftime('%d.%m.%Y %H:%M:%S') }}
+
+
+
Rolle:
+
+ {% if user.is_admin %} + Administrator + {% else %} + Standard-Benutzer + {% endif %} +
+
+
+
Anzahl Queries:
+
{{ user.saved_queries|length }}
+
+
+
+ + + {% if user.id != current_user.id %} +
+
+
Gefahrenbereich
+
+
+

+ Achtung: Das Löschen eines Benutzers kann nicht rückgängig gemacht werden. + Alle gespeicherten Queries dieses Benutzers gehen verloren. +

+
+ +
+
+
+ {% endif %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/admin/users.html b/app/templates/admin/users.html new file mode 100644 index 0000000..fe34cc7 --- /dev/null +++ b/app/templates/admin/users.html @@ -0,0 +1,154 @@ +{% extends "base.html" %} + +{% block title %}Benutzerverwaltung{% endblock %} + +{% block content %} +
+
+
+ + + {% if users %} +
+
+
+ + + + + + + + + + + + + {% for user in users %} + + + + + + + + + {% endfor %} + +
IDBenutzernameE-MailRolleErstellt amAktionen
{{ user.id }} + {{ user.username }} + {% if user.id == current_user.id %} + Sie + {% endif %} + {{ user.email }} +
+ {% if user.is_admin %} + + Administrator + + {% else %} + + Benutzer + + {% endif %} + + {% if user.id != current_user.id %} + + {% endif %} +
+
{{ user.created_at.strftime('%d.%m.%Y %H:%M') }} +
+ + + + + {% if user.id != current_user.id %} +
+ +
+ {% endif %} +
+
+
+
+
+ {% else %} +
+
+ +

Keine Benutzer gefunden

+

Erstellen Sie den ersten Benutzer.

+ + Ersten Benutzer erstellen + +
+
+ {% endif %} +
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index 8f878e3..58fa90e 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -23,8 +23,16 @@ {% if current_user.is_authenticated %}