fix: add language detection from app_settings and fix activity_logs schema
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m6s
Test and Lint / frontend-test (push) Successful in 2m23s
Version and Release / version-bump (push) Successful in 33s
Version and Release / trigger-drone (push) Successful in 3s
continuous-integration/drone/push Build is passing

- Enhanced language detection priority in email processor:
  1. Event-specific language
  2. App settings general_default_language (NEW)
  3. Email config default_language
  4. Domain-based detection
- Fixed activity_logs insertion error by using logActivity function
- Fixed 500 error on resend email endpoint
- Emails now respect language selected in settings page
This commit is contained in:
2025-07-16 16:45:43 +02:00
parent db7e5913eb
commit a9c2761986
6 changed files with 340 additions and 13 deletions
+34 -11
View File
@@ -578,31 +578,54 @@ router.post('/:id/resend-email', adminAuth, async (req, res) => {
return res.status(404).json({ error: 'Event not found' });
}
// Format dates properly for the email
// Get the language preference
let language = 'en';
try {
// First check app_settings for general_default_language
const langSetting = await db('app_settings')
.where('setting_key', 'general_default_language')
.first();
if (langSetting && langSetting.setting_value) {
language = langSetting.setting_value;
}
} catch (err) {
console.warn('Could not fetch language setting:', err);
}
// Format dates based on language
const eventDate = new Date(event.event_date);
const expiryDate = new Date(event.expires_at);
const dateLocale = language === 'de' ? 'de-DE' : 'en-US';
// Prepare password text based on language
const passwordText = language === 'de'
? '(Aus Sicherheitsgründen nicht angezeigt)'
: '(Not shown for security reasons)';
// Queue the email
await queueEmail(id, event.host_email, 'gallery_created', {
host_name: event.host_name || event.host_email.split('@')[0],
event_name: event.event_name,
event_date: eventDate.toLocaleDateString('de-DE'), // Using German date format
event_date: eventDate.toLocaleDateString(dateLocale),
gallery_link: event.share_link,
gallery_password: '(Aus Sicherheitsgründen nicht angezeigt)', // Security: don't show password in resent emails
expiry_date: expiryDate.toLocaleDateString('de-DE'),
gallery_password: passwordText,
expiry_date: expiryDate.toLocaleDateString(dateLocale),
welcome_message: event.welcome_message || '',
eventId: id
});
// Log the activity - wrap in try-catch to prevent failure if activity logging fails
// Log the activity using the proper schema
try {
await db('activity_logs').insert({
event_id: id,
await logActivity('email_resent', {
email_type: 'gallery_created',
recipient: event.host_email,
ip_address: req.ip || '0.0.0.0',
user_agent: req.get('user-agent') || 'Unknown',
action_type: 'email_resent',
action_details: JSON.stringify({ email_type: 'gallery_created' }),
timestamp: new Date()
user_agent: req.get('user-agent') || 'Unknown'
}, id, {
type: 'admin',
id: req.admin.id,
name: req.admin.username
});
} catch (logError) {
console.error('Warning: Failed to log activity:', logError);