diff --git a/infra/n8n/ocsentinel-weekly-organization-reports.json b/infra/n8n/ocsentinel-weekly-organization-reports.json index d93dc2d..159babd 100644 --- a/infra/n8n/ocsentinel-weekly-organization-reports.json +++ b/infra/n8n/ocsentinel-weekly-organization-reports.json @@ -20,19 +20,44 @@ "id": "store-weekly-reports", "name": "Store Weekly Organization Reports", "type": "n8n-nodes-base.postgres", "typeVersion": 2.5, "position": [1080, 300], "credentials": { "postgres": { "id": "WkjY0kIF3kHvREys", "name": "OCSentinel PostgreSQL" } } }, + { + "parameters": { + "assignments": { + "assignments": [ + { "id": "email-enabled", "name": "emailEnabled", "value": true, "type": "boolean" } + ] + }, + "options": {} + }, + "id": "email-delivery-toggle", + "name": "E-Mail-Versand aktiv", + "type": "n8n-nodes-base.set", + "typeVersion": 3.4, + "position": [1330, 300] + }, + { + "parameters": { + "jsCode": "const report = $('Build Organization HTML Reports').item.json;\nif ($json.emailEnabled !== true) return [];\nconst organizationName = String(report.organizationName || 'Unbekannte Organisation');\nconst recipients = ['lg@officecom.it', 'rk@officecom.biz'];\nconst davidOrganizations = [/^Mildenberger Verlag$/i, /^Kirsch\\b/i];\nif (davidOrganizations.some((pattern) => pattern.test(organizationName))) recipients.push('dd@officecom.it');\nreturn [{ json: { ...report, recipients } }];" + }, + "id": "assign-report-recipients", + "name": "Empfaenger je Organisation festlegen", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [1560, 300] + }, { "parameters": { "fromEmail": "donotreply@officecom.biz", - "toEmail": "lg@officecom.it", - "subject": "=OCSentinel Wochenbericht - {{ $('Build Organization HTML Reports').item.json.organizationName }}", - "html": "={{ $('Build Organization HTML Reports').item.json.reportHtml }}", + "toEmail": "={{ $json.recipients.join(', ') }}", + "subject": "=OCSentinel Wochenbericht - {{ $json.organizationName }}", + "html": "={{ $json.reportHtml }}", "options": { "appendAttribution": false } }, "id": "send-weekly-report-email", "name": "Send Weekly Organization Report", "type": "n8n-nodes-base.emailSend", "typeVersion": 2.1, - "position": [1330, 300], + "position": [1800, 300], "credentials": { "smtp": { "id": "vafGYgYzM9SbxQbW", "name": "SMTP account" } } } ], @@ -40,7 +65,9 @@ "Every Monday 07:20": { "main": [[{ "node": "Load Latest Device Reports", "type": "main", "index": 0 }]] }, "Load Latest Device Reports": { "main": [[{ "node": "Build Organization HTML Reports", "type": "main", "index": 0 }]] }, "Build Organization HTML Reports": { "main": [[{ "node": "Store Weekly Organization Reports", "type": "main", "index": 0 }]] }, - "Store Weekly Organization Reports": { "main": [[{ "node": "Send Weekly Organization Report", "type": "main", "index": 0 }]] } + "Store Weekly Organization Reports": { "main": [[{ "node": "E-Mail-Versand aktiv", "type": "main", "index": 0 }]] }, + "E-Mail-Versand aktiv": { "main": [[{ "node": "Empfaenger je Organisation festlegen", "type": "main", "index": 0 }]] }, + "Empfaenger je Organisation festlegen": { "main": [[{ "node": "Send Weekly Organization Report", "type": "main", "index": 0 }]] } }, "settings": { "executionOrder": "v1", "timezone": "Europe/Berlin" }, "active": true,