mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-05 13:46:40 +00:00
fix: maintenance mode not enqeuing notifications
This commit is contained in:
parent
197b2f5370
commit
bccd1a0d31
@ -4,42 +4,49 @@ onModelAfterUpdate((e) => {
|
||||
const newModel = /** @type {models.Record} */ (e.model)
|
||||
const oldModel = newModel.originalCopy()
|
||||
|
||||
const { mkLog, enqueueNotification } = /** @type {Lib} */ (
|
||||
const { mkLog, enqueueNotification, audit } = /** @type {Lib} */ (
|
||||
require(`${__hooks}/lib.js`)
|
||||
)
|
||||
|
||||
const log = mkLog(`maintenance-mode`)
|
||||
|
||||
// Bail out if we aren't in maintenance mode
|
||||
const isMaintenance = newModel.get('maintenance')
|
||||
// log({ isMaintenance })
|
||||
if (!isMaintenance) return
|
||||
try {
|
||||
// Bail out if we aren't in maintenance mode
|
||||
const isMaintenance = newModel.get('maintenance')
|
||||
// log({ isMaintenance })
|
||||
if (!isMaintenance) return
|
||||
|
||||
// Bail out if the maintenance mode flag has not changed
|
||||
if (isMaintenance === oldModel.get(`maintenance`)) return
|
||||
// Bail out if the maintenance mode flag has not changed
|
||||
if (isMaintenance === oldModel.get(`maintenance`)) return
|
||||
|
||||
log(`switched`)
|
||||
const uid = newModel.get(`uid`)
|
||||
const user = dao.findRecordById('users', uid)
|
||||
log(`switched`)
|
||||
const uid = newModel.get(`uid`)
|
||||
const user = dao.findRecordById('users', uid)
|
||||
|
||||
// Bail out if the user has notifications disabled globally or for the instance
|
||||
const shouldNotify =
|
||||
user.getBool(`notifyMaintenanceMode`) &&
|
||||
newModel.getBool(`notifyMaintenanceMode`)
|
||||
log({ shouldNotify })
|
||||
if (!shouldNotify) return
|
||||
// Bail out if the user has notifications disabled globally or for the instance
|
||||
const shouldNotify =
|
||||
user.getBool(`notifyMaintenanceMode`) &&
|
||||
newModel.getBool(`notifyMaintenanceMode`)
|
||||
log({ shouldNotify })
|
||||
if (!shouldNotify) return
|
||||
|
||||
// Send the email warning about maintenance mode
|
||||
const instanceId = newModel.getId()
|
||||
const subdomain = newModel.getString(`subdomain`)
|
||||
const address = user.getString(`email`)
|
||||
log({ instanceId, subdomain, address })
|
||||
enqueueNotification(`email`, `maintenance_mode`, uid, {
|
||||
log,
|
||||
dao,
|
||||
message_template_vars: {
|
||||
subdomain,
|
||||
instanceId,
|
||||
},
|
||||
})
|
||||
// Send the email warning about maintenance mode
|
||||
const instanceId = newModel.getId()
|
||||
const subdomain = newModel.getString(`subdomain`)
|
||||
const address = user.getString(`email`)
|
||||
log({ instanceId, subdomain, address })
|
||||
enqueueNotification(`email`, `maintenance-mode`, uid, {
|
||||
log,
|
||||
dao,
|
||||
message_template_vars: {
|
||||
subdomain,
|
||||
instanceId,
|
||||
},
|
||||
})
|
||||
} catch (e) {
|
||||
audit('ERROR', `Failed to enqueue template with ${e}`, {
|
||||
log,
|
||||
dao,
|
||||
})
|
||||
}
|
||||
}, 'instances')
|
||||
|
2
src/mothership-app/pb_hooks/types/lib.d.ts
vendored
2
src/mothership-app/pb_hooks/types/lib.d.ts
vendored
@ -24,7 +24,7 @@ interface Lib {
|
||||
enqueueNotification: (
|
||||
channel: 'email' | 'lemonbot',
|
||||
template:
|
||||
| 'maintenance_mode'
|
||||
| 'maintenance-mode'
|
||||
| 'lemon_order_email'
|
||||
| 'lemon_order_discord'
|
||||
| 'welcome',
|
||||
|
Loading…
x
Reference in New Issue
Block a user