Benachrichtigungen erweitert
Emails korrigiert
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import nodemailer from 'nodemailer'
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import { createContactRequest } from '../utils/contact-requests.js'
|
||||
import { readUsers, migrateUserRoles, isHiddenUser } from '../utils/auth.js'
|
||||
import { sendNewContactRequestPush } from '../utils/push-notifications.js'
|
||||
@@ -24,17 +23,39 @@ async function loadConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
async function collectRecipients(config) {
|
||||
const isProduction = process.env.NODE_ENV === 'production' && process.env.APP_ENV !== 'test'
|
||||
function envFlagEnabled(value) {
|
||||
return ['1', 'true', 'yes', 'on'].includes(String(value || '').trim().toLowerCase())
|
||||
}
|
||||
|
||||
if (!isProduction) {
|
||||
function shouldUseDeveloperRecipients() {
|
||||
if (process.env.DEBUG !== undefined) return envFlagEnabled(process.env.DEBUG)
|
||||
return process.env.NODE_ENV !== 'production' || process.env.APP_ENV === 'test'
|
||||
}
|
||||
|
||||
async function collectRecipients(config) {
|
||||
if (shouldUseDeveloperRecipients()) {
|
||||
return ['tsschulz@tsschulz.de']
|
||||
}
|
||||
|
||||
const recipients = []
|
||||
|
||||
// Vorstand
|
||||
if (config?.vorstand && typeof config.vorstand === 'object') {
|
||||
// Vorstand: prefer active login users with the board role.
|
||||
try {
|
||||
const users = await readUsers()
|
||||
for (const rawUser of users) {
|
||||
if (!rawUser || rawUser.active === false || isHiddenUser(rawUser)) continue
|
||||
const user = migrateUserRoles({ ...rawUser })
|
||||
const roles = Array.isArray(user.roles) ? user.roles : []
|
||||
if (roles.includes('vorstand') && user.email && String(user.email).trim()) {
|
||||
recipients.push(String(user.email).trim())
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden der Vorstand-Empfänger aus Benutzerdaten:', error)
|
||||
}
|
||||
|
||||
// Fallback: legacy config.json Vorstand object.
|
||||
if (recipients.length === 0 && config?.vorstand && typeof config.vorstand === 'object') {
|
||||
for (const member of Object.values(config.vorstand)) {
|
||||
if (member?.email && typeof member.email === 'string' && member.email.trim()) {
|
||||
recipients.push(member.email.trim())
|
||||
@@ -73,10 +94,7 @@ async function collectRecipients(config) {
|
||||
if (config?.website?.verantwortlicher?.email) {
|
||||
return [config.website.verantwortlicher.email]
|
||||
}
|
||||
if (process.env.SMTP_USER) {
|
||||
return [process.env.SMTP_USER]
|
||||
}
|
||||
return ['j.dichmann@gmx.de']
|
||||
throw new Error('Keine E-Mail-Empfänger in config.json konfiguriert.')
|
||||
}
|
||||
|
||||
function createTransporter() {
|
||||
|
||||
Reference in New Issue
Block a user