mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 06:28:25 -04:00
Merge pull request #1549 from alphagov/show-reply-address
Show email reply to address if one’s been selected
This commit is contained in:
@@ -323,7 +323,8 @@ def send_test_step(service_id, template_id, step_index):
|
|||||||
template_id=template_id,
|
template_id=template_id,
|
||||||
filetype='png',
|
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(
|
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()))
|
remaining_messages = (current_service['message_limit'] - sum(stat['requested'] for stat in statistics.values()))
|
||||||
|
|
||||||
contents = s3download(service_id, upload_id)
|
contents = s3download(service_id, upload_id)
|
||||||
|
|
||||||
template = get_template(
|
template = get_template(
|
||||||
service_api_client.get_service_template(
|
service_api_client.get_service_template(
|
||||||
service_id,
|
service_id,
|
||||||
@@ -462,7 +462,8 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False):
|
|||||||
template_type=template_type,
|
template_type=template_type,
|
||||||
upload_id=upload_id,
|
upload_id=upload_id,
|
||||||
filetype='png',
|
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(
|
recipients = RecipientCSV(
|
||||||
contents,
|
contents,
|
||||||
@@ -726,7 +727,8 @@ def _check_notification(service_id, template_id, exception=None):
|
|||||||
template = get_template(
|
template = get_template(
|
||||||
db_template,
|
db_template,
|
||||||
current_service,
|
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
|
# go back to start of process
|
||||||
@@ -805,3 +807,10 @@ def send_notification(service_id, template_id):
|
|||||||
notification_id=noti['id'],
|
notification_id=noti['id'],
|
||||||
help=request.args.get('help')
|
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']
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ def get_template(
|
|||||||
letter_preview_url=None,
|
letter_preview_url=None,
|
||||||
page_count=1,
|
page_count=1,
|
||||||
redact_missing_personalisation=False,
|
redact_missing_personalisation=False,
|
||||||
|
email_reply_to=None,
|
||||||
):
|
):
|
||||||
if 'email' == template['template_type']:
|
if 'email' == template['template_type']:
|
||||||
return EmailPreviewTemplate(
|
return EmailPreviewTemplate(
|
||||||
@@ -281,6 +282,7 @@ def get_template(
|
|||||||
expanded=expand_emails,
|
expanded=expand_emails,
|
||||||
show_recipient=show_recipient,
|
show_recipient=show_recipient,
|
||||||
redact_missing_personalisation=redact_missing_personalisation,
|
redact_missing_personalisation=redact_missing_personalisation,
|
||||||
|
reply_to=email_reply_to,
|
||||||
)
|
)
|
||||||
if 'sms' == template['template_type']:
|
if 'sms' == template['template_type']:
|
||||||
return SMSPreviewTemplate(
|
return SMSPreviewTemplate(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from notifications_utils.recipients import RecipientCSV
|
|||||||
|
|
||||||
from tests import validate_route_permission, validate_route_permission_with_client
|
from tests import validate_route_permission, validate_route_permission_with_client
|
||||||
from tests.conftest import (
|
from tests.conftest import (
|
||||||
|
fake_uuid,
|
||||||
mock_get_service_template,
|
mock_get_service_template,
|
||||||
mock_get_service_template_with_placeholders,
|
mock_get_service_template_with_placeholders,
|
||||||
mock_get_service_letter_template,
|
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) == (
|
assert normalize_spaces(page.select('.banner-dangerous p')[0].text) == (
|
||||||
'In trial mode you can only send to yourself and members of your team'
|
'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
|
||||||
|
|||||||
Reference in New Issue
Block a user