diff --git a/app/main/forms.py b/app/main/forms.py index 96ff11234..eeb90fe0f 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1252,6 +1252,10 @@ class LetterAddressForm(StripWhitespaceForm): raise ValidationError( f'Last line of the address must be a UK postcode or another country' ) + if address.international: + raise ValidationError( + f'You do not have permission to send letters to other countries' + ) raise ValidationError( f'Last line of the address must be a real UK postcode' ) diff --git a/app/templates/views/check/row-errors.html b/app/templates/views/check/row-errors.html index b150c7704..3c8365bc6 100644 --- a/app/templates/views/check/row-errors.html +++ b/app/templates/views/check/row-errors.html @@ -79,6 +79,8 @@ {% elif not item.as_postal_address.has_valid_last_line %} {% if item.as_postal_address.allow_international_letters %} Last line of the address must be a UK postcode or another country + {% elif item.as_postal_address.international %} + You do not have permission to send letters to other countries {% else %} Last line of the address must be a real UK postcode {% endif %} diff --git a/app/utils.py b/app/utils.py index add05ad91..3f2eabc02 100644 --- a/app/utils.py +++ b/app/utils.py @@ -703,6 +703,15 @@ LETTER_VALIDATION_MESSAGES = { 'Validation failed because the last line of the address is not a real UK postcode.' ), }, + 'cant-send-international-letters': { + 'title': 'There’s a problem with the address for this letter', + 'detail': ( + 'You do not have permission to send letters to other countries.' + ), + 'summary': ( + 'Validation failed because your service cannot send letters to other countries.' + ), + }, 'not-a-real-uk-postcode-or-country': { 'title': 'There’s a problem with the address for this letter', 'detail': ( diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index c0f77f584..f3c04e9df 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -637,7 +637,7 @@ def test_upload_csv_file_with_bad_postal_address_shows_check_page_with_errors( '3 Last line of the address must be a real UK postcode', 'Firstname Lastname 123 Example St. SW!A !AA', - '4 Last line of the address must be a real UK postcode', + '4 You do not have permission to send letters to other countries', 'Firstname Lastname 123 Example St. France', '5 Address must be at least 3 lines long', @@ -2603,6 +2603,11 @@ def test_send_one_off_letter_address_populates_address_fields_in_session( [], 'Last line of the address must be a real UK postcode', ), + ( + '\n'.join(['a', 'b', 'c', 'd', 'e', 'france']), + [], + 'You do not have permission to send letters to other countries', + ), ( '\n'.join(['a', 'b', 'c', 'd', 'e', 'f', 'g']), ['international_letters'], diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index 776143fa6..11cf42645 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -511,6 +511,17 @@ def test_get_letter_validation_error_for_unknown_error(): 'Validation failed because the last line of the address is not a real UK postcode.' ), ), + ( + 'cant-send-international-letters', + None, + 'There’s a problem with the address for this letter', + ( + 'You do not have permission to send letters to other countries.' + ), + ( + 'Validation failed because your service cannot send letters to other countries.' + ), + ), ( 'not-a-real-uk-postcode-or-country', None,