Skip to content

Commit 635e0ca

Browse files
authored
LGA-2803 - Add maintenance page (#27)
Add maintenance page
1 parent 94515a7 commit 635e0ca

File tree

11 files changed

+94
-12
lines changed

11 files changed

+94
-12
lines changed

.github/workflows/test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: workflow_call
44

55
env:
66
SECRET_KEY: "TEST_KEY"
7+
ENVIRONMENT: CI
78

89

910
jobs:
@@ -23,12 +24,17 @@ jobs:
2324
run: |
2425
python -m pip install --upgrade pip
2526
python -m pip install -r requirements/generated/requirements-development.txt
27+
2628
2729
- name: Unit test with pytest
2830
run: |
2931
# Remove this after we move from build assets in-app to esbuild
3032
npm install
3133
pip install pytest pytest-cov
34+
# This is required because at the moment the assets are being built in the app
35+
# When the app tries to access sass files in node_modules it will fail unless this is included
36+
npm install
37+
3238
coverage run -m pytest tests/unit_tests
3339
coverage xml
3440

app/config/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ class Config(object):
2020
SESSION_COOKIE_HTTPONLY = True
2121
SENTRY_DSN = os.environ.get("SENTRY_DSN")
2222
LANGUAGES = {"en": "English", "cy": "Welsh"}
23+
SERVICE_UNAVAILABLE = os.environ.get("MAINTENANCE_MODE", "False").lower() == "true"

app/main/routes.py

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
render_template,
99
request,
1010
current_app,
11+
url_for,
1112
abort,
1213
)
1314
from flask_wtf.csrf import CSRFError
@@ -46,6 +47,18 @@ def set_locale(locale):
4647
return response
4748

4849

50+
@bp.route("/status", methods=["GET"])
51+
def status():
52+
return "OK"
53+
54+
55+
@bp.route("/service-unavailable", methods=["GET"])
56+
def service_unavailable_page():
57+
if not current_app.config["SERVICE_UNAVAILABLE"]:
58+
return redirect(url_for("main.index"))
59+
abort(503)
60+
61+
4962
@bp.route("/accessibility", methods=["GET"])
5063
def accessibility():
5164
return render_template("accessibility.html")
@@ -100,3 +113,22 @@ def http_exception(error):
100113
def csrf_error(error):
101114
flash("The form you were submitting has expired. Please try again.")
102115
return redirect(request.full_path)
116+
117+
118+
@bp.before_request
119+
def service_unavailable_middleware():
120+
if not current_app.config["SERVICE_UNAVAILABLE"]:
121+
return
122+
123+
service_unavailable_url = url_for("main.service_unavailable_page")
124+
exempt_urls = [
125+
service_unavailable_url,
126+
url_for("main.status"),
127+
url_for("main.cookies"),
128+
url_for("main.accessibility"),
129+
url_for("main.privacy"),
130+
url_for("main.set_locale", locale="en"),
131+
url_for("main.set_locale", locale="cy"),
132+
]
133+
if request.path not in exempt_urls:
134+
return redirect(service_unavailable_url)

app/templates/main/503.html

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
{% extends "base.html" %}
22

3-
{% block pageTitle %}Sorry, the service is unavailable – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}
3+
{% block pageTitle %}{% trans %}Sorry, the service is unavailable{% endtrans %} – {{ config.SERVICE_NAME }} – GOV.UK{% endblock %}
44

55
{% set mainClasses = "govuk-main-wrapper--l" %}
66

77
{% block content %}
88
<div class="govuk-grid-row">
99
<div class="govuk-grid-column-two-thirds">
10-
<h1 class="govuk-heading-l">Sorry, the service is unavailable</h1>
11-
<p class="govuk-body">You will be able to use the service from 9am on Monday 19&nbsp;November&nbsp;2018.</p>
10+
<h1 class="govuk-heading-l">{% trans %}Sorry, the service is unavailable{% endtrans%}</h1>
11+
<p class="govuk-body">{% trans %}The service will be available again soon - try in the next hour.{% endtrans%}</p>
12+
13+
<p class="govuk-body">{% trans %}If you already started using the service, your answers will not be saved.{% endtrans%}</p>
14+
<h2 class="govuk-heading-m">{% trans %}If you need urgent help{% endtrans%}</h2>
15+
<p class="govuk-body">{% trans %}Contact the Civil Legal Advice (CLA) helpline.{% endtrans%}</p>
16+
<p class="govuk-body">
17+
{% trans %}Telephone{% endtrans%}: 0345 345 4345 <br />
18+
<a class="govuk-link--no-underline" href="https://www.relayuk.bt.com/">{% trans %}Relay UK{% endtrans%}</a> {% trans %}(textphone and app): 18001 then 0345 345 4345{% endtrans%}
19+
</p>
20+
<p class="govuk-body">
21+
{% trans %}Monday to Friday, 9am to 8pm{% endtrans%} <br />
22+
{% trans %}Saturday, 9am to 12:30pm{% endtrans%} <br />
23+
<a class="govuk-link--no-underline" href="https://www.gov.uk/call-charges">{% trans %}Find out about call charges{% endtrans%}</a>
24+
</p>
25+
<p class="govuk-body">
26+
{% trans %}If you’re worried about the cost of a call{% endtrans%}:
27+
<ul class="govuk-list govuk-list--bullet">
28+
<li>{% trans %}ask the helpline to call you back, or{% endtrans%}</li>
29+
<li>{% trans %}text ‘legalaid’ and your name to 80010 for a call back within 24 hours{% endtrans %}</li>
30+
</ul>
31+
</p>
1232
</div>
1333
</div>
14-
{% endblock %}
34+
{% endblock %}

compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
restart: always
1111
environment:
1212
- SECRET_KEY=CHANGE_ME
13+
- MAINTENANCE_MODE=FALSE
1314
- FLASK_RUN_PORT=8020
1415
- SENTRY_DSN=${SENTRY_DSN:-}
1516
ports:

helm_deploy/laa-access-civil-legal-aid/templates/deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ spec:
4444
protocol: TCP
4545
livenessProbe:
4646
httpGet:
47-
path: /
47+
path: /status
4848
port: http
4949
readinessProbe:
5050
httpGet:
51-
path: /
51+
path: /status
5252
port: http

helm_deploy/laa-access-civil-legal-aid/templates/ingress.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ metadata:
1313
labels:
1414
{{- include "laa-access-civil-legal-aid.labels" . | nindent 4 }}
1515
annotations:
16+
nginx.ingress.kubernetes.io/custom-http-errors: "413,502,504"
1617
{{- if .Values.ingress.cluster.name }}
1718
external-dns.alpha.kubernetes.io/set-identifier: "{{ $fullName }}-{{ .Release.Namespace }}-{{- .Values.ingress.cluster.name -}}"
1819
external-dns.alpha.kubernetes.io/aws-weight: "{{- .Values.ingress.cluster.weight -}}"

helm_deploy/laa-access-civil-legal-aid/values.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ envVars:
6767
SENTRY_DSN:
6868
secret:
6969
name: sentry
70-
key: dsn
70+
key: dsn
71+
MAINTENANCE_MODE:
72+
configmap:
73+
name: maintenance-mode
74+
key: enabled
75+
optional: true

tests/functional_tests/test_accessibility.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from axe_core_python.sync_playwright import Axe
66
import json
77
import os
8+
import shutil
9+
810

911
ACCESSIBILITY_STANDARDS = ["wcag2a", "wcag2aa"]
1012

@@ -45,7 +47,8 @@ def check_accessibility(page: Page):
4547

4648
@pytest.mark.usefixtures("live_server")
4749
def test_all_page_accessibility(app, page: Page):
48-
ignored_routes = ["static", "/", "main.set_locale"]
50+
ignored_routes = ["static", "/", "main.status", "main.set_locale"]
51+
shutil.rmtree("tests/functional_tests/accessibility_output", ignore_errors=True)
4952
routes = app.view_functions
5053
for route in routes:
5154
if route not in ignored_routes:

tests/unit_tests/test_example.py

-4
This file was deleted.

tests/unit_tests/test_pages.py

+17
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,20 @@ def test_set_locale(app, client):
99
def test_set_locale_invalid(app, client):
1010
response = client.get("/locale/de", headers={"referer": "http://localhost/privacy"})
1111
assert response.status_code == 404, f"Expecting 404 got {response.status_code}"
12+
13+
14+
def test_service_unavailable_on(app, client):
15+
app.config["SERVICE_UNAVAILABLE"] = True
16+
response = client.get("/")
17+
assert response.status_code == 302
18+
assert response.headers["location"] == "/service-unavailable"
19+
response = client.get("/", follow_redirects=True)
20+
assert response.status_code == 503
21+
assert response.request.path == "/service-unavailable"
22+
23+
24+
def test_service_unavailable_off(app, client):
25+
app.config["SERVICE_UNAVAILABLE"] = False
26+
response = client.get("/service-unavailable", follow_redirects=True)
27+
assert response.status_code == 200
28+
assert response.request.path == "/"

0 commit comments

Comments
 (0)