M8: Datenexport pro Mandant
Neue Seite datenexport.php (Owner/Admin) laedt einen vollstaendigen JSON-Export des eigenen Mandanten herunter: Stammdaten, Einstellungen, Teilnehmer, Mitglieder mit Rolle, alle Ledger-Buchungen, Hinweise, CSV-Importe, Mail-Versandlog und Admin-Protokoll. Passwort- und Token-Hashes werden bewusst nicht exportiert; der Export selbst wird im Audit-Log protokolliert. Link von konto.php aus. Live getestet: eigens angelegter Test-Mandant, Export heruntergeladen, Header und JSON-Struktur geprueft, keine Passwoerter im Export gefunden. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
/**
|
||||
* Assembles a full export of everything stored for one tenant (data
|
||||
* portability / GDPR Art. 20). Excludes password_hash and token hashes;
|
||||
* everything else that is tenant-scoped is included as-is.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
function app_export_tenant_data(PDO $pdo, int $tenantId): array
|
||||
{
|
||||
$stmt = $pdo->prepare('SELECT id, slug, name, status, timezone, locale, currency_code, created_at, updated_at FROM tenants WHERE id = ?');
|
||||
$stmt->execute([$tenantId]);
|
||||
$tenant = $stmt->fetch();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT * FROM tenant_settings WHERE tenant_id = ?');
|
||||
$stmt->execute([$tenantId]);
|
||||
$settings = $stmt->fetch();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT * FROM participants WHERE tenant_id = ? ORDER BY id');
|
||||
$stmt->execute([$tenantId]);
|
||||
$participants = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT u.id, u.email, u.display_name, u.status, u.email_verified_at, u.last_login_at, u.created_at,
|
||||
tm.role, tm.status AS membership_status, tm.invited_at, tm.joined_at
|
||||
FROM tenant_memberships tm
|
||||
JOIN users u ON u.id = tm.user_id
|
||||
WHERE tm.tenant_id = ?
|
||||
ORDER BY u.id'
|
||||
);
|
||||
$stmt->execute([$tenantId]);
|
||||
$members = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT * FROM ledger_entries WHERE tenant_id = ? ORDER BY id');
|
||||
$stmt->execute([$tenantId]);
|
||||
$ledgerEntries = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT id, message, valid_from, valid_until, deleted_at, created_at FROM notices WHERE tenant_id = ? ORDER BY id');
|
||||
$stmt->execute([$tenantId]);
|
||||
$notices = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT id, original_filename, status, created_at, committed_at FROM payment_import_batches WHERE tenant_id = ? ORDER BY id');
|
||||
$stmt->execute([$tenantId]);
|
||||
$importBatches = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT r.id, r.batch_id, r.row_num, r.raw_name, r.amount_cents, r.booked_at, r.status
|
||||
FROM payment_import_rows r
|
||||
JOIN payment_import_batches b ON b.id = r.batch_id
|
||||
WHERE b.tenant_id = ?
|
||||
ORDER BY r.id'
|
||||
);
|
||||
$stmt->execute([$tenantId]);
|
||||
$importRows = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT id, participant_id, template, subject, status, sent_at, error, created_at FROM outbound_emails WHERE tenant_id = ? ORDER BY id');
|
||||
$stmt->execute([$tenantId]);
|
||||
$outboundEmails = $stmt->fetchAll();
|
||||
|
||||
$stmt = $pdo->prepare('SELECT id, actor_user_id, action, subject_type, subject_id, metadata_json, ip, created_at FROM audit_log WHERE tenant_id = ? ORDER BY id');
|
||||
$stmt->execute([$tenantId]);
|
||||
$auditLog = $stmt->fetchAll();
|
||||
|
||||
return [
|
||||
'exported_at' => date('c'),
|
||||
'tenant' => $tenant ?: null,
|
||||
'tenant_settings' => $settings ?: null,
|
||||
'participants' => $participants,
|
||||
'members' => $members,
|
||||
'ledger_entries' => $ledgerEntries,
|
||||
'notices' => $notices,
|
||||
'payment_import_batches' => $importBatches,
|
||||
'payment_import_rows' => $importRows,
|
||||
'outbound_emails' => $outboundEmails,
|
||||
'audit_log' => $auditLog,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/functions.php';
|
||||
require_once __DIR__ . '/app/data-export.php';
|
||||
require_once __DIR__ . '/app/audit.php';
|
||||
|
||||
$pdo = app_db_pdo();
|
||||
$user = saas_require_login();
|
||||
|
||||
if (!saas_can_manage_tenant_settings($user)) {
|
||||
http_response_code(403);
|
||||
exit('Kein Zugriff.');
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
app_require_csrf();
|
||||
|
||||
$tenantId = (int)$user['tenant_id'];
|
||||
$data = app_export_tenant_data($pdo, $tenantId);
|
||||
app_audit_log($pdo, $tenantId, (int)$user['user_id'], 'tenant_data.exported', 'tenant', $tenantId);
|
||||
|
||||
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
$filename = 'kaffeeliste-export-' . $user['tenant_slug'] . '-' . date('Ymd_His') . '.json';
|
||||
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Content-Length: ' . strlen((string)$json));
|
||||
echo $json;
|
||||
exit;
|
||||
}
|
||||
|
||||
include 'header.php';
|
||||
include 'headerline.php';
|
||||
include 'nav.php';
|
||||
?>
|
||||
|
||||
<section id="banner">
|
||||
<div class="content">
|
||||
<h2>Datenexport</h2>
|
||||
<p>Lädt alle für <?php echo saas_html($user['tenant_name']); ?> gespeicherten Daten als
|
||||
JSON-Datei herunter: Mitglieder, Zugänge und Rollen, alle Buchungen, Hinweise,
|
||||
CSV-Importe, Mail-Versandlog und das Admin-Protokoll. Passwörter werden nicht
|
||||
exportiert.</p>
|
||||
|
||||
<form method="post" action="datenexport.php">
|
||||
<?php echo app_csrf_field(); ?>
|
||||
<button type="submit">Export herunterladen</button>
|
||||
</form>
|
||||
|
||||
<ul class="actions">
|
||||
<li><a href="konto.php" class="button alt">Zurück</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
+26
-2
@@ -124,18 +124,42 @@ erwarteten Rollenliste übereinstimmt.
|
||||
Ergebnis: grün mit 55 Assertions (5 Rollen × 11 Seiten). Räumt die
|
||||
Testdaten am Ende selbst auf.
|
||||
|
||||
## Datenexport pro Mandant
|
||||
|
||||
Umgesetzte Dateien:
|
||||
|
||||
```text
|
||||
app/data-export.php
|
||||
datenexport.php
|
||||
konto.php
|
||||
scripts/http-smoke.php
|
||||
```
|
||||
|
||||
- Neue Seite `datenexport.php` (Owner/Admin, echte SaaS-Session nötig)
|
||||
lädt einen vollständigen JSON-Export des eigenen Mandanten herunter:
|
||||
Tenant-Stammdaten, Einstellungen, Teilnehmer, Mitglieder mit Rolle,
|
||||
alle Ledger-Buchungen, Hinweise, CSV-Importe (Batches und Zeilen),
|
||||
Mail-Versandlog und Admin-Protokoll.
|
||||
- Passwort-Hashes und Token-Hashes werden bewusst nicht exportiert.
|
||||
- Der Export selbst wird im Audit-Log protokolliert
|
||||
(`tenant_data.exported`).
|
||||
- Link von `konto.php` aus neben „Mandant-Einstellungen".
|
||||
- Live getestet: eigens angelegter Test-Mandant, Export heruntergeladen,
|
||||
Header (`Content-Type`, `Content-Disposition`) und JSON-Struktur
|
||||
geprüft, verifiziert dass keine Passwörter enthalten sind. Testdaten
|
||||
anschließend entfernt.
|
||||
|
||||
## Prüfstatus
|
||||
|
||||
- Golden Master: grün mit 104 Assertions.
|
||||
- M4 Ledger-Migration: grün mit 73 Assertions.
|
||||
- M3 Settings-Flow: grün mit 13 Assertions.
|
||||
- HTTP-Smoke: grün mit 26 geprüften Seiten.
|
||||
- HTTP-Smoke: grün mit 27 geprüften Seiten.
|
||||
- M8 Mandanten-Isolation: grün mit 10 Assertions.
|
||||
- M8 Rollenmatrix: grün mit 55 Assertions.
|
||||
|
||||
## Noch offen in M8
|
||||
|
||||
- Content-Security-Policy (braucht Template-Bereinigung der Inline-Styles).
|
||||
- Datenexport pro Mandant.
|
||||
- Lösch-/Anonymisierungsprozess für Teilnehmer und Kunden.
|
||||
- Backup-/Restore-Prozess und Monitoring/Fehlerlogging dokumentieren.
|
||||
|
||||
@@ -647,7 +647,11 @@ Schritte:
|
||||
protokolliert Mitgliederverwaltung, Storno, Mandant-Einstellungen,
|
||||
Hinweise, CSV-Import, Jahresbonus und Live-Mailversand; sichtbar für
|
||||
Owner/Admin auf `mandant-einstellungen.php`.
|
||||
- Datenexport pro Tenant.
|
||||
- Datenexport pro Tenant: erledigt.
|
||||
`datenexport.php` liefert Owner/Admin einen vollständigen JSON-Export
|
||||
des eigenen Mandanten (Stammdaten, Teilnehmer, Mitglieder/Rollen,
|
||||
Buchungen, Hinweise, Importe, Mail-Log, Admin-Protokoll) ohne
|
||||
Passwörter, protokolliert im Audit-Log.
|
||||
- Lösch-/Anonymisierungsprozess für Teilnehmer und Kunden.
|
||||
- Rate-Limits und Security Headers: erledigt. Globale Security-Headers
|
||||
über `app/bootstrap.php` (ohne CSP, siehe `docs/m8-haertung.md`),
|
||||
|
||||
@@ -66,6 +66,7 @@ include 'nav.php';
|
||||
<?php if (saas_can_manage_tenant_settings($user)): ?>
|
||||
<ul class="actions">
|
||||
<li><a href="mandant-einstellungen.php" class="button">Mandant-Einstellungen</a></li>
|
||||
<li><a href="datenexport.php" class="button">Datenexport</a></li>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
@@ -112,6 +112,11 @@ $checks = [
|
||||
'path' => 'namenanpassen.php',
|
||||
'contains' => ['Anzeigenamen aktualisieren'],
|
||||
],
|
||||
[
|
||||
'label' => 'Datenexport Login-Schutz',
|
||||
'path' => 'datenexport.php',
|
||||
'contains' => ['Login'],
|
||||
],
|
||||
[
|
||||
'label' => 'Teilnehmerauswertung',
|
||||
'path' => 'teilnehmerauswertung.php?user_id=1',
|
||||
|
||||
Reference in New Issue
Block a user