Skip to content

Commit

Permalink
Merge pull request #4152 from alphagov/pp_11755_add_banner
Browse files Browse the repository at this point in the history
PP-11755 Add maintenance banner
  • Loading branch information
kbottla authored Nov 1, 2023
2 parents aa096d8 + f570f6a commit 55d1a69
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/controllers/my-services/get-index.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const serviceService = require('../../services/service.service')
const { filterGatewayAccountIds } = require('../../utils/permissions')
const getHeldPermissions = require('../../utils/get-held-permissions')
const { DEFAULT_SERVICE_NAME } = require('../../utils/constants')
const maintenanceBannerEndDate = process.env.MAINTENANCE_BANNER_END_DATE || '2023-11-28T08:00:00'

function hasStripeAccount (gatewayAccounts) {
return gatewayAccounts.some(gatewayAccount =>
Expand All @@ -27,6 +28,13 @@ function sortServicesByLiveThenName (a, b) {
return 0
}

function shouldShowMaintenanceBanner () {
const currentDateTime = new Date()
const endDateTime = new Date(maintenanceBannerEndDate)

return currentDateTime <= endDateTime
}

module.exports = async function getServiceList (req, res) {
const servicesRoles = lodash.get(req, 'user.serviceRoles', [])
const newServiceId = res.locals.flash && res.locals.flash.inviteSuccessServiceId &&
Expand Down Expand Up @@ -62,7 +70,8 @@ module.exports = async function getServiceList (req, res) {
services_singular: servicesData.length === 1,
env: process.env,
has_account_with_payouts: hasStripeAccount(aggregatedGatewayAccounts),
has_live_account: filterGatewayAccountIds(aggregatedGatewayAccounts, true).length
has_live_account: filterGatewayAccountIds(aggregatedGatewayAccounts, true).length,
display_maintenance_banner: shouldShowMaintenanceBanner()
}

if (newServiceId) {
Expand Down
19 changes: 19 additions & 0 deletions app/views/services/_maintenance_banner.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}

{% if display_maintenance_banner %}
<div class="govuk-grid-column-two-thirds">
{% set html %}
<p class="govuk-notification-banner__heading">
GOV.UK Pay will be unavailable for three 4-hour windows between 14 November and 28 November 2023.
<a class="govuk-notification-banner__link" href="https://docs.payments.service.gov.uk/support_contact_and_more_information/scheduled_maintenance/">Read more about this downtime</a>.
</p>
{% endset %}

{{ govukNotificationBanner({
html: html,
attributes: {
id: 'my-services-notification-banner'
}
}) }}
</div>
{% endif %}
2 changes: 2 additions & 0 deletions app/views/services/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
{% block beforeContent %}{% endblock %}

{% block mainContent %}
{% include "./_maintenance_banner.njk" %}

<div class="govuk-grid-column-two-thirds">
{% if new_service_name %}
{% set html %}
Expand Down
16 changes: 16 additions & 0 deletions test/cypress/integration/my-services/my-services.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,19 @@ describe('User has access to one or more live services', () => {
cy.contains('a', 'View transactions for all your services')
})
})

describe('My services notification banner', () => {
it('should display the maintenance banner', () => {
const userExternalId = 'authenticated-user-id'

cy.task('setupStubs', [
userStubs.getUserSuccess({ userExternalId, gatewayAccountId: '1' }),
gatewayAccountStubs.getGatewayAccountsSuccess({ gatewayAccountId: '1' })
])
cy.setEncryptedCookies(userExternalId, 1)
cy.visit('/my-services')
cy.get('#my-services-notification-banner').should('exist')

cy.get('.govuk-notification-banner__heading').contains('GOV.UK Pay will be unavailable for three 4-hour windows between 14 November and 28 November 2023')
})
})
1 change: 1 addition & 0 deletions test/cypress/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ GOCARDLESS_TEST_CLIENT_ID=testClientId
PAYOUTS_RELEASE_DATE=1590148800
ENABLE_STRIPE_ONBOARDING_TASK_LIST=true
ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT=true
MAINTENANCE_BANNER_END_DATE=2024-01-15T00:00:00

0 comments on commit 55d1a69

Please sign in to comment.