Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haar 2764 read only flag #113

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions helm_deploy/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ generic-service:
MANAGE_USERS_API_URL: "https://manage-users-api-dev.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-dev.prison.service.justice.gov.uk"
ENVIRONMENT_NAME: DEV
IS_READ_ONLY: false
SHOW_MIGRATION_WARNING: true

generic-prometheus-alerts:
alertSeverity: digital-prison-service-dev
2 changes: 2 additions & 0 deletions helm_deploy/values-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ generic-service:
MANAGE_USERS_API_URL: "https://manage-users-api-preprod.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-preprod.prison.service.justice.gov.uk"
ENVIRONMENT_NAME: PRE-PRODUCTION
IS_READ_ONLY: false
SHOW_MIGRATION_WARNING: true

generic-prometheus-alerts:
alertSeverity: digital-prison-service-dev
2 changes: 2 additions & 0 deletions helm_deploy/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ generic-service:
HMPPS_AUTHORIZATION_SERVER_URL: "https://authorization.hmpps.service.justice.gov.uk"
MANAGE_USERS_API_URL: "https://manage-users-api.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api.prison.service.justice.gov.uk"
IS_READ_ONLY: true
SHOW_MIGRATION_WARNING: true

generic-prometheus-alerts:
alertSeverity: digital-prison-service
2 changes: 2 additions & 0 deletions helm_deploy/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ generic-service:
MANAGE_USERS_API_URL: "https://manage-users-api-stage.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-stage.prison.service.justice.gov.uk"
ENVIRONMENT_NAME: STAGE
IS_READ_ONLY: false
SHOW_MIGRATION_WARNING: true

generic-prometheus-alerts:
alertSeverity: digital-prison-service-dev
2 changes: 2 additions & 0 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ export default {
},
domain: get('INGRESS_URL', 'http://localhost:3000', requiredInProduction),
environmentName: get('ENVIRONMENT_NAME', ''),
isReadOnly: get('IS_READ_ONLY', 'false') === 'true',
showMigrationWarning: get('SHOW_MIGRATION_WARNING', 'false') === 'true',
}
2 changes: 2 additions & 0 deletions server/utils/nunjucksSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default function nunjucksSetup(app: express.Express, applicationInfo: App
app.locals.applicationName = 'HMPPS Authorization'
app.locals.environmentName = config.environmentName
app.locals.environmentNameColour = config.environmentName === 'PRE-PRODUCTION' ? 'govuk-tag--green' : ''
app.locals.isReadOnly = config.isReadOnly
app.locals.showMigrationWarning = config.showMigrationWarning

// Cachebusting version string
if (production) {
Expand Down
51 changes: 28 additions & 23 deletions server/views/pages/base-client.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

{% set pageName="Home" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{%- from "moj/components/header/macro.njk" import mojHeader -%}
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% from "govuk/components/input/macro.njk" import govukInput %}
Expand All @@ -20,12 +16,15 @@
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{%- from "govuk/components/table/macro.njk" import govukTable -%}

{% block content %}
{% block beforeContent %}
{{ super() }}
{{ govukBackLink({
text: "Back",
href: "/"
}) }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

Expand All @@ -52,26 +51,30 @@
}
}) }}

