Skip to content

Commit

Permalink
Changing the back link to user proper urls rather than just relying o…
Browse files Browse the repository at this point in the history
…n the browser history as the CSP breaks this
  • Loading branch information
ashward committed Jul 10, 2024
1 parent 2705faf commit 55f0d98
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/controllers/deleteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const showDeleteKey = async (req: Request, res: Response, next: NextFunct
const apiKey = await ApiService.getKey(user, customerKeyId)
const createdAt = DashboardPresenter.formatDate(apiKey.CreatedAt, true)

res.render('delete', { apiKey, createdAt })
res.render('delete', { apiKey, createdAt, backLinkHref: '/dashboard' })
} catch (error) {
next(error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/keyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiKeyPresenter } from '../presenters/apiKeyPresenter'
import { validationResult } from 'express-validator'

export const newKey = (_req: Request, res: Response): void => {
res.render('newKey')
res.render('newKey', { backLinkHref: '/dashboard' })
}

export const create = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/revokeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const showRevoke = async (req: Request, res: Response, next: NextFunction
const apiKey = await ApiService.getKey(user, customerKeyId)
const createdAt = DashboardPresenter.formatDate(apiKey.CreatedAt, true)

res.render('revoke', { apiKey, createdAt })
res.render('revoke', { apiKey, createdAt, backLinkHref: '/dashboard' })
} catch (error) {
next(error)
}
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/verificationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const newVerificationPage = (req: Request, res: Response): void => {
session.eoriNumber = session.eoriNumber ?? ''
session.ukacsReference = session.ukacsReference ?? ''
session.emailAddress = session.emailAddress ?? ''
res.render('verification', { session })
res.render('verification', { session, backLinkHref: '/' })
}

export const checkVerificationDetails = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
Expand Down Expand Up @@ -76,9 +76,9 @@ export const checkVerificationDetails = async (req: Request, res: Response, next
}
}
if (Object.keys(errors).length === 0) {
res.render('checkVerification', { body, session })
res.render('checkVerification', { body, session, backLinkHref: '/verification' })
} else {
res.render('verification', { body, session, errors, errorList: Object.values(errors) })
res.render('verification', { body, session, errors, errorList: Object.values(errors), backLinkHref: '/' })
}
} catch (error) {
next(error)
Expand Down Expand Up @@ -127,7 +127,7 @@ export const applicationComplete = async (req: Request, res: Response, next: Nex
req.session = null
res.render('completion', { applicationReference })
} else {
res.render('checkVerification', { body, session, errors, errorList: Object.values(errors) })
res.render('checkVerification', { body, session, errors, errorList: Object.values(errors), backLinkHref: '/verification' })
}
} catch (error) {
next(error)
Expand Down
1 change: 0 additions & 1 deletion views/back-button.njk

This file was deleted.

1 change: 0 additions & 1 deletion views/checkVerification.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}

{% block content %}
{% include "back-button.njk" %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">Check your answers</h1>
Expand Down
1 change: 0 additions & 1 deletion views/completion.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "layout.njk" %}
{% block content %}
{% include "back-button.njk" %}
<main class="govuk-main-wrapper govuk-width-container"
id="main-content"
role="main">
Expand Down
1 change: 0 additions & 1 deletion views/dashboard.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% block title %}Dashboard{% endblock %}
{% set createKeyPath = ["/dashboard/new"] | join %}
{% block content %}
{% include "back-button.njk" %}
<span class="govuk-caption-l">Commodity Code Identification Tool Hub</span>
<h1 class="govuk-heading-l">Your account</h1>
<p class="govuk-body">
Expand Down
1 change: 0 additions & 1 deletion views/delete.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}
{% block title %}Dashboard{% endblock %}
{% block content %}
{% include "back-button.njk" %}
<h1 class="govuk-heading-l">Delete an API Key</h1>
{{ govukWarningText({
"text": "Your API Key will be deleted with immediate effect and cannot be reactivated once deleted.",
Expand Down
1 change: 0 additions & 1 deletion views/keySuccessPage.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

{% block title %}Dashboard{% endblock %}
{% block content %}
{% include "back-button.njk" %}
{{ govukPanel({
titleText: "Your API Key has been created successfully"
}) }}
Expand Down
7 changes: 7 additions & 0 deletions views/layout.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "govuk/template.njk" %}
<!DOCTYPE html>
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
{% from "govuk/components/cookie-banner/macro.njk" import govukCookieBanner %}
{% from "govuk/components/skip-link/macro.njk" import govukSkipLink %}
{% from "govuk/components/header/macro.njk" import govukHeader %}
Expand Down Expand Up @@ -34,6 +35,12 @@
},
html: phaseBannerHtml
}) }}
{%- if backLinkHref %}
{{ govukBackLink({
href: backLinkHref,
text: "Back"
}) }}
{% endif %}
{% endblock %}
<body class="govuk-template_body govuk-frontend-supported">
<main id="main-content"
Expand Down
1 change: 0 additions & 1 deletion views/newKey.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

{% block title %}Dashboard{% endblock %}
{% block content %}
{% include "back-button.njk" %}
{% if error %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down
1 change: 0 additions & 1 deletion views/rejectedPage.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% from "govuk/components/button/macro.njk" import govukButton %}

{% block content %}
{% include "back-button.njk" %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l">Your application has been rejected</h1>
Expand Down
1 change: 0 additions & 1 deletion views/revoke.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}
{% block title %}Dashboard{% endblock %}
{% block content %}
{% include "back-button.njk" %}
<h1 class="govuk-heading-l">Revoke an API Key</h1>
<p class="govuk-body">
Check the below details regarding the API Key you have selected to revoke and confirm your choice.
Expand Down
1 change: 0 additions & 1 deletion views/verification.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}

{% block content %}
{% include "back-button.njk" %}
{% if errorList.length > 0 %}
{{ govukErrorSummary({
titleText: "There is a problem",
Expand Down

0 comments on commit 55f0d98

Please sign in to comment.