Skip to content

Commit

Permalink
Merge pull request #2491 from alphagov/PP-7583-remove-get-email-notif…
Browse files Browse the repository at this point in the history
…ication-middleware

PP-7583 Remove unnecessary getEmailNotifications middleware
  • Loading branch information
stephencdaly authored Jan 15, 2021
2 parents bfd8562 + b147859 commit a7b2db5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports.collectionEmailIndex = (req, res) => {
optional: 'OPTIONAL',
no: 'OFF'
},
emailCollectionMode: req.account.emailCollectionMode
emailCollectionMode: req.account.email_collection_mode
})
}

Expand All @@ -65,8 +65,8 @@ module.exports.collectionEmailUpdate = (req, res) => {

module.exports.confirmationEmailIndex = (req, res) => {
showConfirmationEmail(req, res, 'confirmation-email-toggle', {
confirmationEnabled: req.account.emailEnabled,
emailCollectionMode: req.account.emailCollectionMode
confirmationEnabled: req.account.email_notifications.PAYMENT_CONFIRMED.enabled,
emailCollectionMode: req.account.email_collection_mode
})
}

Expand All @@ -89,8 +89,8 @@ module.exports.confirmationEmailOff = (req, res) => {

module.exports.refundEmailIndex = (req, res) => {
showRefundEmail(req, res, 'refund-email-toggle', {
refundEmailEnabled: req.account.refundEmailEnabled,
emailCollectionMode: req.account.emailCollectionMode
refundEmailEnabled: req.account.email_notifications.REFUND_ISSUED && req.account.email_notifications.REFUND_ISSUED.enabled,
emailCollectionMode: req.account.email_collection_mode
})
}

Expand All @@ -108,28 +108,28 @@ module.exports.refundEmailUpdate = (req, res) => {
module.exports.index = (req, res) => {
showEmail(req, res, 'index', {
confirmationTabActive: true,
customEmailText: req.account.customEmailText,
customEmailText: req.account.email_notifications.PAYMENT_CONFIRMED.template_body,
serviceName: req.account.service_name,
emailEnabled: req.account.emailEnabled,
emailCollectionMode: req.account.emailCollectionMode,
refundEmailEnabled: req.account.refundEmailEnabled
emailEnabled: req.account.email_notifications.PAYMENT_CONFIRMED.enabled,
emailCollectionMode: req.account.email_collection_mode,
refundEmailEnabled: req.account.email_notifications.REFUND_ISSUED && req.account.email_notifications.REFUND_ISSUED.enabled
})
}

module.exports.indexRefundTabEnabled = (req, res) => {
showEmail(req, res, 'index', {
confirmationTabActive: false,
customEmailText: req.account.customEmailText,
customEmailText: req.account.email_notifications.PAYMENT_CONFIRMED.template_body,
serviceName: req.account.service_name,
emailEnabled: req.account.emailEnabled,
emailCollectionMode: req.account.emailCollectionMode,
refundEmailEnabled: req.account.refundEmailEnabled
emailEnabled: req.account.email_notifications.PAYMENT_CONFIRMED.enabled,
emailCollectionMode: req.account.email_collection_mode,
refundEmailEnabled: req.account.email_notifications.REFUND_ISSUED && req.account.email_notifications.REFUND_ISSUED.enabled
})
}

module.exports.edit = (req, res) => {
showEmail(req, res, 'edit', {
customEmailText: req.account.customEmailText,
customEmailText: req.account.email_notifications.PAYMENT_CONFIRMED.template_body,
serviceName: req.account.service_name
})
}
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/settings/get.settings.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module.exports = (req, res) => {
supports3ds: req.account.supports3ds,
requires3ds: req.account.requires3ds,
collectBillingAddress: req.service.collectBillingAddress,
emailCollectionMode: humaniseEmailMode(req.account.emailCollectionMode),
confirmationEmailEnabled: req.account.emailEnabled,
refundEmailEnabled: req.account.refundEmailEnabled,
emailCollectionMode: humaniseEmailMode(req.account.email_collection_mode),
confirmationEmailEnabled: req.account.email_notifications.PAYMENT_CONFIRMED.enabled,
refundEmailEnabled: req.account.email_notifications.REFUND_ISSUED && req.account.email_notifications.REFUND_ISSUED.enabled,
allowMoto: req.account.allow_moto,
motoMaskCardNumberInputEnabled: req.account.moto_mask_card_number_input,
motoMaskSecurityCodeInputEnabled: req.account.moto_mask_card_security_code_input
Expand Down
15 changes: 0 additions & 15 deletions app/middleware/get-email-notification.js

This file was deleted.

33 changes: 16 additions & 17 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const getServiceAndAccount = require('./middleware/get-service-and-gateway-accou
// Middleware
const { lockOutDisabledUsers, enforceUserAuthenticated, enforceUserFirstFactor, redirectLoggedInUser } = require('./services/auth.service')
const { validateAndRefreshCsrf, ensureSessionHasCsrfSecret } = require('./middleware/csrf')
const getEmailNotification = require('./middleware/get-email-notification')
const getAccount = require('./middleware/get-gateway-account')
const hasServices = require('./middleware/has-services')
const resolveService = require('./middleware/resolve-service')
Expand Down Expand Up @@ -92,14 +91,14 @@ const {
requestToGoLive, policyPages, stripeSetup, stripe,
settings, yourPsp, allServiceTransactions, payouts
} = paths
const {
const {
digitalWallet,
emailNotifications,
paymentTypes,
toggle3ds,
toggleBillingAddress,
toggleMotoMaskCardNumberAndSecurityCode
} = paths.account
} = paths.account

// Exports
module.exports.generateRoute = generateRoute
Expand Down Expand Up @@ -200,7 +199,7 @@ module.exports.bind = function (app) {
app.use(authenticatedPaths, enforceUserAuthenticated, validateAndRefreshCsrf) // Enforce authentication on all get requests
app.use(authenticatedPaths.filter(item => !lodash.values(serviceSwitcher).includes(item)), hasServices) // Require services everywhere but the switcher page

app.get(settings.index, permission('transactions-details:read'), getAccount, getEmailNotification, settingsController.index)
app.get(settings.index, permission('transactions-details:read'), getAccount, settingsController.index)

// TRANSACTIONS
app.get(transactions.index, permission('transactions:read'), getAccount, paymentMethodIsCard, transactionsListController)
Expand Down Expand Up @@ -253,19 +252,19 @@ module.exports.bind = function (app) {
account.post(digitalWallet.googlePay, permission('payment-types:update'), paymentMethodIsCard, digitalWalletController.postGooglePay)

// EMAIL
account.get(emailNotifications.index, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.index)
account.get(emailNotifications.indexRefundTabEnabled, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.indexRefundTabEnabled)
account.get(emailNotifications.edit, permission('email-notification-paragraph:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.edit)
account.post(emailNotifications.confirm, permission('email-notification-paragraph:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirm)
account.post(emailNotifications.update, permission('email-notification-paragraph:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.update)
account.get(emailNotifications.collection, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.collectionEmailIndex)
account.post(emailNotifications.collection, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.collectionEmailUpdate)
account.get(emailNotifications.confirmation, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailIndex)
account.post(emailNotifications.confirmation, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailUpdate)
account.post(emailNotifications.off, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailOff)
account.post(emailNotifications.on, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailOn)
account.get(emailNotifications.refund, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.refundEmailIndex)
account.post(emailNotifications.refund, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.refundEmailUpdate)
account.get(emailNotifications.index, permission('email-notification-template:read'), paymentMethodIsCard, emailNotificationsController.index)
account.get(emailNotifications.indexRefundTabEnabled, permission('email-notification-template:read'), paymentMethodIsCard, emailNotificationsController.indexRefundTabEnabled)
account.get(emailNotifications.edit, permission('email-notification-paragraph:update'), paymentMethodIsCard, emailNotificationsController.edit)
account.post(emailNotifications.confirm, permission('email-notification-paragraph:update'), paymentMethodIsCard, emailNotificationsController.confirm)
account.post(emailNotifications.update, permission('email-notification-paragraph:update'), paymentMethodIsCard, emailNotificationsController.update)
account.get(emailNotifications.collection, permission('email-notification-template:read'), paymentMethodIsCard, emailNotificationsController.collectionEmailIndex)
account.post(emailNotifications.collection, permission('email-notification-toggle:update'), paymentMethodIsCard, emailNotificationsController.collectionEmailUpdate)
account.get(emailNotifications.confirmation, permission('email-notification-template:read'), paymentMethodIsCard, emailNotificationsController.confirmationEmailIndex)
account.post(emailNotifications.confirmation, permission('email-notification-toggle:update'), paymentMethodIsCard, emailNotificationsController.confirmationEmailUpdate)
account.post(emailNotifications.off, permission('email-notification-toggle:update'), paymentMethodIsCard, emailNotificationsController.confirmationEmailOff)
account.post(emailNotifications.on, permission('email-notification-toggle:update'), paymentMethodIsCard, emailNotificationsController.confirmationEmailOn)
account.get(emailNotifications.refund, permission('email-notification-template:read'), paymentMethodIsCard, emailNotificationsController.refundEmailIndex)
account.post(emailNotifications.refund, permission('email-notification-toggle:update'), paymentMethodIsCard, emailNotificationsController.refundEmailUpdate)

// SERVICE SWITCHER
app.get(serviceSwitcher.index, myServicesController.getIndex)
Expand Down
18 changes: 0 additions & 18 deletions app/services/email.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@ const ConnectorClient = require('./clients/connector.client.js').ConnectorClient

const connectorClient = new ConnectorClient(process.env.CONNECTOR_URL)

const getEmailSettings = async function (accountID, correlationId) {
try {
const data = await connectorClient.getAccount({
gatewayAccountId: accountID,
correlationId: correlationId
})
return {
customEmailText: data.email_notifications.PAYMENT_CONFIRMED.template_body,
emailEnabled: data.email_notifications.PAYMENT_CONFIRMED.enabled,
emailCollectionMode: data.email_collection_mode,
refundEmailEnabled: data.email_notifications.REFUND_ISSUED && data.email_notifications.REFUND_ISSUED.enabled
}
} catch (err) {
clientFailure(err, 'GET', false)
}
}

const updateConfirmationTemplate = async function (accountID, emailText, correlationId) {
try {
const patch = { 'op': 'replace', 'path': '/payment_confirmed/template_body', 'value': emailText }
Expand Down Expand Up @@ -89,7 +72,6 @@ const clientFailure = function (err, methodType, isPatchEndpoint) {
}

module.exports = {
getEmailSettings,
updateConfirmationTemplate,
setEmailCollectionMode,
setConfirmationEnabled,
Expand Down
64 changes: 0 additions & 64 deletions test/unit/middleware/get-email-notification.test.js

This file was deleted.

125 changes: 0 additions & 125 deletions test/unit/services/email.service.test.js

This file was deleted.

0 comments on commit a7b2db5

Please sign in to comment.