<form class="govuk-grid-row" action="/base-clients/{{ baseClient.baseClientId }}/clients" method="POST">
<input type="hidden" name="_csrf" value="{{ csrfToken }}">
<div class="govuk-grid-column-one-half">
{{ govukButton({
text: "Add client instance",
attributes: {
"data-qa": "add-new-client-button"
}
}) }}
</div>
</form>
{% if not isReadOnly %}
<form class="govuk-grid-row" action="/base-clients/{{ baseClient.baseClientId }}/clients" method="POST">
<input type="hidden" name="_csrf" value="{{ csrfToken }}">
<div class="govuk-grid-column-one-half">
{{ govukButton({
text: "Add client instance",
attributes: {
"data-qa": "add-new-client-button"
}
}) }}
</div>
</form>
{% endif %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-l">Client details</h2>
</div>
<div class="govuk-grid-column-one-third govuk-!-text-align-right">
<a class="govuk-link" href="/base-clients/{{ baseClient.baseClientId }}/edit" data-qa='change-client-details-link'>Change
client details</a>
</div>
{% if not isReadOnly %}
<div class="govuk-grid-column-one-third govuk-!-text-align-right">
<a class="govuk-link" href="/base-clients/{{ baseClient.baseClientId }}/edit" data-qa='change-client-details-link'>Change
client details</a>
</div>
{% endif %}
</div>

{{ govukTable({
Expand Down Expand Up @@ -292,9 +295,11 @@
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-l">Deployment details</h2>
</div>
<div class="govuk-grid-column-one-third govuk-!-text-align-right">
<a class="govuk-link" href="/base-clients/{{ baseClient.baseClientId }}/deployment" data-qa='change-deployment-details-link'>Change deployment details</a>
</div>
{% if not isReadOnly %}
<div class="govuk-grid-column-one-third govuk-!-text-align-right">
<a class="govuk-link" href="/base-clients/{{ baseClient.baseClientId }}/deployment" data-qa='change-deployment-details-link' disabled='{{ isReadOnly }}'>Change deployment details</a>
</div>
{% endif %}
</div>

{{ govukTable({
Expand Down
31 changes: 17 additions & 14 deletions server/views/pages/base-clients.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
{% set pageName="Home" %}
{% set bodyClasses = "extra-wide" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{%- from "moj/components/header/macro.njk" import mojHeader -%}
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% from "govuk/components/input/macro.njk" import govukInput %}
Expand Down Expand Up @@ -169,16 +165,23 @@
<div class="moj-action-bar">

<div class="moj-action-bar__filter"></div>
{{ mojButtonMenu({
items: [{
text: 'Add new client',
href:"/base-clients/new",
classes: 'govuk-button--primary',
attributes: {
'data-qa': 'addNewBaseClientButton'
}
}]
}) }}
{% if isReadOnly %}
{{ mojButtonMenu({
items: []
}) }}
{% else %}
{{ mojButtonMenu({
items: [{
text: 'Add new client',
href:"/base-clients/new",
classes: 'govuk-button--primary',
attributes: {
'data-qa': 'addNewBaseClientButton'
}
}]
}) }}
{% endif %}

<div class="moj-action-bar__filterTagsContainer"></div>
</div>

Expand Down
7 changes: 2 additions & 5 deletions server/views/pages/delete-client-instance.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

{% set pageName="Delete client?" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{%- from "moj/components/header/macro.njk" import mojHeader -%}
{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/button/macro.njk" import govukButton %}
Expand Down Expand Up @@ -86,7 +82,8 @@
classes: "govuk-button--warning",
attributes: {
"data-qa": "delete-button"
}
},
disabled: isReadOnly
}) }}
{{ govukButton({
text: "Cancel",
Expand Down
4 changes: 0 additions & 4 deletions server/views/pages/edit-base-client-deployment.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
{% set pageName="Home" %}
{% set bodyClasses = "extra-wide" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/label/macro.njk" import govukLabel %}
Expand Down
4 changes: 0 additions & 4 deletions server/views/pages/edit-base-client-details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
{% set pageName="Home" %}
{% set bodyClasses = "extra-wide" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/select/macro.njk" import govukSelect %}
Expand Down
4 changes: 0 additions & 4 deletions server/views/pages/new-base-client-details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
{% set pageName="Home" %}
{% set bodyClasses = "extra-wide" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/select/macro.njk" import govukSelect %}
Expand Down
4 changes: 0 additions & 4 deletions server/views/pages/new-base-client-grant.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

{% set pageName="Home" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/label/macro.njk" import govukLabel %}
{% from "govuk/components/radios/macro.njk" import govukRadios %}
Expand Down
4 changes: 0 additions & 4 deletions server/views/pages/new-base-client-success.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
{% set pageName="Home" %}
{% set bodyClasses = "extra-wide" %}

{% block header %}
{% include "partials/header.njk" %}
{% endblock %}

{% from "govuk/components/panel/macro.njk" import govukPanel %}
{%- from "govuk/components/table/macro.njk" import govukTable -%}
{% from "govuk/components/button/macro.njk" import govukButton %}
Expand Down
14 changes: 14 additions & 0 deletions server/views/partials/layout.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% from "govuk/components/phase-banner/macro.njk" import govukPhaseBanner %}

{% extends "govuk/template.njk" %}

{% block head %}
Expand All @@ -16,6 +18,18 @@
{% include "./header.njk" %}
{% endblock %}

{% block beforeContent %}
{% if showMigrationWarning and not isReadOnly %}
{{ govukPhaseBanner({
tag: {
text: "Warning",
classes: "govuk-tag--red"
},
html: 'This service is in migration phase - do not create or edit active clients.'
}) }}
{% endif %}
{% endblock %}

{% block bodyStart %}
{% endblock %}

Expand Down
26 changes: 21 additions & 5 deletions server/views/presenters/viewBaseClientPresenter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,38 @@ describe('viewBaseClientPresenter', () => {
expect(expectedAccessed).toEqual(actualAccessed)
})

it('links to a delete page for each client', () => {
it('links to a delete page if not readOnly', () => {
// Given some base clients with some clients
const isReadOnly = false
const baseClient = baseClientFactory.build({ baseClientId: 'baseClientId' })
const clients = [clientFactory.build({ clientId: 'clientIdA' }), clientFactory.build({ clientId: 'clientIdB' })]

// When we map to a presenter
const presenter = viewBaseClientPresenter(baseClient, clients)
const presenter = viewBaseClientPresenter(baseClient, clients, isReadOnly)

// Then the dates are formatted as DD/MM/YYYY
// Then the delete links are correct
const expected = [
'<a class="govuk-link" href="/base-clients/baseClientId/clients/clientIdA/delete" data-qa=\'delete-client-instance-link\'>delete</a>',
'<a class="govuk-link" href="/base-clients/baseClientId/clients/clientIdB/delete" data-qa=\'delete-client-instance-link\'>delete</a>',
"<a class='govuk-link' href='/base-clients/baseClientId/clients/clientIdA/delete' data-qa='delete-client-instance-link'>delete</a>",
"<a class='govuk-link' href='/base-clients/baseClientId/clients/clientIdB/delete' data-qa='delete-client-instance-link'>delete</a>",
]
const actual = presenter.clientsTable.map(row => row[3].html)
expect(expected).toEqual(actual)
})

it('does not link to a delete page if readOnly', () => {
// Given some base clients with some clients
const isReadOnly = true
const baseClient = baseClientFactory.build({ baseClientId: 'baseClientId' })
const clients = [clientFactory.build({ clientId: 'clientIdA' }), clientFactory.build({ clientId: 'clientIdB' })]

// When we map to a presenter
const presenter = viewBaseClientPresenter(baseClient, clients, isReadOnly)

// Then delete links are empty
const expected = ['', '']
const actual = presenter.clientsTable.map(row => row[3].html)
expect(expected).toEqual(actual)
})
})

describe('expiry', () => {
Expand Down
8 changes: 5 additions & 3 deletions server/views/presenters/viewBaseClientPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseClient } from '../../interfaces/baseClientApi/baseClient'
import { Client } from '../../interfaces/baseClientApi/client'
import { dateTimeFormat, daysRemaining } from '../../utils/utils'

export default (baseClient: BaseClient, clients: Client[]) => {
export default (baseClient: BaseClient, clients: Client[], isReadOnly: boolean = true) => {
return {
clientsTable: clients.map(item => [
{
Expand All @@ -15,10 +15,12 @@ export default (baseClient: BaseClient, clients: Client[]) => {
html: item.accessed ? dateTimeFormat(item.accessed) : '',
},
{
html: `<a class="govuk-link" href="/base-clients/${baseClient.baseClientId}/clients/${item.clientId}/delete" data-qa='delete-client-instance-link'>delete</a>`,
html: isReadOnly
? ''
: `<a class='govuk-link' href='/base-clients/${baseClient.baseClientId}/clients/${item.clientId}/delete' data-qa='delete-client-instance-link'>delete</a>`,
},
]),
expiry: baseClient.config.expiryDate ? `Yes - days remaining ${daysRemaining(baseClient.config.expiryDate)}` : 'No',
skipToAzureField: '',
skipToAzure: baseClient.authorisationCode.azureAdLoginFlow,
}
}