From 9b81ba2a06da77b1113f03229ca77a0a1f347db1 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 5 Aug 2024 14:11:51 +0100 Subject: [PATCH 01/18] An attempt at extracting the uac form components --- rh_ui/templates/partials/uac_form.html | 47 ++++++++++++++++++++++++++ rh_ui/templates/start.html | 35 ++----------------- 2 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 rh_ui/templates/partials/uac_form.html diff --git a/rh_ui/templates/partials/uac_form.html b/rh_ui/templates/partials/uac_form.html new file mode 100644 index 0000000..16342ef --- /dev/null +++ b/rh_ui/templates/partials/uac_form.html @@ -0,0 +1,47 @@ +{# Create error component if error message has been flashed to use in onsAccessCode #} +{% set flashed_messages = get_flashed_messages() %} +{% set error_uac = None %} + +{{flashed_messages}} +{% if flashed_messages %} + {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} + {%- if 'uac_empty' in flashed_messages -%} + {%- set error_uac = { + 'id': 'uac_empty', + 'text': _('Enter an access code'), + 'field': 'uac_empty', + 'group': 'ERROR' + } -%} + {%- elif 'uac_invalid_length' in flashed_messages -%} + {%- set error_uac = { + 'id': 'uac_invalid_length', + 'text': _('Enter a 16-character access code'), + 'field': 'uac_invalid_length', + 'group': 'ERROR'} -%} + {%- elif 'uac_invalid' in flashed_messages -%} + {%- set error_uac = { + 'id': 'uac_invalid', + 'text': _('Access code not recognised. Enter the code again.'), + 'field': 'uac_invalid', + 'group': 'ERROR'} -%} + {%- endif -%} +{%- endif -%} + + +{{ onsAccessCode({ + "id": "uac", + "name": "uac", + + "label": { + "text": _("Enter your 16-character access code"), + "description": _('Keep this code safe. You will need to enter it every time you access your study') + }, + + "securityMessage": _('Your personal information is protected by law and will be kept confidential.'), + + "error": error_uac + +}) }} + + + diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index 10e53c9..cc5d510 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -4,24 +4,7 @@ {% from "components/button/_macro.njk" import onsButton %} {% from "components/details/_macro.njk" import onsDetails %} -{# display uac error msg if exists #} - -{% set flashed_messages = get_flashed_messages() %} - -{%- if 'uac_empty' in flashed_messages -%} - {%- set error_uac = {'id': 'uac_empty', 'text': _('Enter an access code'), 'field': 'uac_empty','group': 'ERROR'} -%} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} -{%- elif 'uac_invalid_length' in flashed_messages -%} - {%- set error_uac = {'id': 'uac_invalid_length', 'text': _('Enter a 16-character access code'), 'field': 'uac_invalid_length','group': 'ERROR'} -%} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} -{%- elif 'uac_invalid' in flashed_messages -%} - {%- set error_uac = {'id': 'uac_invalid', 'text': _('Access code not recognised. Enter the code again.'), 'field': 'uac_invalid','group': 'ERROR'} -%} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} - -{%- else -%} - {%- set error_uac = None -%} - {%- set page_title_value = _('Start study - ONS Surveys') -%} -{%- endif -%} +{% set page_title_value = _('Start study - ONS Surveys') %} {% block main %}
@@ -30,21 +13,7 @@ {% endif %}

{{ _('Start study') }}

- -{{ onsAccessCode({ - "id": "uac", - "name": "uac", - - "label": { - "text": _("Enter your 16-character access code"), - "description": _('Keep this code safe. You will need to enter it every time you access your study') - }, - - "securityMessage": _('Your personal information is protected by law and will be kept confidential.'), - - "error": error_uac - - }) }} +{% include "partials/uac_form.html" with context %} {{ onsButton({ 'id': 'submit_uac_btn', From af5195760d769aac6b82f5cc02c106207079857e Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 5 Aug 2024 16:31:14 +0100 Subject: [PATCH 02/18] Reverted the changes --- rh_ui/templates/partials/uac_form.html | 47 -------------------------- rh_ui/templates/start.html | 35 +++++++++++++++++-- 2 files changed, 33 insertions(+), 49 deletions(-) delete mode 100644 rh_ui/templates/partials/uac_form.html diff --git a/rh_ui/templates/partials/uac_form.html b/rh_ui/templates/partials/uac_form.html deleted file mode 100644 index 16342ef..0000000 --- a/rh_ui/templates/partials/uac_form.html +++ /dev/null @@ -1,47 +0,0 @@ -{# Create error component if error message has been flashed to use in onsAccessCode #} -{% set flashed_messages = get_flashed_messages() %} -{% set error_uac = None %} - -{{flashed_messages}} -{% if flashed_messages %} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} - {%- if 'uac_empty' in flashed_messages -%} - {%- set error_uac = { - 'id': 'uac_empty', - 'text': _('Enter an access code'), - 'field': 'uac_empty', - 'group': 'ERROR' - } -%} - {%- elif 'uac_invalid_length' in flashed_messages -%} - {%- set error_uac = { - 'id': 'uac_invalid_length', - 'text': _('Enter a 16-character access code'), - 'field': 'uac_invalid_length', - 'group': 'ERROR'} -%} - {%- elif 'uac_invalid' in flashed_messages -%} - {%- set error_uac = { - 'id': 'uac_invalid', - 'text': _('Access code not recognised. Enter the code again.'), - 'field': 'uac_invalid', - 'group': 'ERROR'} -%} - {%- endif -%} -{%- endif -%} - - -{{ onsAccessCode({ - "id": "uac", - "name": "uac", - - "label": { - "text": _("Enter your 16-character access code"), - "description": _('Keep this code safe. You will need to enter it every time you access your study') - }, - - "securityMessage": _('Your personal information is protected by law and will be kept confidential.'), - - "error": error_uac - -}) }} - - - diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index cc5d510..10e53c9 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -4,7 +4,24 @@ {% from "components/button/_macro.njk" import onsButton %} {% from "components/details/_macro.njk" import onsDetails %} -{% set page_title_value = _('Start study - ONS Surveys') %} +{# display uac error msg if exists #} + +{% set flashed_messages = get_flashed_messages() %} + +{%- if 'uac_empty' in flashed_messages -%} + {%- set error_uac = {'id': 'uac_empty', 'text': _('Enter an access code'), 'field': 'uac_empty','group': 'ERROR'} -%} + {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} +{%- elif 'uac_invalid_length' in flashed_messages -%} + {%- set error_uac = {'id': 'uac_invalid_length', 'text': _('Enter a 16-character access code'), 'field': 'uac_invalid_length','group': 'ERROR'} -%} + {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} +{%- elif 'uac_invalid' in flashed_messages -%} + {%- set error_uac = {'id': 'uac_invalid', 'text': _('Access code not recognised. Enter the code again.'), 'field': 'uac_invalid','group': 'ERROR'} -%} + {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} + +{%- else -%} + {%- set error_uac = None -%} + {%- set page_title_value = _('Start study - ONS Surveys') -%} +{%- endif -%} {% block main %} @@ -13,7 +30,21 @@ {% endif %}

{{ _('Start study') }}

-{% include "partials/uac_form.html" with context %} + +{{ onsAccessCode({ + "id": "uac", + "name": "uac", + + "label": { + "text": _("Enter your 16-character access code"), + "description": _('Keep this code safe. You will need to enter it every time you access your study') + }, + + "securityMessage": _('Your personal information is protected by law and will be kept confidential.'), + + "error": error_uac + + }) }} {{ onsButton({ 'id': 'submit_uac_btn', From 4f40f422288e4eaa51b2d3cd891c89b8bd298c4a Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 5 Aug 2024 16:36:18 +0100 Subject: [PATCH 03/18] Cleaned up the start template --- rh_ui/templates/start.html | 46 ++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index 10e53c9..2297db0 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -6,22 +6,40 @@ {# display uac error msg if exists #} +{%- set error_uac = None -%} +{%- set page_title_value = _('Start study - ONS Surveys') -%} + {% set flashed_messages = get_flashed_messages() %} -{%- if 'uac_empty' in flashed_messages -%} - {%- set error_uac = {'id': 'uac_empty', 'text': _('Enter an access code'), 'field': 'uac_empty','group': 'ERROR'} -%} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} -{%- elif 'uac_invalid_length' in flashed_messages -%} - {%- set error_uac = {'id': 'uac_invalid_length', 'text': _('Enter a 16-character access code'), 'field': 'uac_invalid_length','group': 'ERROR'} -%} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} -{%- elif 'uac_invalid' in flashed_messages -%} - {%- set error_uac = {'id': 'uac_invalid', 'text': _('Access code not recognised. Enter the code again.'), 'field': 'uac_invalid','group': 'ERROR'} -%} - {%- set page_title_value = _('Error: Start study - ONS Surveys') -%} - -{%- else -%} - {%- set error_uac = None -%} - {%- set page_title_value = _('Start study - ONS Surveys') -%} -{%- endif -%} +{% if flashed_messages %} + {% set page_title_value = _('Error: Start study - ONS Surveys') %} + + {% if 'uac_empty' in flashed_messages %} + {% set error_uac = { + 'id': 'uac_empty', + 'text': _('Enter an access code'), + 'field': 'uac_empty', + 'group': 'ERROR' + } %} + {% elif 'uac_invalid_length' in flashed_messages %} + {% set error_uac = { + 'id': 'uac_invalid_length', + 'text': _('Enter a 16-character access code'), + 'field': 'uac_invalid_length', + 'group': 'ERROR' + } %} + {% elif 'uac_invalid' in flashed_messages %} + {% set error_uac = { + 'id': 'uac_invalid', + 'text': _('Access code not recognised. Enter the code again.'), + 'field': 'uac_invalid', + 'group': 'ERROR' + } %} + {% endif %} + +{% endif %}} + + {% block main %} From 7ec59043f19ce68cf790d0ea3a2dc293e4afbd42 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 5 Aug 2024 17:15:02 +0100 Subject: [PATCH 04/18] Some more cleanup/refactoring --- rh_ui/templates/partials/messages.html | 38 ---------- .../partials/uac_error_message_list.html | 30 ++++++++ rh_ui/templates/start.html | 75 +++++++++---------- 3 files changed, 67 insertions(+), 76 deletions(-) delete mode 100644 rh_ui/templates/partials/messages.html create mode 100644 rh_ui/templates/partials/uac_error_message_list.html diff --git a/rh_ui/templates/partials/messages.html b/rh_ui/templates/partials/messages.html deleted file mode 100644 index 2527ed1..0000000 --- a/rh_ui/templates/partials/messages.html +++ /dev/null @@ -1,38 +0,0 @@ - -{%- from './components/panel/_macro.njk' import onsPanel -%} -{%- from './components/list/_macro.njk' import onsList -%} - -{%- if error_uac -%} - {%- if '/start/' in currentLanguage['url'] -%} - {%- set errorTitle = _('There is a problem with this page') -%} - {%- endif -%} -{%- endif -%} - -{%- set itemsList = [] -%} - -{%- if itemsList.append( { - 'text': error_uac['text'], - 'url': '#' + error_uac['field'], - 'variants': 'inPageLink' - } ) --%} {%- endif -%} - - - -{%- if error_uac['group']=='ERROR' -%} -{%- call - onsPanel({ - 'title': errorTitle, - 'variant': 'error' - }) --%} - -{{ - onsList({ - 'element': 'ol', - 'itemsList': itemsList - }) -}} -{%- endcall -%} -{%- endif -%} - diff --git a/rh_ui/templates/partials/uac_error_message_list.html b/rh_ui/templates/partials/uac_error_message_list.html new file mode 100644 index 0000000..957ecb5 --- /dev/null +++ b/rh_ui/templates/partials/uac_error_message_list.html @@ -0,0 +1,30 @@ +{%- from './components/panel/_macro.njk' import onsPanel -%} +{%- from './components/list/_macro.njk' import onsList -%} + +{% if error_uac %} + {% + call onsPanel({ + 'title': _('There is a problem with this page'), + 'variant': 'error' + }) + %} + + {{ + onsList({ + 'element': 'ol', + 'itemsList': [ + { + 'text': error_uac['text'], + 'url': '#' + error_uac['field'], + 'variants': 'inPageLink' + } + ] + }) + }} + + {% endcall %} +{% endif %} + + + + diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index 2297db0..9b74ac6 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -42,52 +42,51 @@ {% block main %} - -{% if error_uac %} - {% include 'partials/messages.html' with context %} -{% endif %} -

{{ _('Start study') }}

+ {% include 'partials/uac_error_message_list.html' with context %} +

{{ _('Start study') }}

-{{ onsAccessCode({ - "id": "uac", - "name": "uac", - - "label": { - "text": _("Enter your 16-character access code"), - "description": _('Keep this code safe. You will need to enter it every time you access your study') - }, + + {{ onsAccessCode({ + "id": "uac", + "name": "uac", + + "label": { + "text": _("Enter your 16-character access code"), + "description": _('Keep this code safe. You will need to enter it every time you access your study') + }, - "securityMessage": _('Your personal information is protected by law and will be kept confidential.'), + "securityMessage": _('Your personal information is protected by law and will be kept confidential.'), - "error": error_uac + "error": error_uac }) }} -{{ onsButton({ - 'id': 'submit_uac_btn', - 'text': _('Access study'), - 'classes': 'ons-u-mb-xl', - 'name': 'action[save_continue]', - "variants": 'loader' + {{ onsButton({ + 'id': 'submit_uac_btn', + 'text': _('Access study'), + 'classes': 'ons-u-mb-xl', + 'name': 'action[save_continue]', + "variants": 'loader' }) }} + -

{{ _('Where to find your access code') }}

-

{{ _('Your access code can be found in the invitation letter or email you received. - Your 16-character access code will be a combination of letters and numbers.') }}

- -{%- set further_info_content -%} -

{{ _('Telephone: +44 0808 196 1270
9am to 4:30pm Monday to Thursday
9am to 3pm Friday') }}

-

{{ _('Minicom (for the deaf and hearing impaired): 18001 +44 800 085 7376') }}

-

{{ _('Email:') }} surveyfeedback@ons.gov.uk

-{%- endset -%} - -{{ onsDetails({ - "titleTag": "h3", - "id": "details", - "title": _('Who can I contact for further information?'), - "content": further_info_content - }) }} - +

{{ _('Where to find your access code') }}

+

{{ _('Your access code can be found in the invitation letter or email you received. + Your 16-character access code will be a combination of letters and numbers.') }}

+ + {%- set further_info_content -%} +

{{ _('Telephone: +44 0808 196 1270
9am to 4:30pm Monday to Thursday
9am to 3pm Friday') }}

+

{{ _('Minicom (for the deaf and hearing impaired): 18001 +44 800 085 7376') }}

+

{{ _('Email:') }} surveyfeedback@ons.gov.uk

+ {%- endset -%} + + {{ onsDetails({ + "titleTag": "h3", + "id": "details", + "title": _('Who can I contact for further information?'), + "content": further_info_content + }) }} + {% endblock %} \ No newline at end of file From fe88de684b5482035d608c3a9b000cd60fa6dd57 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Mon, 5 Aug 2024 17:49:43 +0100 Subject: [PATCH 05/18] Added the gtag.js script --- config.py | 1 + rh_ui/templates/base.html | 22 +++++++++++++++++++++- rh_ui/templates/start.html | 4 +--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 736a8df..a865d77 100644 --- a/config.py +++ b/config.py @@ -12,6 +12,7 @@ class BaseConfig: SECRET_KEY = os.getenv("SECRET_KEY") SESSION_COOKIE_SECURE = bool(strtobool(os.getenv('SESSION_COOKIE_SECURE', 'True'))) + GOOGLE_TAG_ID = os.getenv("GOOGLE_TAG_ID") # Account service url is a link back to our service that we send to eq as part of the token ACCOUNT_SERVICE_URL = f"{DOMAIN_URL_PROTOCOL}{DOMAIN_URL}" diff --git a/rh_ui/templates/base.html b/rh_ui/templates/base.html index 60cfcdd..2e3c4f4 100644 --- a/rh_ui/templates/base.html +++ b/rh_ui/templates/base.html @@ -4,8 +4,28 @@ {%- block preHeader -%} {%- autoescape false -%} -{% set cookiesPageURL = url_for('i18n.info_pages_bp.cookies') %} +{% set g_tag_id = config.GOOGLE_TAG_ID %} + + +{% block head %} + {% if g_tag_id %} + {% set script_src_url = "https://www.googletagmanager.com/gtag/js?id=" + g_tag_id %} + + + + {% endif %} +{% endblock%} + + + +{% set cookiesPageURL = url_for('i18n.info_pages_bp.cookies') %} {%- from 'components/cookies-banner/_macro.njk' import onsCookiesBanner -%} {{ onsCookiesBanner({ 'lang': g.lang_code, diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index 9b74ac6..d92a553 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -4,8 +4,6 @@ {% from "components/button/_macro.njk" import onsButton %} {% from "components/details/_macro.njk" import onsDetails %} -{# display uac error msg if exists #} - {%- set error_uac = None -%} {%- set page_title_value = _('Start study - ONS Surveys') -%} @@ -46,7 +44,7 @@

{{ _('Start study') }}

-
+ {{ onsAccessCode({ "id": "uac", "name": "uac", From 351be771f05bb9b5dc82a3f4910d1f06da8b5354 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 10:05:49 +0100 Subject: [PATCH 06/18] Add the config variable to vulture whitelist --- whitelist.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/whitelist.py b/whitelist.py index e6ec23c..20f997c 100644 --- a/whitelist.py +++ b/whitelist.py @@ -4,20 +4,21 @@ RH_SVC_URL # unused variable (config.py:9) SECRET_KEY # unused variable (config.py:13) SESSION_COOKIE_SECURE # unused variable (config.py:14) -ACCOUNT_SERVICE_URL # unused variable (config.py:17) -LANGUAGES # unused variable (config.py:18) -EQ_URL # unused variable (config.py:19) -DEBUG # unused variable (config.py:23) -PORT # unused variable (config.py:24) -HOST # unused variable (config.py:25) -LOGGING_LEVEL # unused variable (config.py:26) -EQ_URL # unused variable (config.py:27) -SECRET_KEY # unused variable (config.py:31) -SESSION_COOKIE_SECURE # unused variable (config.py:32) -ACCOUNT_SERVICE_URL # unused variable (config.py:34) -RH_SVC_URL # unused variable (config.py:35) -DEBUG # unused variable (config.py:39) -RH_SVC_URL # unused variable (config.py:40) +GOOGLE_TAG_ID # unused variable (config.py:15) +ACCOUNT_SERVICE_URL # unused variable (config.py:18) +LANGUAGES # unused variable (config.py:19) +EQ_URL # unused variable (config.py:20) +DEBUG # unused variable (config.py:24) +PORT # unused variable (config.py:25) +HOST # unused variable (config.py:26) +LOGGING_LEVEL # unused variable (config.py:27) +EQ_URL # unused variable (config.py:28) +SECRET_KEY # unused variable (config.py:32) +SESSION_COOKIE_SECURE # unused variable (config.py:33) +ACCOUNT_SERVICE_URL # unused variable (config.py:35) +RH_SVC_URL # unused variable (config.py:36) +DEBUG # unused variable (config.py:40) +RH_SVC_URL # unused variable (config.py:41) wsgi_app # unused variable (gunicorn.conf.py:9) bind # unused variable (gunicorn.conf.py:12) worker_class # unused variable (gunicorn.conf.py:14) @@ -28,7 +29,7 @@ _.secret_key # unused attribute (rh_ui/app_setup.py:28) _.session_cookie_name # unused attribute (rh_ui/app_setup.py:29) _.session_cookie_secure # unused attribute (rh_ui/app_setup.py:30) -TestingConfig # unused class (config.py:38) +TestingConfig # unused class (config.py:39) add_language_code # unused function (rh_ui/views/i18n.py:19) pull_lang_code # unused function (rh_ui/views/i18n.py:24) cookies # unused function (rh_ui/views/info_pages.py:11) From e70e37a895cf90fb06a700b82fb2831e751383d4 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 10:12:37 +0100 Subject: [PATCH 07/18] Added the tracking label attributes --- rh_ui/templates/start.html | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index d92a553..31a49f4 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -17,21 +17,36 @@ 'id': 'uac_empty', 'text': _('Enter an access code'), 'field': 'uac_empty', - 'group': 'ERROR' + 'group': 'ERROR', + 'attributes': { + "data-ga": "error", + "data-ga-category": "UAC-error", + "data-ga-label": "uac_empty_error" + } } %} {% elif 'uac_invalid_length' in flashed_messages %} {% set error_uac = { 'id': 'uac_invalid_length', 'text': _('Enter a 16-character access code'), 'field': 'uac_invalid_length', - 'group': 'ERROR' + 'group': 'ERROR', + 'attributes': { + "data-ga": "error", + "data-ga-category": "UAC-error", + "data-ga-label": "uac_invalid_length_error" + } } %} {% elif 'uac_invalid' in flashed_messages %} {% set error_uac = { 'id': 'uac_invalid', 'text': _('Access code not recognised. Enter the code again.'), 'field': 'uac_invalid', - 'group': 'ERROR' + 'group': 'ERROR', + 'attributes': { + "data-ga": "error", + "data-ga-category": "UAC-error", + "data-ga-label": "uac_invalid_error" + } } %} {% endif %} From e4bac6eed95749df0574b22583eb6e6edb654d10 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 10:16:13 +0100 Subject: [PATCH 08/18] Removed unused attributes from the error templates --- rh_ui/templates/partials/uac_error_message_list.html | 2 +- rh_ui/templates/start.html | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/rh_ui/templates/partials/uac_error_message_list.html b/rh_ui/templates/partials/uac_error_message_list.html index 957ecb5..139852e 100644 --- a/rh_ui/templates/partials/uac_error_message_list.html +++ b/rh_ui/templates/partials/uac_error_message_list.html @@ -15,7 +15,7 @@ 'itemsList': [ { 'text': error_uac['text'], - 'url': '#' + error_uac['field'], + 'url': '#' + error_uac['id'], 'variants': 'inPageLink' } ] diff --git a/rh_ui/templates/start.html b/rh_ui/templates/start.html index 31a49f4..1876e6c 100644 --- a/rh_ui/templates/start.html +++ b/rh_ui/templates/start.html @@ -16,8 +16,6 @@ {% set error_uac = { 'id': 'uac_empty', 'text': _('Enter an access code'), - 'field': 'uac_empty', - 'group': 'ERROR', 'attributes': { "data-ga": "error", "data-ga-category": "UAC-error", @@ -28,8 +26,6 @@ {% set error_uac = { 'id': 'uac_invalid_length', 'text': _('Enter a 16-character access code'), - 'field': 'uac_invalid_length', - 'group': 'ERROR', 'attributes': { "data-ga": "error", "data-ga-category": "UAC-error", @@ -40,8 +36,6 @@ {% set error_uac = { 'id': 'uac_invalid', 'text': _('Access code not recognised. Enter the code again.'), - 'field': 'uac_invalid', - 'group': 'ERROR', 'attributes': { "data-ga": "error", "data-ga-category": "UAC-error", From fce41b36e57a9b89a2efb1d4414253c4fb28a5a9 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 10:28:11 +0100 Subject: [PATCH 09/18] Add tracking attributes to uac error pages and server error pages --- rh_ui/templates/error_pages/404.html | 22 +++++++++++------- rh_ui/templates/error_pages/error.html | 23 +++++++++++-------- .../uac_error_pages/uac-already-used.html | 8 ++++++- .../uac_error_pages/uac-inactive.html | 7 +++++- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/rh_ui/templates/error_pages/404.html b/rh_ui/templates/error_pages/404.html index daed3cd..641f574 100644 --- a/rh_ui/templates/error_pages/404.html +++ b/rh_ui/templates/error_pages/404.html @@ -4,15 +4,21 @@ {%- block main -%} -

{{ _('Page not found') }}

+

+ {{ _('Page not found') }} +

-

{{ _('If you entered a web address, check it is correct.') }}

-

{{ _('If you pasted the web address, check you copied the whole address.') }}

+

{{ _('If you entered a web address, check it is correct.') }}

+

{{ _('If you pasted the web address, check you copied the whole address.') }}

-{%- autoescape false -%} -{% set contact_us_link = _('https://www.ons.gov.uk/aboutus/contactus/surveyenquiries') %} -

{{ _('If the web address is correct or you selected a link or button, %(open)scontact us%(close)s for more help.', open='' - % contact_us_link, close='')|safe }}

-{%- endautoescape -%} + {%- autoescape false -%} + {% set contact_us_link = _('https://www.ons.gov.uk/aboutus/contactus/surveyenquiries') %} +

{{ _('If the web address is correct or you selected a link or button, %(open)scontact us%(close)s for more help.', open='' + % contact_us_link, close='')|safe }}

+ {%- endautoescape -%} {%- endblock -%} diff --git a/rh_ui/templates/error_pages/error.html b/rh_ui/templates/error_pages/error.html index 22d207d..11a612b 100644 --- a/rh_ui/templates/error_pages/error.html +++ b/rh_ui/templates/error_pages/error.html @@ -3,16 +3,21 @@ {% set page_title_value = _('ONS Surveys') %} {%- block main -%} + +

+ {{ _('Sorry, something went wrong') }} +

-

- {{ _('Sorry, something went wrong') }} -

+

{{ _('We are experiencing some technical problems.') }}

-

{{ _('We are experiencing some technical problems.') }}

- -{%- autoescape false -%} -{% set contact_us_link = _('https://www.ons.gov.uk/aboutus/contactus/surveyenquiries') %} -

{{ _('Please try again later, or %(open)scontact us%(close)s if the problem continues.', open='' % contact_us_link, close='')|safe }}

-{%- endautoescape -%} + {%- autoescape false -%} + {% set contact_us_link = _('https://www.ons.gov.uk/aboutus/contactus/surveyenquiries') %} +

{{ _('Please try again later, or %(open)scontact us%(close)s if the problem continues.', + open='' % contact_us_link, close='')|safe }}

+ {%- endautoescape -%} {%- endblock main -%} diff --git a/rh_ui/templates/uac_error_pages/uac-already-used.html b/rh_ui/templates/uac_error_pages/uac-already-used.html index 3cfef5b..fe920a5 100644 --- a/rh_ui/templates/uac_error_pages/uac-already-used.html +++ b/rh_ui/templates/uac_error_pages/uac-already-used.html @@ -18,7 +18,13 @@ {%- block main -%} -

{{ _('This access code has already been used') }}

+

+ {{ _('This access code has already been used') }} +

{{ _('Someone has already submitted a response using this access code.') }}

diff --git a/rh_ui/templates/uac_error_pages/uac-inactive.html b/rh_ui/templates/uac_error_pages/uac-inactive.html index d7c9d97..c825de6 100644 --- a/rh_ui/templates/uac_error_pages/uac-inactive.html +++ b/rh_ui/templates/uac_error_pages/uac-inactive.html @@ -17,7 +17,12 @@ {%- endblock -%} {%- block main -%} -

+

{{ _('This questionnaire has now closed') }}

+ {%- endblock main -%} \ No newline at end of file From 5b5a7638f344903343fd25a354ebbf4c2056926f Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 14:07:37 +0100 Subject: [PATCH 10/18] Updated the CSP whitelist --- rh_ui/security.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rh_ui/security.py b/rh_ui/security.py index 469fb07..24c609e 100644 --- a/rh_ui/security.py +++ b/rh_ui/security.py @@ -12,6 +12,7 @@ 'script-src': [ "'self'", 'https://cdn.ons.gov.uk', + 'https://www.googletagmanager.com', ], 'connect-src': [ "'self'", From e690aac8eefb046c7450af48b4d3056b63086e6c Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 16:02:41 +0100 Subject: [PATCH 11/18] Mock value for gtag_id, reformat base.html --- config.py | 2 +- rh_ui/templates/base.html | 52 +++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/config.py b/config.py index a865d77..89f55ee 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,7 @@ class BaseConfig: SECRET_KEY = os.getenv("SECRET_KEY") SESSION_COOKIE_SECURE = bool(strtobool(os.getenv('SESSION_COOKIE_SECURE', 'True'))) - GOOGLE_TAG_ID = os.getenv("GOOGLE_TAG_ID") + GOOGLE_TAG_ID = os.getenv("GOOGLE_TAG_ID", "G-XXXXXXXXXX") # Account service url is a link back to our service that we send to eq as part of the token ACCOUNT_SERVICE_URL = f"{DOMAIN_URL_PROTOCOL}{DOMAIN_URL}" diff --git a/rh_ui/templates/base.html b/rh_ui/templates/base.html index 2e3c4f4..1bd13aa 100644 --- a/rh_ui/templates/base.html +++ b/rh_ui/templates/base.html @@ -1,45 +1,41 @@ {%- extends 'layout/_template.njk' -%} -{%- block preHeader -%} -{%- autoescape false -%} - -{% set g_tag_id = config.GOOGLE_TAG_ID %} - - {% block head %} + {% set g_tag_id = config.GOOGLE_TAG_ID %} {% if g_tag_id %} {% set script_src_url = "https://www.googletagmanager.com/gtag/js?id=" + g_tag_id %} + - + {% endif %} {% endblock%} - - -{% set cookiesPageURL = url_for('i18n.info_pages_bp.cookies') %} -{%- from 'components/cookies-banner/_macro.njk' import onsCookiesBanner -%} -{{ onsCookiesBanner({ - 'lang': g.lang_code, - 'statementTitle': _('Cookies'), - 'serviceName': '', - 'settingsLinkTextURL': cookiesPageURL, - 'statementText': _("To collect information about how you use this website, we use%(open_cookies_link)s cookies.%(close_link)s
- This information helps us improve our services and make sure that the website works as well as possible.", - open_cookies_link='' % cookiesPageURL, close_link=''), - 'preferencesText': _("You can %(open_cookies_link)s change your cookie preferences%(close_link)s at any time.",open_cookies_link='' % cookiesPageURL, close_link='') - }) }} -{% endautoescape %} +{%- block preHeader -%} + {%- autoescape false -%} + {% set cookiesPageURL = url_for('i18n.info_pages_bp.cookies') %} + {%- from 'components/cookies-banner/_macro.njk' import onsCookiesBanner -%} + {{ onsCookiesBanner({ + 'lang': g.lang_code, + 'statementTitle': _('Cookies'), + 'serviceName': '', + 'settingsLinkTextURL': cookiesPageURL, + 'statementText': _("To collect information about how you use this website, we use%(open_cookies_link)s cookies.%(close_link)s
+ This information helps us improve our services and make sure that the website works as well as possible.", + open_cookies_link='' % cookiesPageURL, close_link=''), + 'preferencesText': _("You can %(open_cookies_link)s change your cookie preferences%(close_link)s at any time.",open_cookies_link='' % cookiesPageURL, close_link='') + }) }} + {% endautoescape %} {%- endblock -%} + {%- set language = { 'languages': [ { @@ -57,6 +53,7 @@ ] }-%} + {%- set footer_content = { 'newTabWarning': _('The following links open in a new tab'), 'crest': true, @@ -100,6 +97,7 @@ } }-%} + {%- set pageConfig = { 'title': page_title_value, 'header': { @@ -113,9 +111,3 @@ 'cspNonce': csp_nonce(), 'meta' : {} } -%} - - -{%- block bodyStart -%} - - -{%- endblock -%} \ No newline at end of file From 15ced91f741a9663bcae605c5850a3b803110600 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 16:54:35 +0100 Subject: [PATCH 12/18] Added the tracking cookies check with a comment --- rh_ui/templates/base.html | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/rh_ui/templates/base.html b/rh_ui/templates/base.html index 1bd13aa..8bc5020 100644 --- a/rh_ui/templates/base.html +++ b/rh_ui/templates/base.html @@ -9,10 +9,19 @@ {% endif %} {% endblock%} From 459c3f52ff68e53f41a7c6274a083b989eab3501 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Tue, 6 Aug 2024 16:55:38 +0100 Subject: [PATCH 13/18] Moved the gtagid mock value to dev config --- config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 89f55ee..e433bff 100644 --- a/config.py +++ b/config.py @@ -12,7 +12,7 @@ class BaseConfig: SECRET_KEY = os.getenv("SECRET_KEY") SESSION_COOKIE_SECURE = bool(strtobool(os.getenv('SESSION_COOKIE_SECURE', 'True'))) - GOOGLE_TAG_ID = os.getenv("GOOGLE_TAG_ID", "G-XXXXXXXXXX") + GOOGLE_TAG_ID = os.getenv("GOOGLE_TAG_ID") # Account service url is a link back to our service that we send to eq as part of the token ACCOUNT_SERVICE_URL = f"{DOMAIN_URL_PROTOCOL}{DOMAIN_URL}" @@ -31,6 +31,7 @@ class DevelopmentConfig(BaseConfig): SECRET_KEY = os.getenv('SECRET_KEY', b'_5#y2L"F4Q8z\n\xec]/') SESSION_COOKIE_SECURE = bool(strtobool(os.getenv('SESSION_COOKIE_SECURE', 'False'))) + GOOGLE_TAG_ID = os.getenv("GOOGLE_TAG_ID", "G-XXXXXXXXXX") ACCOUNT_SERVICE_URL = f"{DOMAIN_URL_PROTOCOL}{DOMAIN_URL}" RH_SVC_URL = os.getenv("RH_SVC_URL", "http://localhost:8071") From 57a7810edd5285602a14cbff8007e97a5d49cb09 Mon Sep 17 00:00:00 2001 From: Kacper Prywata Date: Wed, 7 Aug 2024 10:59:10 +0100 Subject: [PATCH 14/18] Add nonce and whitelist to make CSP happy --- rh_ui/security.py | 1 + rh_ui/templates/base.html | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rh_ui/security.py b/rh_ui/security.py index 24c609e..7761a3e 100644 --- a/rh_ui/security.py +++ b/rh_ui/security.py @@ -17,6 +17,7 @@ 'connect-src': [ "'self'", 'https://cdn.ons.gov.uk', + 'https://*.google-analytics.com/' ], 'img-src': [ "'self'", diff --git a/rh_ui/templates/base.html b/rh_ui/templates/base.html index 8bc5020..d75f358 100644 --- a/rh_ui/templates/base.html +++ b/rh_ui/templates/base.html @@ -7,8 +7,8 @@ {% set script_src_url = "https://www.googletagmanager.com/gtag/js?id=" + g_tag_id %} - - + -