Skip to content

Commit

Permalink
Prevent infinite loop for ineligible application
Browse files Browse the repository at this point in the history
This prevents an infinite loop when building the task list for an
application that has the ESAP AP type selected but no agreement with
CHPP. The loop was the result of the inegibility page returning the user
to the AP type selection page on submission. This works if the user then saves a
different AP type straight away; however, should the user then exit the
application, any further attempt to load the application would result in
the loop.

To prevent this, the ESAP inegibility page no longer posts, but simply
offers a link to the AP Type selection.

In addition, to ensure the AP Type task is shown as 'In progress' in the
above scenario, the ESAP ineligibility page always returns an error.
This error is never shown, but prevents the loop from continuing with
processing any further task.
  • Loading branch information
froddd committed Jan 7, 2025
1 parent a9a7191 commit 8c0b27c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ describe('EsapNotEligible', () => {

itShouldHavePreviousValue(page, 'esap-exceptional-case')

itShouldHaveNextValue(page, 'ap-type')
itShouldHaveNextValue(page, '')

describe('errors', () => {
it('should return an empty object', () => {
expect(page.errors()).toEqual({})
it('should return an object with an error to prevent continuing with the application', () => {
expect(page.errors()).toEqual({
esapNotEligible: 'The person is not eligible for an Enhanced Security Approved Premises (ESAP) placement.',
})
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { ApprovedPremisesApplication as Application } from '@approved-premises/api'
import type { TaskListErrors } from '@approved-premises/ui'
import { Page } from '../../../utils/decorators'

import TasklistPage from '../../../tasklistPage'

@Page({ name: 'not-esap-eligible', bodyProperties: [] })
@Page({ name: 'not-esap-eligible', bodyProperties: ['esapNotEligible'] })
export default class EsapNotEligible implements TasklistPage {
title = `The person is not eligible for an Enhanced Security Approved Premises (ESAP) placement.`

constructor(
readonly body: Record<string, never>,
readonly body: Partial<{
esapNotEligible: never
}>,
readonly application: Application,
) {}

Expand All @@ -21,10 +24,14 @@ export default class EsapNotEligible implements TasklistPage {
}

next() {
return 'ap-type'
return ''
}

errors() {
return {}
const errors: TaskListErrors<this> = {}

errors.esapNotEligible = this.title

return errors
}
}
53 changes: 21 additions & 32 deletions server/views/applications/pages/type-of-ap/not-esap-eligible.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,31 @@
{% set mainClasses = "app-container govuk-body" %}

{% block beforeContent %}
{{ govukBackLink({
text: "Back",
href: paths.applications.pages.show({ id: applicationId, task: task, page: page.previous() })
{{ govukBackLink({
text: "Back",
href: paths.applications.pages.show({ id: applicationId, task: task, page: page.previous() })
}) }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="{{ columnClasses | default("govuk-grid-column-two-thirds") }}">
<form action="{{ paths.applications.pages.update({ id: applicationId, task: task, page: page.name }) }}?_method=PUT" method="post">
<input type="hidden" name="_csrf" value="{{ csrfToken }}"/>

<h1 class="govuk-heading-l">{{ page.title }}</h1>

<p>From the information you've provided this person is not eligible for an ESAP placement.</p>

<p>You can continue with an application for a standard Approved Premises placement. Or you can return to the dashboard to withdraw your application.</p>

<div class="govuk-button-group">
{{
govukButton({
text: "Continue with application",
preventDoubleClick: true
})
}}
{{
linkTo(
paths.applications.index,
{},
{
text: 'Back to dashboard'
}
) | safe
}}
<div class="govuk-grid-row">
<div class="{{ columnClasses | default("govuk-grid-column-two-thirds") }}">

<h1 class="govuk-heading-l">{{ page.title }}</h1>

<p>From the information you've provided this person is not eligible for an ESAP placement.</p>

<p>You can continue with an application for a standard Approved Premises placement. Or you can return to the
dashboard to withdraw your application.</p>

<div class="govuk-button-group">
{{ govukButton({
text: "Continue with application",
href: paths.applications.pages.show({ id: applicationId, task: task, page: 'ap-type' })
}) }}

<a href="{{ paths.applications.index() }}">Back to dashboard</a>
</div>
</div>
</form>
</div>
</div>
{% endblock %}

0 comments on commit 8c0b27c

Please sign in to comment.