diff --git a/backend/admin.py b/backend/admin.py index 82ae57d..ca298dc 100644 --- a/backend/admin.py +++ b/backend/admin.py @@ -39,17 +39,6 @@ def _ensure_tables(cur): ) """ ) - cur.execute( - """ - CREATE TABLE IF NOT EXISTS scripts ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(100) NOT NULL, - description VARCHAR(255) DEFAULT '', - content TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ) - """ - ) @admin_bp.route("/api/admin/users", methods=["GET"]) @@ -269,78 +258,6 @@ def delete_website(item_id): return jsonify({"message": "Serverfehler"}), 500 -# ---------- Scripts (Admin CRUD) ---------- - -@admin_bp.route("/api/admin/scripts", methods=["GET"]) -def list_scripts_admin(): - _, err = _require_admin() - if err: - return err - try: - cfg = load_config() - conn = connect(**cfg) - cur = conn.cursor(dictionary=True) - _ensure_tables(cur) - cur.execute("SELECT id, name, description, created_at FROM scripts ORDER BY created_at DESC") - rows = cur.fetchall() - cur.close() - conn.close() - return jsonify(rows) - except Exception as e: - logger.error(f"[Admin list_scripts] {e}") - return jsonify({"message": "Serverfehler"}), 500 - - -@admin_bp.route("/api/admin/scripts", methods=["POST"]) -def create_script(): - _, err = _require_admin() - if err: - return err - data = request.get_json() or {} - name = data.get("name", "").strip() - description = data.get("description", "").strip() - content = data.get("content", "") - if not name or not content: - return jsonify({"message": "Name und Inhalt erforderlich"}), 400 - try: - cfg = load_config() - conn = connect(**cfg) - cur = conn.cursor() - _ensure_tables(cur) - cur.execute( - "INSERT INTO scripts (name, description, content) VALUES (%s, %s, %s)", - (name, description, content), - ) - conn.commit() - new_id = cur.lastrowid - cur.close() - conn.close() - return jsonify({"id": new_id, "name": name, "description": description}), 201 - except Exception as e: - logger.error(f"[Admin create_script] {e}") - return jsonify({"message": "Serverfehler"}), 500 - - -@admin_bp.route("/api/admin/scripts/", methods=["DELETE"]) -def delete_script(item_id): - _, err = _require_admin() - if err: - return err - try: - cfg = load_config() - conn = connect(**cfg) - cur = conn.cursor() - _ensure_tables(cur) - cur.execute("DELETE FROM scripts WHERE id=%s", (item_id,)) - conn.commit() - cur.close() - conn.close() - return jsonify({"message": "Gelöscht"}), 200 - except Exception as e: - logger.error(f"[Admin delete_script] {e}") - return jsonify({"message": "Serverfehler"}), 500 - - # ---------- Public (logged-in) endpoints ---------- @admin_bp.route("/api/websites", methods=["GET"]) @@ -365,19 +282,4 @@ def list_websites_public(): @admin_bp.route("/api/scripts", methods=["GET"]) def list_scripts_public(): - user = verify_token() - if not user: - return jsonify({"message": "Nicht autorisiert"}), 401 - try: - cfg = load_config() - conn = connect(**cfg) - cur = conn.cursor(dictionary=True) - _ensure_tables(cur) - cur.execute("SELECT id, name, description, created_at FROM scripts ORDER BY created_at DESC") - rows = cur.fetchall() - cur.close() - conn.close() - return jsonify(rows) - except Exception as e: - logger.error(f"[Public list_scripts] {e}") - return jsonify({"message": "Serverfehler"}), 500 + return jsonify({"message": "Scripts wurden entfernt"}), 410 diff --git a/frontend/src/components/AdminDashboard.jsx b/frontend/src/components/AdminDashboard.jsx index d9ccceb..329a3d4 100644 --- a/frontend/src/components/AdminDashboard.jsx +++ b/frontend/src/components/AdminDashboard.jsx @@ -4,16 +4,12 @@ import axios from '../services/api'; function AdminDashboard() { const [users, setUsers] = useState([]); const [websites, setWebsites] = useState([]); - const [scripts, setScripts] = useState([]); const [loadingUsers, setLoadingUsers] = useState(true); const [loadingSites, setLoadingSites] = useState(true); - const [loadingScripts, setLoadingScripts] = useState(true); const [creatingUser, setCreatingUser] = useState(false); const [creatingSite, setCreatingSite] = useState(false); - const [creatingScript, setCreatingScript] = useState(false); const [formUser, setFormUser] = useState({ username: '', password: '', role: 'user' }); const [formSite, setFormSite] = useState({ name: '', url: '', description: '' }); - const [formScript, setFormScript] = useState({ name: '', description: '', content: '' }); const [error, setError] = useState(null); const fetchUsers = async () => { @@ -41,22 +37,9 @@ function AdminDashboard() { } }; - const fetchScripts = async () => { - try { - setLoadingScripts(true); - const res = await axios.get('/api/admin/scripts'); - setScripts(res.data); - } catch (e) { - setError('Scripts konnten nicht geladen werden'); - } finally { - setLoadingScripts(false); - } - }; - useEffect(() => { fetchUsers(); fetchWebsites(); - fetchScripts(); }, []); const createUser = async () => { @@ -93,23 +76,6 @@ function AdminDashboard() { } }; - const createScript = async () => { - if (!formScript.name || !formScript.content) { - setError('Name und Inhalt erforderlich'); - return; - } - try { - setCreatingScript(true); - await axios.post('/api/admin/scripts', formScript); - setFormScript({ name: '', description: '', content: '' }); - await fetchScripts(); - } catch (e) { - setError(e.response?.data?.message || 'Script konnte nicht angelegt werden'); - } finally { - setCreatingScript(false); - } - }; - const updateRole = async (id, role) => { try { await axios.put(`/api/admin/users/${id}`, { role }); @@ -150,16 +116,6 @@ function AdminDashboard() { } }; - const deleteScript = async (id) => { - if (!window.confirm('Script löschen?')) return; - try { - await axios.delete(`/api/admin/scripts/${id}`); - await fetchScripts(); - } catch (e) { - setError('Konnte Script nicht löschen'); - } - }; - return (
@@ -294,55 +250,7 @@ function AdminDashboard() { )}
-
-

Python-Skripte

-
- - -