P1: Rollenbasiertes Dashboard mit Plugin-Karten
- Plugin-Vertrag erweitert: optionaler Hook dashboard_karten(user) + DashboardKarte-Dataclass (Kern bleibt schlank, Fachlogik im Plugin) - Karten: Neuheiten+System-Status (neuheiten), Planungs-Stats bzw. eigene Einträge (planung), offene Dedup-Konflikte (dedup), nächste Redaktionsschlüsse (erinnerung), ungelesene Benachrichtigungen (benachrichtigung), letzte Audit-Einträge (audit-log, nur Admin), Benutzer-Anzahl (Kern, nur Admin) - 'Geladene Plugins' als aufklappbarer Admin-Technikbereich
This commit is contained in:
@@ -33,12 +33,12 @@ import logging
|
||||
import os
|
||||
|
||||
from fastapi import Depends, Form, Request
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from redaktionskern.auth.deps import get_db, require_user
|
||||
from redaktionskern.auth.models import User
|
||||
from redaktionskern.contracts import BasePlugin, Migration, NavEntry
|
||||
from redaktionskern.contracts import BasePlugin, DashboardKarte, Migration, NavEntry
|
||||
|
||||
from .bgg import BggPruefClient
|
||||
from .ki_pruefung import KiPruefClient, lade_konfiguration
|
||||
@@ -87,6 +87,36 @@ class DedupPlugin(BasePlugin):
|
||||
def navigation(self) -> list[NavEntry]:
|
||||
return [NavEntry(label=self.title, url="/dedup")]
|
||||
|
||||
def dashboard_karten(self, user: User) -> list[DashboardKarte]:
|
||||
"""Dashboard: offene Dedup-Konflikte (nur Redaktion)."""
|
||||
from redaktionskern.auth.models import Role
|
||||
from redaktionskern.db import Base
|
||||
|
||||
if user.role not in (Role.ADMIN.value, Role.REDAKTEUR.value):
|
||||
return []
|
||||
tabelle = Base.metadata.tables.get("planungsliste")
|
||||
if tabelle is None:
|
||||
return []
|
||||
with self.context.session_factory() as db:
|
||||
offene = db.scalar(
|
||||
select(func.count())
|
||||
.select_from(tabelle)
|
||||
.where(
|
||||
tabelle.c.pruefung.is_not(None),
|
||||
tabelle.c.status != "abgeschlossen",
|
||||
)
|
||||
) or 0
|
||||
return [
|
||||
DashboardKarte(
|
||||
titel="Offene Dedup-Konflikte",
|
||||
wert=str(offene),
|
||||
beschreibung="Planungseinträge mit Prüfhinweis",
|
||||
link_url="/planung",
|
||||
link_label="Zur Planung",
|
||||
ton="warnung" if offene else "ok",
|
||||
)
|
||||
]
|
||||
|
||||
def on_load(self, context) -> None:
|
||||
super().on_load(context)
|
||||
self._bgg_aktiv = os.environ.get("SPIELE_DEDUP_BGG_AKTIV", "1").strip() != "0"
|
||||
|
||||
Reference in New Issue
Block a user