mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
fix: notify all admins for registration confirmation, fix #498
This commit is contained in:
parent
6026f5b1ca
commit
40f1f91937
3 changed files with 19 additions and 15 deletions
|
@ -315,13 +315,9 @@ const eventController = {
|
||||||
author
|
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
|
// 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
|
// notify author
|
||||||
if (event['user.email'] && body.is_author_visible && !isMine) {
|
if (event['user.email'] && body.is_author_visible && !isMine) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ const { User } = require('../models/models')
|
||||||
const settingsController = require('./settings')
|
const settingsController = require('./settings')
|
||||||
const log = require('../../log')
|
const log = require('../../log')
|
||||||
const linkify = require('linkifyjs')
|
const linkify = require('linkifyjs')
|
||||||
|
const notifier = require('../../notifier')
|
||||||
|
|
||||||
const userController = {
|
const userController = {
|
||||||
|
|
||||||
|
@ -95,9 +96,9 @@ const userController = {
|
||||||
|
|
||||||
log.info('Register user ', req.body.email)
|
log.info('Register user ', req.body.email)
|
||||||
const user = await User.create(req.body)
|
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(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)
|
res.sendStatus(200)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error('Registration error:', e)
|
log.error('Registration error:', e)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const events = require('events')
|
const events = require('events')
|
||||||
|
|
||||||
const mail = require('./api/mail')
|
const mail = require('./api/mail')
|
||||||
const log = require('./log')
|
const log = require('./log')
|
||||||
const fediverseHelpers = require('./federation/helpers')
|
const fediverseHelpers = require('./federation/helpers')
|
||||||
|
@ -22,11 +21,7 @@ const notifier = {
|
||||||
// case 'mail': TODO: locale?
|
// case 'mail': TODO: locale?
|
||||||
// return mail.send(notification.email, 'event', { event, notification })
|
// return mail.send(notification.email, 'event', { event, notification })
|
||||||
case 'admin_email':
|
case 'admin_email':
|
||||||
const admins = await User.findAll({ where: { role: ['admin', 'editor'], is_active: true }, attributes: ['email'], raw: true })
|
p = notifier.notifyAdmins('event', { event, to_confirm: !event.is_visible, notification })
|
||||||
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)
|
|
||||||
promises.push(p)
|
promises.push(p)
|
||||||
break
|
break
|
||||||
case 'ap':
|
case 'ap':
|
||||||
|
@ -64,6 +59,18 @@ const notifier = {
|
||||||
return notifications.filter(notification => match(event, notification.filters))
|
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) {
|
async notifyEvent (action, eventId) {
|
||||||
|
|
||||||
const event = await Event.findByPk(eventId, { include: [ { model: Tag, attributes: ['tag'], through: { attributes: [] }}, Place],
|
const event = await Event.findByPk(eventId, { include: [ { model: Tag, attributes: ['tag'], through: { attributes: [] }}, Place],
|
||||||
|
|
Loading…
Reference in a new issue