Merge pull request #1549 from alphagov/show-reply-address

Show email reply to address if one’s been selected
This commit is contained in:
Chris Hill-Scott
2017-10-18 12:33:52 +01:00
committed by GitHub
3 changed files with 67 additions and 4 deletions

View File

@@ -323,7 +323,8 @@ def send_test_step(service_id, template_id, step_index):
template_id=template_id,
filetype='png',
),
page_count=session['send_test_letter_page_count']
page_count=session['send_test_letter_page_count'],
email_reply_to=get_email_reply_to_address_from_session(service_id),
)
placeholders = fields_to_fill_in(
@@ -448,7 +449,6 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False):
remaining_messages = (current_service['message_limit'] - sum(stat['requested'] for stat in statistics.values()))
contents = s3download(service_id, upload_id)
template = get_template(
service_api_client.get_service_template(
service_id,
@@ -462,7 +462,8 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False):
template_type=template_type,
upload_id=upload_id,
filetype='png',
) if not letters_as_pdf else None
) if not letters_as_pdf else None,
email_reply_to=get_email_reply_to_address_from_session(service_id),
)
recipients = RecipientCSV(
contents,
@@ -726,7 +727,8 @@ def _check_notification(service_id, template_id, exception=None):
template = get_template(
db_template,
current_service,
show_recipient=True
show_recipient=True,
email_reply_to=get_email_reply_to_address_from_session(service_id),
)
# go back to start of process
@@ -805,3 +807,10 @@ def send_notification(service_id, template_id):
notification_id=noti['id'],
help=request.args.get('help')
))
def get_email_reply_to_address_from_session(service_id):
if session.get('sender_id'):
return service_api_client.get_reply_to_email_address(
service_id, session['sender_id']
)['email_address']

View File

@@ -272,6 +272,7 @@ def get_template(
letter_preview_url=None,
page_count=1,
redact_missing_personalisation=False,
email_reply_to=None,
):
if 'email' == template['template_type']:
return EmailPreviewTemplate(
@@ -281,6 +282,7 @@ def get_template(
expanded=expand_emails,
show_recipient=show_recipient,
redact_missing_personalisation=redact_missing_personalisation,
reply_to=email_reply_to,
)
if 'sms' == template['template_type']:
return SMSPreviewTemplate(

View File

@@ -16,6 +16,7 @@ from notifications_utils.recipients import RecipientCSV
from tests import validate_route_permission, validate_route_permission_with_client
from tests.conftest import (
fake_uuid,
mock_get_service_template,
mock_get_service_template_with_placeholders,
mock_get_service_letter_template,
@@ -2233,3 +2234,54 @@ def test_send_notification_shows_email_error_in_trial_mode(
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
'In trial mode you can only send to yourself and members of your team'
)
@pytest.mark.parametrize('endpoint, extra_args', [
('main.check_messages', {'template_type': 'email', 'upload_id': fake_uuid()}),
('main.send_one_off_step', {'template_id': fake_uuid(), 'step_index': 0}),
])
@pytest.mark.parametrize('reply_to_address', [
None,
fake_uuid(),
])
def test_reply_to_is_previewed_if_chosen(
client_request,
mocker,
mock_get_service_email_template,
mock_s3_download,
mock_get_users_by_service,
mock_get_detailed_service_for_today,
get_default_reply_to_email_address,
endpoint,
extra_args,
reply_to_address,
):
mocker.patch('app.main.views.send.s3download', return_value="""
email_address,date,thing
notify@digital.cabinet-office.gov.uk,foo,bar
""")
with client_request.session_transaction() as session:
session['recipient'] = 'notify@digital.cabinet-office.gov.uk'
session['placeholders'] = {}
session['upload_data'] = {
'original_file_name': 'example.csv',
'template_id': fake_uuid(),
'notification_count': 1,
'valid': True
}
session['sender_id'] = reply_to_address
page = client_request.get(
endpoint,
service_id=SERVICE_ONE_ID,
**extra_args
)
email_meta = page.select_one('.email-message-meta').text
if reply_to_address:
assert 'test@example.com' in email_meta
else:
assert 'test@example.com' not in email_meta