feat: Introduce admin dashboard product standard management
- Added new API endpoints for managing the product dashboard standard, including retrieval, update, and deletion functionalities. - Enhanced the DashboardConfigurePage to support admin mode for configuring the product dashboard standard. - Updated the admin navigation to include a link for the product dashboard standard configuration. - Refactored the dashboard layout logic to utilize the new product standard management features. - Bumped app_dashboard version to 1.10.0 to reflect these enhancements and changes.
This commit is contained in:
1 parent
ff95ef63c7
commit
365ce49c6a
12 files changed
+299
-32
No files matched your search
@@ -7,12 +7,21 @@ import os
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
|
||||
from db import get_db, get_cursor, r2d
|
||||
from auth import require_admin, hash_pin
|
||||
from models import AdminProfileUpdate
|
||||
from dashboard_layout_schema import DashboardLayoutPayload, product_default_layout_dict
|
||||
from dashboard_widget_entitlements import widgets_catalog_admin_payload
|
||||
from system_dashboard_product_default import (
|
||||
delete_product_default_override,
|
||||
get_product_default_base_dict,
|
||||
get_stored_product_default_validated,
|
||||
upsert_product_default_base,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/api/admin", tags=["admin"])
|
||||
|
||||
@@ -155,3 +164,52 @@ def admin_test_email(data: dict, session: dict=Depends(require_admin)):
|
||||
return {"ok": True, "message": f"Test-E-Mail an {email} gesendet"}
|
||||
except Exception as e:
|
||||
raise HTTPException(500, f"Fehler beim Senden: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/widgets/catalog-full")
|
||||
def admin_widgets_catalog_full(session: dict = Depends(require_admin)):
|
||||
"""Dashboard-Widget-Katalog ohne Feature-Filter (Konfiguration des Produkt-Standards)."""
|
||||
_ = session
|
||||
return widgets_catalog_admin_payload()
|
||||
|
||||
|
||||
@router.get("/dashboard-product-default")
|
||||
def admin_get_dashboard_product_default(session: dict = Depends(require_admin)):
|
||||
"""Aktueller Produkt-Dashboard-Standard (DB oder Code)."""
|
||||
_ = session
|
||||
with get_db() as conn:
|
||||
layout = get_product_default_base_dict(conn)
|
||||
from_database = get_stored_product_default_validated(conn) is not None
|
||||
code_ref = product_default_layout_dict()
|
||||
return {
|
||||
"from_database": from_database,
|
||||
"layout": layout,
|
||||
"code_reference": code_ref,
|
||||
}
|
||||
|
||||
|
||||
@router.put("/dashboard-product-default")
|
||||
def admin_put_dashboard_product_default(
|
||||
body: dict[str, Any],
|
||||
session: dict = Depends(require_admin),
|
||||
):
|
||||
"""System-Standard persistieren (JSON wie Nutzer-Layout v1)."""
|
||||
_ = session
|
||||
try:
|
||||
payload = DashboardLayoutPayload.model_validate(body)
|
||||
except Exception as e:
|
||||
raise HTTPException(422, str(e)) from e
|
||||
stored = payload.to_stored_dict()
|
||||
with get_db() as conn:
|
||||
upsert_product_default_base(conn, stored)
|
||||
return {"ok": True, "layout": stored, "from_database": True}
|
||||
|
||||
|
||||
@router.delete("/dashboard-product-default")
|
||||
def admin_delete_dashboard_product_default(session: dict = Depends(require_admin)):
|
||||
"""DB-Override entfernen; App fällt auf Code-Standard zurück."""
|
||||
_ = session
|
||||
with get_db() as conn:
|
||||
delete_product_default_override(conn)
|
||||
layout = get_product_default_base_dict(conn)
|
||||
return {"ok": True, "layout": layout, "from_database": False}
|
||||
@@ -13,11 +13,11 @@ from dashboard_layout_schema import (
|
||||
DashboardLayoutPayload,
|
||||
coalesce_effective_layout,
|
||||
lab_default_layout_dict,
|
||||
product_default_layout_dict,
|
||||
)
|
||||
from dashboard_widget_entitlements import apply_entitlements_to_layout_dict, widgets_catalog_payload
|
||||
from db import get_cursor, get_db
|
||||
from routers.profiles import get_pid
|
||||
from system_dashboard_product_default import get_product_default_base_dict
|
||||
|
||||
router = APIRouter(prefix="/api/app", tags=["app-dashboard-lab"])
|
||||
|
||||
@@ -51,8 +51,11 @@ def get_dashboard_layout(
|
||||
raw = row["dashboard_layout"] if row else None
|
||||
custom, effective = coalesce_effective_layout(raw)
|
||||
with get_db() as conn:
|
||||
base_product = get_product_default_base_dict(conn)
|
||||
if not custom:
|
||||
effective = base_product
|
||||
effective = apply_entitlements_to_layout_dict(effective, pid, conn)
|
||||
product_adj = apply_entitlements_to_layout_dict(product_default_layout_dict(), pid, conn)
|
||||
product_adj = apply_entitlements_to_layout_dict(base_product, pid, conn)
|
||||
lab_adj = apply_entitlements_to_layout_dict(lab_default_layout_dict(), pid, conn)
|
||||
return {
|
||||
"custom": custom,
|
||||
@@ -107,5 +110,6 @@ def reset_dashboard_layout(
|
||||
)
|
||||
if cur.rowcount == 0:
|
||||
raise HTTPException(404, "Profil nicht gefunden")
|
||||
cleared = apply_entitlements_to_layout_dict(product_default_layout_dict(), pid, conn)
|
||||
base = get_product_default_base_dict(conn)
|
||||
cleared = apply_entitlements_to_layout_dict(base, pid, conn)
|
||||
return {"ok": True, "layout": cleared}
|
||||
Reference in new issue
Block a user