feat: create cashbox removal notifications

This commit is contained in:
Sérgio Salgado 2021-05-20 14:40:38 +01:00 committed by Josh Harvey
parent 73bd11b38b
commit 598135ccaf
6 changed files with 92 additions and 4 deletions

View file

@ -6,6 +6,7 @@ const LOW_CRYPTO_BALANCE = 'LOW_CRYPTO_BALANCE'
const HIGH_CRYPTO_BALANCE = 'HIGH_CRYPTO_BALANCE' const HIGH_CRYPTO_BALANCE = 'HIGH_CRYPTO_BALANCE'
const CASH_BOX_FULL = 'CASH_BOX_FULL' const CASH_BOX_FULL = 'CASH_BOX_FULL'
const LOW_CASH_OUT = 'LOW_CASH_OUT' const LOW_CASH_OUT = 'LOW_CASH_OUT'
const SECURITY = 'SECURITY'
const CODES_DISPLAY = { const CODES_DISPLAY = {
PING: 'Machine Down', PING: 'Machine Down',
@ -13,7 +14,8 @@ const CODES_DISPLAY = {
LOW_CRYPTO_BALANCE: 'Low Crypto Balance', LOW_CRYPTO_BALANCE: 'Low Crypto Balance',
HIGH_CRYPTO_BALANCE: 'High Crypto Balance', HIGH_CRYPTO_BALANCE: 'High Crypto Balance',
CASH_BOX_FULL: 'Cash box full', CASH_BOX_FULL: 'Cash box full',
LOW_CASH_OUT: 'Low Cash-out' LOW_CASH_OUT: 'Low Cash-out',
CASHBOX_REMOVED: 'Cashbox removed'
} }
const NETWORK_DOWN_TIME = 1 * T.minute const NETWORK_DOWN_TIME = 1 * T.minute
@ -26,7 +28,8 @@ const NOTIFICATION_TYPES = {
FIAT_BALANCE: 'fiatBalance', FIAT_BALANCE: 'fiatBalance',
CRYPTO_BALANCE: 'cryptoBalance', CRYPTO_BALANCE: 'cryptoBalance',
COMPLIANCE: 'compliance', COMPLIANCE: 'compliance',
ERROR: 'error' ERROR: 'error',
SECURITY: 'security'
} }
module.exports = { module.exports = {
@ -36,6 +39,7 @@ module.exports = {
HIGH_CRYPTO_BALANCE, HIGH_CRYPTO_BALANCE,
CASH_BOX_FULL, CASH_BOX_FULL,
LOW_CASH_OUT, LOW_CASH_OUT,
SECURITY,
CODES_DISPLAY, CODES_DISPLAY,
NETWORK_DOWN_TIME, NETWORK_DOWN_TIME,
STALE_STATE, STALE_STATE,

View file

@ -9,7 +9,8 @@ const {
LOW_CRYPTO_BALANCE, LOW_CRYPTO_BALANCE,
HIGH_CRYPTO_BALANCE, HIGH_CRYPTO_BALANCE,
CASH_BOX_FULL, CASH_BOX_FULL,
LOW_CASH_OUT LOW_CASH_OUT,
SECURITY
} = require('./codes') } = require('./codes')
function alertSubject (alertRec, config) { function alertSubject (alertRec, config) {
@ -79,6 +80,8 @@ function emailAlert (alert) {
return `Cash box full on ${alert.machineName} [${alert.notes} banknotes]` return `Cash box full on ${alert.machineName} [${alert.notes} banknotes]`
case LOW_CASH_OUT: case LOW_CASH_OUT:
return `Cassette for ${alert.denomination} ${alert.fiatCode} low [${alert.notes} banknotes]` return `Cassette for ${alert.denomination} ${alert.fiatCode} low [${alert.notes} banknotes]`
case SECURITY:
return `Cashbox removed on ${alert.machineName}`
} }
} }

View file

@ -246,6 +246,41 @@ function sendTransactionMessage (rec, isHighValueTx) {
}) })
} }
function cashboxNotify (deviceId) {
return Promise.all([
settingsLoader.loadLatest(),
queries.getMachineName(deviceId)
])
.then(([settings, machineName]) => {
const notifications = configManager.getGlobalNotifications(settings.config)
const rec = {
sms: {
body: `Cashbox removed - ${machineName}`
},
email: {
subject: `Cashbox removal`,
body: `Cashbox removed in machine ${machineName}`
}
}
const promises = []
const emailActive =
notifications.email.active &&
notifications.email.security
const smsActive =
notifications.sms.active &&
notifications.sms.security
if (emailActive) promises.push(emailFuncs.sendMessage(settings, rec))
if (smsActive) promises.push(smsFuncs.sendMessage(settings, rec))
notifyIfActive('security', 'cashboxNotify', deviceId)
return Promise.all(promises)
})
}
// for notification center, check if type of notification is active before calling the respective notify function // for notification center, check if type of notification is active before calling the respective notify function
const notifyIfActive = (type, fnName, ...args) => { const notifyIfActive = (type, fnName, ...args) => {
return settingsLoader.loadLatest().then(settings => { return settingsLoader.loadLatest().then(settings => {
@ -263,5 +298,6 @@ module.exports = {
checkPings, checkPings,
checkStuckScreen, checkStuckScreen,
sendRedemptionMessage, sendRedemptionMessage,
cashboxNotify,
notifyIfActive notifyIfActive
} }

View file

@ -6,6 +6,7 @@ const codes = require('./codes')
const customers = require('../customers') const customers = require('../customers')
const { NOTIFICATION_TYPES: { const { NOTIFICATION_TYPES: {
SECURITY,
COMPLIANCE, COMPLIANCE,
CRYPTO_BALANCE, CRYPTO_BALANCE,
FIAT_BALANCE, FIAT_BALANCE,
@ -177,11 +178,18 @@ const blacklistNotify = (tx, isAddressReuse) => {
return queries.addNotification(COMPLIANCE, message, detailB) return queries.addNotification(COMPLIANCE, message, detailB)
} }
const cashboxNotify = deviceId => {
const detailB = utils.buildDetail({ deviceId: deviceId })
const message = `Cashbox removed`
return queries.addNotification(SECURITY, message, detailB)
}
module.exports = { module.exports = {
sanctionsNotify, sanctionsNotify,
customerComplianceNotify, customerComplianceNotify,
balancesNotify, balancesNotify,
errorAlertsNotify, errorAlertsNotify,
notifCenterTransactionNotify, notifCenterTransactionNotify,
blacklistNotify blacklistNotify,
cashboxNotify
} }

View file

@ -0,0 +1,35 @@
const db = require('./db')
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
exports.up = function (next) {
const sql = [
`ALTER TYPE notification_type ADD VALUE 'security'`
]
return loadLatest()
.then(config => {
const newConfig = {}
if(config.notifications_email_active) {
newConfig.notifications_email_security = true
}
if(config.notifications_sms_active) {
newConfig.notifications_sms_security = true
}
if(config.notifications_notificationCenter_active) {
newConfig.notifications_notificationCenter_security = true
}
return saveConfig(newConfig)
.then(() => db.multi(sql, next))
.catch(err => {
if (err.message === 'lamassu-server is not configured') {
return next()
}
return next(err)
})
})
}
module.exports.down = function (next) {
next()
}

View file

@ -22,6 +22,7 @@ const sizes = {
transactions: 184, transactions: 184,
compliance: 178, compliance: 178,
errors: 142, errors: 142,
security: 152,
active: 263 active: 263
} }
@ -57,6 +58,7 @@ const Row = ({ namespace, forceDisable }) => {
<Cell name="transactions" disabled={disabled} /> <Cell name="transactions" disabled={disabled} />
<Cell name="compliance" disabled={disabled} /> <Cell name="compliance" disabled={disabled} />
<Cell name="errors" disabled={disabled} /> <Cell name="errors" disabled={disabled} />
<Cell name="security" disabled={disabled} />
<Cell name="active" disabled={forceDisable} /> <Cell name="active" disabled={forceDisable} />
</Tr> </Tr>
) )