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>
125 lines
4.6 KiB
Python
125 lines
4.6 KiB
Python
"""
|
|
SQLAlchemy models for Einwilligungen — Consent-Tracking und Cookie-Banner Konfiguration.
|
|
|
|
Tables:
|
|
- compliance_einwilligungen_catalog: Tenant-Katalog (aktive Datenpunkte)
|
|
- compliance_einwilligungen_company: Firmeninformationen fuer DSI-Generierung
|
|
- compliance_einwilligungen_cookies: Cookie-Banner-Konfiguration
|
|
- compliance_einwilligungen_consents: Endnutzer-Consent-Aufzeichnungen
|
|
- compliance_einwilligungen_consent_history: Aenderungshistorie (Migration 009)
|
|
"""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import (
|
|
Column, String, Text, Boolean, DateTime, JSON, Index, Integer
|
|
)
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
from classroom_engine.database import Base
|
|
|
|
|
|
class EinwilligungenCatalogDB(Base):
|
|
"""Tenant-spezifischer Datenpunktkatalog — welche Datenpunkte sind aktiv?"""
|
|
|
|
__tablename__ = 'compliance_einwilligungen_catalog'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
tenant_id = Column(String(100), nullable=False, unique=True)
|
|
selected_data_point_ids = Column(JSON, default=list)
|
|
custom_data_points = Column(JSON, default=list)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
__table_args__ = (
|
|
Index('idx_einw_catalog_tenant', 'tenant_id'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<EinwilligungenCatalog tenant={self.tenant_id}>"
|
|
|
|
|
|
class EinwilligungenCompanyDB(Base):
|
|
"""Firmeninformationen fuer die DSI-Generierung."""
|
|
|
|
__tablename__ = 'compliance_einwilligungen_company'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
tenant_id = Column(String(100), nullable=False, unique=True)
|
|
data = Column(JSON, nullable=False, default=dict)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
def __repr__(self):
|
|
return f"<EinwilligungenCompany tenant={self.tenant_id}>"
|
|
|
|
|
|
class EinwilligungenCookiesDB(Base):
|
|
"""Cookie-Banner-Konfiguration pro Tenant."""
|
|
|
|
__tablename__ = 'compliance_einwilligungen_cookies'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
tenant_id = Column(String(100), nullable=False, unique=True)
|
|
categories = Column(JSON, default=list)
|
|
config = Column(JSON, default=dict)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
__table_args__ = (
|
|
Index('idx_einw_cookies_tenant', 'tenant_id'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<EinwilligungenCookies tenant={self.tenant_id}>"
|
|
|
|
|
|
class EinwilligungenConsentDB(Base):
|
|
"""Endnutzer-Consent-Aufzeichnung — granulare Einwilligungen pro Datenpunkt."""
|
|
|
|
__tablename__ = 'compliance_einwilligungen_consents'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
tenant_id = Column(String(100), nullable=False)
|
|
user_id = Column(String(200), nullable=False)
|
|
data_point_id = Column(String(100), nullable=False)
|
|
granted = Column(Boolean, nullable=False, default=True)
|
|
granted_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
|
revoked_at = Column(DateTime)
|
|
ip_address = Column(String(45))
|
|
user_agent = Column(Text)
|
|
consent_version = Column(String(20), default='1.0')
|
|
source = Column(String(100))
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
__table_args__ = (
|
|
Index('idx_einw_consents_tenant', 'tenant_id'),
|
|
Index('idx_einw_consents_user', 'tenant_id', 'user_id'),
|
|
Index('idx_einw_consents_dpid', 'data_point_id'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<EinwilligungenConsent user={self.user_id} dp={self.data_point_id} granted={self.granted}>"
|
|
|
|
|
|
class EinwilligungenConsentHistoryDB(Base):
|
|
"""Aenderungshistorie fuer Einwilligungen — jede Aktion wird protokolliert."""
|
|
|
|
__tablename__ = 'compliance_einwilligungen_consent_history'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
consent_id = Column(UUID(as_uuid=True), nullable=False)
|
|
tenant_id = Column(String(100), nullable=False)
|
|
action = Column(String(50), nullable=False) # granted | revoked | version_update | renewed
|
|
consent_version = Column(String(20))
|
|
ip_address = Column(String(45))
|
|
user_agent = Column(Text)
|
|
source = Column(String(100))
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
__table_args__ = (
|
|
Index('idx_einw_history_consent', 'consent_id'),
|
|
Index('idx_einw_history_tenant', 'tenant_id'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<ConsentHistory consent={self.consent_id} action={self.action}>"
|