fix: notify all admins for registration confirmation, fix #498

This commit is contained in:
lesion 2025-01-20 12:26:55 +01:00
parent 6026f5b1ca
commit 40f1f91937
No known key found for this signature in database
GPG key ID: 352918250B012177
3 changed files with 19 additions and 15 deletions

View file

@ -315,13 +315,9 @@ const eventController = {
author
})
const admins = await User.findAll({ where: { role: ['admin', 'editor'], is_active: true }, attributes: ['email'], raw: true })
let emails = [res.locals.settings.admin_email]
emails = emails.concat(admins?.map(a => a.email))
log.info('[EVENT] Report event to %s', emails)
// notify admins
mail.send(emails, 'report', { event, message: body.message, author }, undefined, true)
notifier.notifyAdmins('report', { event, message: body.message, author })
log.info('[EVENT] Report event to admins')
// notify author
if (event['user.email'] && body.is_author_visible && !isMine) {

View file

@ -6,6 +6,7 @@ const { User } = require('../models/models')
const settingsController = require('./settings')
const log = require('../../log')
const linkify = require('linkifyjs')
const notifier = require('../../notifier')
const userController = {
@ -95,9 +96,9 @@ const userController = {
log.info('Register user ', req.body.email)
const user = await User.create(req.body)
log.info(`Sending registration email to ${user.email}`)
log.info(`Sending registration email to ${user.email} and registration confirmation to admins`)
mail.send(user.email, 'register', { user, config }, res.locals.locale)
mail.send(settingsController.settings.admin_email, 'admin_register', { user, config })
notifier.notifyAdmins('admin_register', { user, config })
res.sendStatus(200)
} catch (e) {
log.error('Registration error:', e)

View file

@ -1,5 +1,4 @@
const events = require('events')
const mail = require('./api/mail')
const log = require('./log')
const fediverseHelpers = require('./federation/helpers')
@ -22,11 +21,7 @@ const notifier = {
// case 'mail': TODO: locale?
// return mail.send(notification.email, 'event', { event, notification })
case 'admin_email':
const admins = await User.findAll({ where: { role: ['admin', 'editor'], is_active: true }, attributes: ['email'], raw: true })
let emails = [settingsController.settings.admin_email]
emails = emails.concat(admins?.map(a => a.email))
p = mail.send(emails, 'event',
{ event, to_confirm: !event.is_visible, notification }, undefined, true)
p = notifier.notifyAdmins('event', { event, to_confirm: !event.is_visible, notification })
promises.push(p)
break
case 'ap':
@ -62,7 +57,19 @@ const notifier = {
// get notification that matches with selected event
return notifications.filter(notification => match(event, notification.filters))
},
},
/**
* Send admins an email notification
* @param {String} template The template to use to build the email (./server/emails/)
* @param {Object} locals Locals key/value object used in templates
*/
async notifyAdmins (template, locals) {
const admins = await User.findAll({ where: { role: ['admin', 'editor'], is_active: true }, attributes: ['email'], raw: true })
let emails = [settingsController.settings.admin_email]
emails = emails.concat(admins?.map(a => a.email))
return mail.send(emails, template, locals)
},
async notifyEvent (action, eventId) {