Clean admin layout, drop scripts, keep admin out of tools list

This commit is contained in:
Nirodan
2026-01-22 12:31:19 +01:00
parent e3b34bfc47
commit 450e184cf3
4 changed files with 10 additions and 198 deletions
+1 -99
View File
@@ -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/<int:item_id>", 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