mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-06 22:26:45 +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 newModel = /** @type {models.Record} */ (e.model)
|
||||||
const oldModel = newModel.originalCopy()
|
const oldModel = newModel.originalCopy()
|
||||||
|
|
||||||
const { mkLog, enqueueNotification } = /** @type {Lib} */ (
|
const { mkLog, enqueueNotification, audit } = /** @type {Lib} */ (
|
||||||
require(`${__hooks}/lib.js`)
|
require(`${__hooks}/lib.js`)
|
||||||
)
|
)
|
||||||
|
|
||||||
const log = mkLog(`maintenance-mode`)
|
const log = mkLog(`maintenance-mode`)
|
||||||
|
|
||||||
// Bail out if we aren't in maintenance mode
|
try {
|
||||||
const isMaintenance = newModel.get('maintenance')
|
// Bail out if we aren't in maintenance mode
|
||||||
// log({ isMaintenance })
|
const isMaintenance = newModel.get('maintenance')
|
||||||
if (!isMaintenance) return
|
// log({ isMaintenance })
|
||||||
|
if (!isMaintenance) return
|
||||||
|
|
||||||
// Bail out if the maintenance mode flag has not changed
|
// Bail out if the maintenance mode flag has not changed
|
||||||
if (isMaintenance === oldModel.get(`maintenance`)) return
|
if (isMaintenance === oldModel.get(`maintenance`)) return
|
||||||
|
|
||||||
log(`switched`)
|
log(`switched`)
|
||||||
const uid = newModel.get(`uid`)
|
const uid = newModel.get(`uid`)
|
||||||
const user = dao.findRecordById('users', uid)
|
const user = dao.findRecordById('users', uid)
|
||||||
|
|
||||||
// Bail out if the user has notifications disabled globally or for the instance
|
// Bail out if the user has notifications disabled globally or for the instance
|
||||||
const shouldNotify =
|
const shouldNotify =
|
||||||
user.getBool(`notifyMaintenanceMode`) &&
|
user.getBool(`notifyMaintenanceMode`) &&
|
||||||
newModel.getBool(`notifyMaintenanceMode`)
|
newModel.getBool(`notifyMaintenanceMode`)
|
||||||
log({ shouldNotify })
|
log({ shouldNotify })
|
||||||
if (!shouldNotify) return
|
if (!shouldNotify) return
|
||||||
|
|
||||||
// Send the email warning about maintenance mode
|
// Send the email warning about maintenance mode
|
||||||
const instanceId = newModel.getId()
|
const instanceId = newModel.getId()
|
||||||
const subdomain = newModel.getString(`subdomain`)
|
const subdomain = newModel.getString(`subdomain`)
|
||||||
const address = user.getString(`email`)
|
const address = user.getString(`email`)
|
||||||
log({ instanceId, subdomain, address })
|
log({ instanceId, subdomain, address })
|
||||||
enqueueNotification(`email`, `maintenance_mode`, uid, {
|
enqueueNotification(`email`, `maintenance-mode`, uid, {
|
||||||
log,
|
log,
|
||||||
dao,
|
dao,
|
||||||
message_template_vars: {
|
message_template_vars: {
|
||||||
subdomain,
|
subdomain,
|
||||||
instanceId,
|
instanceId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
} catch (e) {
|
||||||
|
audit('ERROR', `Failed to enqueue template with ${e}`, {
|
||||||
|
log,
|
||||||
|
dao,
|
||||||
|
})
|
||||||
|
}
|
||||||
}, 'instances')
|
}, '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: (
|
enqueueNotification: (
|
||||||
channel: 'email' | 'lemonbot',
|
channel: 'email' | 'lemonbot',
|
||||||
template:
|
template:
|
||||||
| 'maintenance_mode'
|
| 'maintenance-mode'
|
||||||
| 'lemon_order_email'
|
| 'lemon_order_email'
|
||||||
| 'lemon_order_discord'
|
| 'lemon_order_discord'
|
||||||
| 'welcome',
|
| 'welcome',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user