Services: Admin-Lehrer, Backend-Lehrer, Studio v2, Website, Klausur-Service, School-Service, Voice-Service, Geo-Service, BreakPilot Drive, Agent-Core Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
384 lines
13 KiB
TypeScript
384 lines
13 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import AdminLayout from '@/components/admin/AdminLayout'
|
|
import {
|
|
WizardStepper,
|
|
WizardNavigation,
|
|
EducationCard,
|
|
ArchitectureContext,
|
|
TestRunner,
|
|
TestSummary,
|
|
type WizardStep,
|
|
type TestCategoryResult,
|
|
type FullTestResults,
|
|
type EducationContent,
|
|
type ArchitectureContextType,
|
|
} from '@/components/wizard'
|
|
|
|
// ==============================================
|
|
// Types & Constants
|
|
// ==============================================
|
|
|
|
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000'
|
|
|
|
const STEPS: WizardStep[] = [
|
|
{ id: 'welcome', name: 'Willkommen', icon: '👋', status: 'pending' },
|
|
{ id: 'api-health', name: 'API Status', icon: '💚', status: 'pending', category: 'api-health' },
|
|
{ id: 'documents', name: 'Dokumente', icon: '📄', status: 'pending', category: 'documents' },
|
|
{ id: 'versions', name: 'Versionen', icon: '📋', status: 'pending', category: 'versions' },
|
|
{ id: 'consent-records', name: 'Einwilligungen', icon: '✅', status: 'pending', category: 'consent-records' },
|
|
{ id: 'summary', name: 'Zusammenfassung', icon: '📊', status: 'pending' },
|
|
]
|
|
|
|
const EDUCATION_CONTENT: Record<string, EducationContent> = {
|
|
'welcome': {
|
|
title: 'Willkommen zum Consent-Wizard',
|
|
content: [
|
|
'Die Consent-Verwaltung ist das Herzstuck der DSGVO-Konformitaet. Hier lernen Sie:',
|
|
'• Wie rechtliche Dokumente verwaltet werden',
|
|
'• Wie der Versions-Workflow funktioniert',
|
|
'• Wie Einwilligungen erfasst und nachgewiesen werden',
|
|
'• Welche Architektur-Komponenten beteiligt sind',
|
|
'',
|
|
'Jede Einwilligung eines Benutzers wird rechtssicher dokumentiert.',
|
|
'Bei Behoerdenanfragen koennen Sie jeden Nachweis sofort vorlegen.',
|
|
],
|
|
},
|
|
'api-health': {
|
|
title: 'API Verfuegbarkeit - Kritische Infrastruktur',
|
|
content: [
|
|
'Der Consent Service ist kritische Infrastruktur:',
|
|
'• Ohne ihn koennen keine Einwilligungen erfasst werden',
|
|
'• Benutzer koennen die Website nicht DSGVO-konform nutzen',
|
|
'• Rechtliche Risiken bei Ausfall',
|
|
'',
|
|
'Der Health-Check prueft:',
|
|
'• Go Consent Service (Port 8081)',
|
|
'• Python Backend API (Port 8000)',
|
|
'• PostgreSQL Datenbankverbindung',
|
|
],
|
|
},
|
|
'documents': {
|
|
title: 'Rechtliche Dokumente - DSGVO Art. 6 & 7',
|
|
content: [
|
|
'Jede Einwilligung muss auf einem rechtlich geprueften Dokument basieren.',
|
|
'Diese Dokumente durchlaufen einen Freigabe-Workflow:',
|
|
'',
|
|
'draft → review → approved → published → archived',
|
|
'',
|
|
'Nur der Datenschutzbeauftragte (DSB) kann Dokumente freigeben.',
|
|
'Dokumenttypen: terms, privacy, cookies, community_guidelines, imprint',
|
|
'',
|
|
'• Bussgelder bis 20 Mio. EUR bei Verstoessen',
|
|
'• Rechtswirksamkeit von Einwilligungen haengt davon ab',
|
|
],
|
|
},
|
|
'versions': {
|
|
title: 'Dokumentversionen - Lueckenlose Nachverfolgbarkeit',
|
|
content: [
|
|
'Jede Aenderung an einem rechtlichen Dokument erzeugt eine neue Version.',
|
|
'',
|
|
'Die DSGVO verlangt lueckenlose Nachverfolgbarkeit:',
|
|
'• Wann wurde welche Version erstellt?',
|
|
'• Wer hat die Version freigegeben?',
|
|
'• Welcher Text war zum Zeitpunkt der Einwilligung gueltig?',
|
|
'',
|
|
'Versionen koennen nicht geloescht werden (Audit-Trail).',
|
|
'Archivierte Versionen bleiben fuer Nachweiszwecke erhalten.',
|
|
],
|
|
},
|
|
'consent-records': {
|
|
title: 'Einwilligungsnachweise - Der rechtliche Beweis',
|
|
content: [
|
|
'Der Consent Record ist der rechtliche Nachweis, dass ein Benutzer',
|
|
'einer bestimmten Datenverarbeitung zugestimmt hat.',
|
|
'',
|
|
'Jeder Record enthaelt:',
|
|
'• Zeitstempel der Einwilligung',
|
|
'• Exakte Version des Dokuments',
|
|
'• IP-Adresse (anonymisiert)',
|
|
'• Art der Einwilligung (opt-in, opt-out)',
|
|
'',
|
|
'Bei Behoerdenanfragen oder Rechtsstreitigkeiten ist dieser',
|
|
'Nachweis entscheidend fuer die Rechtmaessigkeit der Verarbeitung.',
|
|
],
|
|
},
|
|
'summary': {
|
|
title: 'Zusammenfassung der Tests',
|
|
content: [
|
|
'Hier sehen Sie eine Uebersicht aller durchgefuehrten Tests:',
|
|
'• Anzahl bestandener Tests',
|
|
'• Fehlgeschlagene Tests mit Details',
|
|
'• Empfehlungen zur Behebung',
|
|
],
|
|
},
|
|
}
|
|
|
|
const ARCHITECTURE_CONTEXTS: Record<string, ArchitectureContextType> = {
|
|
'api-health': {
|
|
layer: 'service',
|
|
services: ['consent-service', 'backend'],
|
|
dependencies: ['PostgreSQL'],
|
|
dataFlow: ['Health Check', 'Go Consent Service', 'PostgreSQL'],
|
|
},
|
|
'documents': {
|
|
layer: 'service',
|
|
services: ['consent-service', 'postgres'],
|
|
dependencies: ['JWT Auth', 'RBAC (data_protection_officer)'],
|
|
dataFlow: ['Browser', 'Next.js', 'FastAPI', 'Go Consent Service', 'PostgreSQL'],
|
|
},
|
|
'versions': {
|
|
layer: 'service',
|
|
services: ['consent-service', 'postgres'],
|
|
dependencies: ['JWT Auth', 'Version Control'],
|
|
dataFlow: ['Browser', 'Next.js', 'FastAPI', 'Go Consent Service', 'document_versions'],
|
|
},
|
|
'consent-records': {
|
|
layer: 'database',
|
|
services: ['consent-service', 'postgres'],
|
|
dependencies: ['JWT Auth', 'PII Redaction', 'Audit Log'],
|
|
dataFlow: ['User Action', 'FastAPI', 'Go Consent Service', 'consent_records'],
|
|
},
|
|
}
|
|
|
|
// ==============================================
|
|
// Main Component
|
|
// ==============================================
|
|
|
|
export default function ConsentWizardPage() {
|
|
const [currentStep, setCurrentStep] = useState(0)
|
|
const [steps, setSteps] = useState<WizardStep[]>(STEPS)
|
|
const [categoryResults, setCategoryResults] = useState<Record<string, TestCategoryResult>>({})
|
|
const [fullResults, setFullResults] = useState<FullTestResults | null>(null)
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
const [error, setError] = useState<string | null>(null)
|
|
|
|
const currentStepData = steps[currentStep]
|
|
const isTestStep = currentStepData?.category !== undefined
|
|
const isWelcome = currentStepData?.id === 'welcome'
|
|
const isSummary = currentStepData?.id === 'summary'
|
|
|
|
const runCategoryTest = async (category: string) => {
|
|
setIsLoading(true)
|
|
setError(null)
|
|
|
|
try {
|
|
const response = await fetch(`${BACKEND_URL}/api/admin/consent-tests/${category}`, {
|
|
method: 'POST',
|
|
})
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
|
}
|
|
|
|
const result: TestCategoryResult = await response.json()
|
|
setCategoryResults((prev) => ({ ...prev, [category]: result }))
|
|
|
|
// Update step status
|
|
setSteps((prev) =>
|
|
prev.map((step) =>
|
|
step.category === category
|
|
? { ...step, status: result.failed === 0 ? 'completed' : 'failed' }
|
|
: step
|
|
)
|
|
)
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : 'Unbekannter Fehler')
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
const runAllTests = async () => {
|
|
setIsLoading(true)
|
|
setError(null)
|
|
|
|
try {
|
|
const response = await fetch(`${BACKEND_URL}/api/admin/consent-tests/run-all`, {
|
|
method: 'POST',
|
|
})
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
|
}
|
|
|
|
const results: FullTestResults = await response.json()
|
|
setFullResults(results)
|
|
|
|
// Update all step statuses
|
|
setSteps((prev) =>
|
|
prev.map((step) => {
|
|
if (step.category) {
|
|
const catResult = results.categories.find((c) => c.category === step.category)
|
|
if (catResult) {
|
|
return { ...step, status: catResult.failed === 0 ? 'completed' : 'failed' }
|
|
}
|
|
}
|
|
return step
|
|
})
|
|
)
|
|
|
|
// Store category results
|
|
const newCategoryResults: Record<string, TestCategoryResult> = {}
|
|
results.categories.forEach((cat) => {
|
|
newCategoryResults[cat.category] = cat
|
|
})
|
|
setCategoryResults(newCategoryResults)
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : 'Unbekannter Fehler')
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
const goToNext = () => {
|
|
if (currentStep < steps.length - 1) {
|
|
setSteps((prev) =>
|
|
prev.map((step, idx) =>
|
|
idx === currentStep && step.status === 'pending'
|
|
? { ...step, status: 'completed' }
|
|
: step
|
|
)
|
|
)
|
|
setCurrentStep((prev) => prev + 1)
|
|
}
|
|
}
|
|
|
|
const goToPrev = () => {
|
|
if (currentStep > 0) {
|
|
setCurrentStep((prev) => prev - 1)
|
|
}
|
|
}
|
|
|
|
const handleStepClick = (index: number) => {
|
|
if (index <= currentStep || steps[index - 1]?.status !== 'pending') {
|
|
setCurrentStep(index)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<AdminLayout
|
|
title="Consent Wizard"
|
|
description="Interaktives Lernen und Testen der Consent-Verwaltung"
|
|
>
|
|
{/* Header with back link */}
|
|
<div className="bg-white rounded-lg shadow p-4 mb-6 flex items-center justify-between">
|
|
<div className="flex items-center">
|
|
<span className="text-3xl mr-3">📋</span>
|
|
<div>
|
|
<h2 className="text-lg font-bold text-gray-800">Consent Management Test Wizard</h2>
|
|
<p className="text-sm text-gray-600">DSGVO-konforme Einwilligungsverwaltung</p>
|
|
</div>
|
|
</div>
|
|
<a href="/admin/consent" className="text-blue-600 hover:text-blue-800 text-sm">
|
|
← Zurueck zur Consent-Verwaltung
|
|
</a>
|
|
</div>
|
|
|
|
{/* Stepper */}
|
|
<div className="bg-white rounded-lg shadow p-6 mb-6">
|
|
<WizardStepper steps={steps} currentStep={currentStep} onStepClick={handleStepClick} />
|
|
</div>
|
|
|
|
{/* Content */}
|
|
<div className="bg-white rounded-lg shadow p-6">
|
|
{/* Step Header */}
|
|
<div className="flex items-center mb-6">
|
|
<span className="text-3xl mr-3">{currentStepData?.icon}</span>
|
|
<div>
|
|
<h2 className="text-xl font-bold text-gray-800">
|
|
Schritt {currentStep + 1}: {currentStepData?.name}
|
|
</h2>
|
|
<p className="text-gray-500 text-sm">
|
|
{currentStep + 1} von {steps.length}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Education Card */}
|
|
<EducationCard content={EDUCATION_CONTENT[currentStepData?.id || '']} />
|
|
|
|
{/* Architecture Context for test steps */}
|
|
{isTestStep && currentStepData?.category && ARCHITECTURE_CONTEXTS[currentStepData.category] && (
|
|
<ArchitectureContext
|
|
context={ARCHITECTURE_CONTEXTS[currentStepData.category]}
|
|
currentStep={currentStepData.name}
|
|
/>
|
|
)}
|
|
|
|
{/* Error Display */}
|
|
{error && (
|
|
<div className="bg-red-50 border border-red-200 text-red-700 rounded-lg p-4 mb-6">
|
|
<strong>Fehler:</strong> {error}
|
|
</div>
|
|
)}
|
|
|
|
{/* Welcome Step */}
|
|
{isWelcome && (
|
|
<div className="text-center py-8">
|
|
<button
|
|
onClick={goToNext}
|
|
className="bg-blue-600 text-white px-8 py-3 rounded-lg font-medium hover:bg-blue-700 transition-colors"
|
|
>
|
|
Wizard starten
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{/* Test Steps */}
|
|
{isTestStep && currentStepData?.category && (
|
|
<TestRunner
|
|
category={currentStepData.category}
|
|
categoryResult={categoryResults[currentStepData.category]}
|
|
isLoading={isLoading}
|
|
onRunTests={() => runCategoryTest(currentStepData.category!)}
|
|
/>
|
|
)}
|
|
|
|
{/* Summary Step */}
|
|
{isSummary && (
|
|
<div>
|
|
{!fullResults ? (
|
|
<div className="text-center py-8">
|
|
<p className="text-gray-600 mb-4">
|
|
Fuehren Sie alle Tests aus um eine Zusammenfassung zu sehen.
|
|
</p>
|
|
<button
|
|
onClick={runAllTests}
|
|
disabled={isLoading}
|
|
className={`px-6 py-3 rounded-lg font-medium transition-colors ${
|
|
isLoading
|
|
? 'bg-gray-400 cursor-not-allowed'
|
|
: 'bg-blue-600 text-white hover:bg-blue-700'
|
|
}`}
|
|
>
|
|
{isLoading ? 'Alle Tests laufen...' : 'Alle Tests ausfuehren'}
|
|
</button>
|
|
</div>
|
|
) : (
|
|
<TestSummary results={fullResults} />
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Navigation */}
|
|
<WizardNavigation
|
|
currentStep={currentStep}
|
|
totalSteps={steps.length}
|
|
onPrev={goToPrev}
|
|
onNext={goToNext}
|
|
showNext={!isSummary}
|
|
isLoading={isLoading}
|
|
/>
|
|
</div>
|
|
|
|
{/* Footer Info */}
|
|
<div className="text-center text-gray-500 text-sm mt-6">
|
|
Diese Tests pruefen die DSGVO-konforme Consent-Verwaltung.
|
|
Bei Fragen wenden Sie sich an den Datenschutzbeauftragten.
|
|
</div>
|
|
</AdminLayout>
|
|
)
|
|
}
|