feat: Package 4 Nachbesserungen — History-Tracking, Pagination, Frontend-Fixes
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 36s
CI / test-python-backend-compliance (push) Successful in 31s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 18s
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 36s
CI / test-python-backend-compliance (push) Successful in 31s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 18s
Backend:
- Migration 009: compliance_einwilligungen_consent_history Tabelle
- EinwilligungenConsentHistoryDB Modell (consent_id, action, version, ip, ua, source)
- _record_history() Helper: automatisch bei POST /consents (granted) + PUT /revoke (revoked)
- GET /consents/{id}/history Endpoint (vor revoke platziert für korrektes Routing)
- GET /consents: history-Array pro Eintrag (inline Sub-Query)
- 5 neue Tests (TestConsentHistoryTracking) — 32/32 bestanden
Frontend:
- consent/route.ts: limit+offset aus Frontend-Request weitergeleitet, total-Feld ergänzt
- Neuer Proxy consent/[id]/history/route.ts für GET /consents/{id}/history
- page.tsx: globalStats state + loadStats() (Backend /consents/stats für globale Zahlen)
- page.tsx: Stats-Kacheln auf globalStats umgestellt (nicht mehr page-relativ)
- page.tsx: history-Mapper: created_at→timestamp, consent_version→version
- page.tsx: loadStats() bei Mount + nach Revoke
Dokumentation:
- Developer Portal: neue API-Docs-Seite /api/einwilligungen (Consent + Legal Docs + Cookie Banner)
- developer-portal/app/api/page.tsx: Consent Management Abschnitt
- MkDocs: History-Endpoint, Pagination-Abschnitt, History-Tracking Abschnitt
- Deploy-Skript: scripts/apply_consent_history_migration.sh
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,7 @@ from ..db.einwilligungen_models import (
|
||||
EinwilligungenCompanyDB,
|
||||
EinwilligungenCookiesDB,
|
||||
EinwilligungenConsentDB,
|
||||
EinwilligungenConsentHistoryDB,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -72,6 +73,20 @@ def _get_tenant(x_tenant_id: Optional[str] = Header(None, alias='X-Tenant-ID'))
|
||||
return x_tenant_id
|
||||
|
||||
|
||||
def _record_history(db: Session, consent: EinwilligungenConsentDB, action: str) -> None:
|
||||
"""Protokolliert eine Aenderung an einer Einwilligung in der History-Tabelle."""
|
||||
entry = EinwilligungenConsentHistoryDB(
|
||||
consent_id=consent.id,
|
||||
tenant_id=consent.tenant_id,
|
||||
action=action,
|
||||
consent_version=consent.consent_version,
|
||||
ip_address=consent.ip_address,
|
||||
user_agent=consent.user_agent,
|
||||
source=consent.source,
|
||||
)
|
||||
db.add(entry)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Catalog
|
||||
# ============================================================================
|
||||
@@ -326,6 +341,21 @@ async def list_consents(
|
||||
"ip_address": c.ip_address,
|
||||
"user_agent": c.user_agent,
|
||||
"created_at": c.created_at,
|
||||
"history": [
|
||||
{
|
||||
"id": str(h.id),
|
||||
"action": h.action,
|
||||
"consent_version": h.consent_version,
|
||||
"ip_address": h.ip_address,
|
||||
"user_agent": h.user_agent,
|
||||
"source": h.source,
|
||||
"created_at": h.created_at,
|
||||
}
|
||||
for h in db.query(EinwilligungenConsentHistoryDB)
|
||||
.filter(EinwilligungenConsentHistoryDB.consent_id == c.id)
|
||||
.order_by(EinwilligungenConsentHistoryDB.created_at.asc())
|
||||
.all()
|
||||
],
|
||||
}
|
||||
for c in consents
|
||||
],
|
||||
@@ -351,6 +381,7 @@ async def create_consent(
|
||||
user_agent=request.user_agent,
|
||||
)
|
||||
db.add(consent)
|
||||
_record_history(db, consent, 'granted')
|
||||
db.commit()
|
||||
db.refresh(consent)
|
||||
|
||||
@@ -364,6 +395,37 @@ async def create_consent(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/consents/{consent_id}/history")
|
||||
async def get_consent_history(
|
||||
consent_id: str,
|
||||
tenant_id: str = Depends(_get_tenant),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Get the change history for a specific consent record."""
|
||||
entries = (
|
||||
db.query(EinwilligungenConsentHistoryDB)
|
||||
.filter(
|
||||
EinwilligungenConsentHistoryDB.consent_id == consent_id,
|
||||
EinwilligungenConsentHistoryDB.tenant_id == tenant_id,
|
||||
)
|
||||
.order_by(EinwilligungenConsentHistoryDB.created_at.asc())
|
||||
.all()
|
||||
)
|
||||
return [
|
||||
{
|
||||
"id": str(e.id),
|
||||
"consent_id": str(e.consent_id),
|
||||
"action": e.action,
|
||||
"consent_version": e.consent_version,
|
||||
"ip_address": e.ip_address,
|
||||
"user_agent": e.user_agent,
|
||||
"source": e.source,
|
||||
"created_at": e.created_at,
|
||||
}
|
||||
for e in entries
|
||||
]
|
||||
|
||||
|
||||
@router.put("/consents/{consent_id}/revoke")
|
||||
async def revoke_consent(
|
||||
consent_id: str,
|
||||
@@ -382,6 +444,7 @@ async def revoke_consent(
|
||||
raise HTTPException(status_code=400, detail="Consent is already revoked")
|
||||
|
||||
consent.revoked_at = datetime.utcnow()
|
||||
_record_history(db, consent, 'revoked')
|
||||
db.commit()
|
||||
db.refresh(consent)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user