diff --git a/app/main/views/tour.py b/app/main/views/tour.py index c17c51bf8..4a29a667a 100644 --- a/app/main/views/tour.py +++ b/app/main/views/tour.py @@ -49,6 +49,11 @@ def tour_step(service_id, template_id, step_index): if db_template['template_type'] != 'sms': abort(404) + if 'placeholders' not in session: + return redirect(url_for( + '.begin_tour', service_id=current_service.id, template_id=template_id + )) + template = get_template( db_template, current_service, @@ -119,6 +124,11 @@ def check_tour_notification(service_id, template_id): show_recipient=True, ) + if 'placeholders' not in session: + return redirect(url_for( + '.begin_tour', service_id=current_service.id, template_id=template_id + )) + placeholders = fields_to_fill_in(template, prefill_current_user=True) if not all_placeholders_in_session(template.placeholders): diff --git a/tests/app/main/views/test_tour.py b/tests/app/main/views/test_tour.py index 93ccd951d..9375593b4 100644 --- a/tests/app/main/views/test_tour.py +++ b/tests/app/main/views/test_tour.py @@ -234,6 +234,30 @@ def test_should_403_if_user_does_not_have_send_permissions_for_tour_step( ) +def test_tour_step_redirects_to_tour_start_if_placeholders_doesnt_exist_in_session( + client_request, + mock_get_service_template_with_multiple_placeholders, + service_one, + fake_uuid, +): + with client_request.session_transaction() as session: + assert 'placeholders' not in session + + client_request.get( + 'main.tour_step', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + step_index=1, + _expected_status=302, + _expected_redirect=url_for( + 'main.begin_tour', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _external=True, + ), + ) + + def test_back_link_from_first_get_tour_step_points_to_tour_start( client_request, mock_get_service_template_with_multiple_placeholders, @@ -518,6 +542,30 @@ def test_back_link_from_check_tour_notification_points_to_last_tour_step( ) +def test_check_tour_notification_redirects_to_tour_start_if_placeholders_doesnt_exist_in_session( + client_request, + mock_get_service_template_with_multiple_placeholders, + service_one, + fake_uuid, +): + with client_request.session_transaction() as session: + assert 'placeholders' not in session + + client_request.get( + 'main.check_tour_notification', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + step_index=1, + _expected_status=302, + _expected_redirect=url_for( + 'main.begin_tour', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _external=True, + ), + ) + + def test_check_tour_notification_redirects_to_first_step_if_not_all_placeholders_in_session( client_request, mock_get_service_template_with_multiple_placeholders,