factory-defaults: HTML-Templates + Import über UI
Erweitert das bestehende Factory-Defaults-Bundle um vier HTML-Standardtexte (Datenschutzerklärung, Impressum, Vollmacht-Vorlage, Website-Datenschutz) und ergänzt den bisherigen CLI-Only-Import um einen Upload-Pfad in der UI. Backend: - collectFactoryDefaults() zieht jetzt auch die Whitelist-AppSettings - exportFactoryDefaults() legt sie als app-settings/app-settings.json ins ZIP - importFactoryDefaults(buffer) liest die ZIP idempotent ein – upserts pro Kategorie, Whitelist-Filter für AppSettings, Anti-Zip-Slip durch basename beim PDF-Lookup - POST /api/factory-defaults/import (multer memoryStorage, max 50 MB, settings:update) - seed-factory-defaults.ts (CLI) gleichermaßen um seedAppSettings() erweitert Frontend: - Import-Card in FactoryDefaults.tsx: Datei-Upload statt CLI-Anleitung - Erfolgs-Box mit Counts pro Kategorie + Warnings (z.B. fehlende PDFs im ZIP) - Preview zeigt jetzt auch die Anzahl HTML-Templates Live verifiziert: Round-Trip Export → DELETE privacyPolicyHtml → Import → Wert (13.6 KB) wieder vollständig hergestellt, Audit-Log zeigt EXPORT + UPDATE-Eintrag mit Detail-Counts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,19 @@ interface PdfTemplateDef {
|
||||
pdfFilename: string; // Dateiname im pdf-templates/-Ordner
|
||||
}
|
||||
|
||||
interface AppSettingDef {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
// Whitelist – muss synchron zu factoryDefaults.service.ts sein.
|
||||
const FACTORY_DEFAULT_APP_SETTING_KEYS = new Set([
|
||||
'privacyPolicyHtml',
|
||||
'authorizationTemplateHtml',
|
||||
'imprintHtml',
|
||||
'websitePrivacyPolicyHtml',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Liest alle *.json Dateien aus einem Ordner und gibt die zusammengeführten Arrays zurück.
|
||||
*/
|
||||
@@ -299,6 +312,31 @@ async function seedPdfTemplates() {
|
||||
console.log(` ✓ PDF-Vorlagen: ${count}${skipped > 0 ? ` (${skipped} übersprungen)` : ''}`);
|
||||
}
|
||||
|
||||
async function seedAppSettings() {
|
||||
const items = readJsonArrays<AppSettingDef>(path.join(ROOT, 'app-settings'));
|
||||
if (items.length === 0) {
|
||||
console.log(' app-settings – keine Einträge');
|
||||
return;
|
||||
}
|
||||
let count = 0;
|
||||
let skipped = 0;
|
||||
for (const s of items) {
|
||||
if (!s.key || typeof s.value !== 'string') continue;
|
||||
if (!FACTORY_DEFAULT_APP_SETTING_KEYS.has(s.key)) {
|
||||
console.warn(` ⚠ AppSetting-Key '${s.key}' nicht auf Whitelist – übersprungen`);
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
await prisma.appSetting.upsert({
|
||||
where: { key: s.key },
|
||||
update: { value: s.value },
|
||||
create: { key: s.key, value: s.value },
|
||||
});
|
||||
count++;
|
||||
}
|
||||
console.log(` ✓ HTML-Templates: ${count}${skipped > 0 ? ` (${skipped} übersprungen)` : ''}`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('\n📦 Factory-Defaults werden eingespielt...\n');
|
||||
|
||||
@@ -313,6 +351,7 @@ async function main() {
|
||||
await seedContractDurations();
|
||||
await seedContractCategories();
|
||||
await seedPdfTemplates();
|
||||
await seedAppSettings();
|
||||
|
||||
console.log('\n✅ Factory-Defaults erfolgreich eingespielt.\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user