diff --git a/app/templates/components/current-service-link.html b/app/templates/components/service-link.html
similarity index 58%
rename from app/templates/components/current-service-link.html
rename to app/templates/components/service-link.html
index 807ba8ac4..c4f128877 100644
--- a/app/templates/components/current-service-link.html
+++ b/app/templates/components/service-link.html
@@ -1,6 +1,6 @@
-{% macro current_service_link(endpoint, link_text) %}
- {% if current_service %}
- {{ link_text }}
+{% macro service_link(service, endpoint, link_text) %}
+ {% if service %}
+ {{ link_text }}
{% else %}
{{ link_text|capitalize }}
{% endif %}
diff --git a/app/templates/views/guidance/branding-and-customisation.html b/app/templates/views/guidance/branding-and-customisation.html
index cc68bcb75..44d8c1072 100644
--- a/app/templates/views/guidance/branding-and-customisation.html
+++ b/app/templates/views/guidance/branding-and-customisation.html
@@ -1,5 +1,5 @@
{% extends "content_template.html" %}
-{% from "components/current-service-link.html" import current_service_link %}
+{% from "components/service-link.html" import service_link %}
{% block per_page_title %}
Branding and customisation
@@ -25,7 +25,7 @@
To change your email branding:
- - Go to the Email settings section of the {{ current_service_link('main.service_settings', 'settings') }} page.
+ - Go to the Email settings section of the {{ service_link(current_service, 'main.service_settings', 'settings') }} page.
- Select Change on the Email branding row.
@@ -36,7 +36,7 @@
To add a reply-to email address:
- - Go to the Email settings section of the {{ current_service_link('main.service_settings', 'settings') }} page.
+ - Go to the Email settings section of the {{ service_link(current_service, 'main.service_settings', 'settings') }} page.
- Select Manage on the Reply-to email addresses row.
- Select Add reply-to address.
@@ -48,7 +48,7 @@
To change the text message sender from the default of ‘GOVUK’:
- - Go to the Text message settings section of the {{ current_service_link('main.service_settings', 'settings') }} page.
+ - Go to the Text message settings section of the {{ service_link(current_service, 'main.service_settings', 'settings') }} page.
- Select Manage on the Text message senders row.
- Select Change or Add text message sender.
@@ -60,7 +60,7 @@
To add a logo to your letters:
- - Go to the Letter settings section of the {{ current_service_link('main.service_settings', 'settings') }} page.
+ - Go to the Letter settings section of the {{ service_link(current_service, 'main.service_settings', 'settings') }} page.
- Select Change on the Letter branding row.
diff --git a/app/templates/views/guidance/create-and-send-messages.html b/app/templates/views/guidance/create-and-send-messages.html
index fa905b33d..5f94387d7 100644
--- a/app/templates/views/guidance/create-and-send-messages.html
+++ b/app/templates/views/guidance/create-and-send-messages.html
@@ -1,5 +1,5 @@
{% extends "content_template.html" %}
-{% from "components/current-service-link.html" import current_service_link %}
+{% from "components/service-link.html" import service_link %}
{% block per_page_title %}
Send messages
@@ -15,7 +15,7 @@
To send a batch of messages at once:
- - Go to the {{ current_service_link('main.choose_template', 'templates') }} page and choose an existing template.
+ - Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page and choose an existing template.
- Select Send.
- If you’re sending emails, select Upload a list of email addresses. If you’re sending text messages, select Upload a list of phone numbers. If you’re sending letters, select Upload a list of addresses.
diff --git a/app/templates/views/guidance/edit-and-format-messages.html b/app/templates/views/guidance/edit-and-format-messages.html
index a80655a81..eb74e2e7d 100644
--- a/app/templates/views/guidance/edit-and-format-messages.html
+++ b/app/templates/views/guidance/edit-and-format-messages.html
@@ -1,5 +1,5 @@
{% extends "content_template.html" %}
-{% from "components/current-service-link.html" import current_service_link %}
+{% from "components/service-link.html" import service_link %}
{% block per_page_title %}
Edit and format messages
@@ -22,7 +22,7 @@
You can see a list of formatting instructions on the edit template page:
- - Go to the {{ current_service_link('main.choose_template', 'templates') }} page.
+ - Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page.
- Add a new template or choose an existing template and select Edit.
@@ -61,7 +61,7 @@
To add a placeholder to the template:
- - Go to the {{ current_service_link('main.choose_template', 'templates') }} page.
+ - Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page.
- Add a new template or choose an existing template and select Edit.
- Add a placeholder using double brackets. For example: Hello ((first name)), your reference is ((ref number)).
- Select Save.
@@ -81,7 +81,7 @@
To add optional content to your emails and text messages:
- - Go to the {{ current_service_link('main.choose_template', 'templates') }} page.
+ - Go to the {{ service_link(current_service, 'main.choose_template', 'templates') }} page.
- Add a new template or choose an existing template and select Edit.
- Use double brackets and ?? to define optional content. For example, if you only want to show something to people who are under 18: ((under18??Please get your application signed by a parent or guardian.))
- Select Save.
diff --git a/app/templates/views/guidance/upload-a-letter.html b/app/templates/views/guidance/upload-a-letter.html
index 42f33d765..619b2a5c3 100644
--- a/app/templates/views/guidance/upload-a-letter.html
+++ b/app/templates/views/guidance/upload-a-letter.html
@@ -1,5 +1,5 @@
{% extends "content_template.html" %}
-{% from "components/current-service-link.html" import current_service_link %}
+{% from "components/service-link.html" import service_link %}
{% block per_page_title %}
Upload a letter
@@ -14,7 +14,7 @@
To upload and send a letter from a PDF file:
- - Go to the {{ current_service_link('main.uploads', 'uploads') }} page.
+ - Go to the {{ service_link(current_service, 'main.uploads', 'uploads') }} page.
- Select Upload a letter.
- Select Choose file.
diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py
index 3b0de3657..bd4cea5a4 100644
--- a/tests/app/main/views/test_index.py
+++ b/tests/app/main/views/test_index.py
@@ -5,7 +5,7 @@ from bs4 import BeautifulSoup
from flask import url_for
from app.main.forms import FieldWithNoneOption
-from tests.conftest import normalize_spaces, sample_uuid
+from tests.conftest import SERVICE_ONE_ID, normalize_spaces, sample_uuid
def test_non_logged_in_user_can_see_homepage(
@@ -109,6 +109,34 @@ def test_static_pages(
request()
+def test_guidance_pages_link_to_service_pages_when_signed_in(
+ client_request,
+):
+ request = partial(client_request.get, 'main.edit_and_format_messages')
+ selector = '.list-number li a'
+
+ # Check the page loads when user is signed in
+ page = request()
+ assert page.select_one(selector)['href'] == url_for(
+ 'main.choose_template',
+ service_id=SERVICE_ONE_ID,
+ )
+
+ # Check it still works when they don’t have a recent service
+ with client_request.session_transaction() as session:
+ session['service_id'] = None
+ page = request()
+ assert not page.select_one(selector)
+
+ # Check it still works when they sign out
+ client_request.logout()
+ with client_request.session_transaction() as session:
+ session['service_id'] = None
+ session['user_id'] = None
+ page = request()
+ assert not page.select_one(selector)
+
+
@pytest.mark.parametrize('view, expected_view', [
('information_risk_management', 'security'),
('old_integration_testing', 'integration_testing'),