mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 05:53:13 -04:00
Updated send_to_providers.py to use the notification email_reply_to address if there is one present otherwise it uses the service email_reply_to so now users can choose a per notification email_reply_to address.
This commit is contained in:
@@ -8,7 +8,7 @@ from notifications_utils.recipients import (
|
|||||||
from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTemplate, SMSMessageTemplate
|
from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTemplate, SMSMessageTemplate
|
||||||
|
|
||||||
from app import clients, statsd_client, create_uuid
|
from app import clients, statsd_client, create_uuid
|
||||||
from app.dao.notifications_dao import dao_update_notification
|
from app.dao.notifications_dao import dao_update_notification, dao_get_notification_email_reply_for_notification
|
||||||
from app.dao.provider_details_dao import (
|
from app.dao.provider_details_dao import (
|
||||||
get_provider_details_by_notification_type,
|
get_provider_details_by_notification_type,
|
||||||
dao_toggle_sms_provider
|
dao_toggle_sms_provider
|
||||||
@@ -110,13 +110,18 @@ def send_email_to_provider(notification):
|
|||||||
from_address = '"{}" <{}@{}>'.format(service.name, service.email_from,
|
from_address = '"{}" <{}@{}>'.format(service.name, service.email_from,
|
||||||
current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||||
|
|
||||||
|
email_reply_to = dao_get_notification_email_reply_for_notification(notification.id)
|
||||||
|
|
||||||
|
if not email_reply_to:
|
||||||
|
email_reply_to = service.get_default_reply_to_email_address()
|
||||||
|
|
||||||
reference = provider.send_email(
|
reference = provider.send_email(
|
||||||
from_address,
|
from_address,
|
||||||
notification.to,
|
notification.to,
|
||||||
plain_text_email.subject,
|
plain_text_email.subject,
|
||||||
body=str(plain_text_email),
|
body=str(plain_text_email),
|
||||||
html_body=str(html_email),
|
html_body=str(html_email),
|
||||||
reply_to_address=service.get_default_reply_to_email_address(),
|
reply_to_address=email_reply_to,
|
||||||
)
|
)
|
||||||
notification.reference = reference
|
notification.reference = reference
|
||||||
update_notification(notification, provider)
|
update_notification(notification, provider)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from app.models import (
|
|||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
ServiceInboundApi,
|
ServiceInboundApi,
|
||||||
ServiceEmailReplyTo,
|
ServiceEmailReplyTo,
|
||||||
ServiceLetterContact, ServiceSmsSender)
|
ServiceLetterContact, ServiceSmsSender, NotificationEmailReplyTo)
|
||||||
from app.dao.users_dao import save_model_user
|
from app.dao.users_dao import save_model_user
|
||||||
from app.dao.notifications_dao import dao_create_notification, dao_created_scheduled_notification
|
from app.dao.notifications_dao import dao_create_notification, dao_created_scheduled_notification
|
||||||
from app.dao.templates_dao import dao_create_template
|
from app.dao.templates_dao import dao_create_template
|
||||||
@@ -384,3 +384,21 @@ def create_letter_contact(
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return letter_content
|
return letter_content
|
||||||
|
|
||||||
|
|
||||||
|
def create_reply_to_email_for_notification(
|
||||||
|
notification_id,
|
||||||
|
service,
|
||||||
|
email_address,
|
||||||
|
is_default=True
|
||||||
|
):
|
||||||
|
reply_to = create_reply_to_email(service, email_address, is_default)
|
||||||
|
|
||||||
|
notification_email_reply_to = NotificationEmailReplyTo(
|
||||||
|
notification_id=str(notification_id),
|
||||||
|
service_email_reply_to_id=str(reply_to.id)
|
||||||
|
)
|
||||||
|
db.session.add(notification_email_reply_to)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return reply_to
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from unittest.mock import ANY, call
|
|||||||
import pytest
|
import pytest
|
||||||
from notifications_utils.recipients import validate_and_format_phone_number
|
from notifications_utils.recipients import validate_and_format_phone_number
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from requests_mock import mock
|
||||||
|
|
||||||
import app
|
import app
|
||||||
from app import mmg_client, firetext_client
|
from app import mmg_client, firetext_client
|
||||||
@@ -21,10 +22,10 @@ from app.models import (
|
|||||||
BRANDING_ORG,
|
BRANDING_ORG,
|
||||||
BRANDING_GOVUK,
|
BRANDING_GOVUK,
|
||||||
BRANDING_BOTH,
|
BRANDING_BOTH,
|
||||||
BRANDING_ORG_BANNER)
|
BRANDING_ORG_BANNER, NotificationEmailReplyTo)
|
||||||
|
|
||||||
from tests.app.db import create_service, create_template, create_notification, create_inbound_number, \
|
from tests.app.db import create_service, create_template, create_notification, create_inbound_number, \
|
||||||
create_reply_to_email
|
create_reply_to_email, create_reply_to_email_for_notification
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_highest_priority_active_provider(restore_provider_details):
|
def test_should_return_highest_priority_active_provider(restore_provider_details):
|
||||||
@@ -697,3 +698,65 @@ def test_should_use_inbound_number_as_sender_if_set(
|
|||||||
reference=str(notification.id),
|
reference=str(notification.id),
|
||||||
sender=inbound_number.number
|
sender=inbound_number.number
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_email_to_provider_get_linked_email_reply_to_default_is_false(
|
||||||
|
sample_service,
|
||||||
|
sample_email_template,
|
||||||
|
mocker):
|
||||||
|
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||||
|
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||||
|
|
||||||
|
db_notification = create_notification(template=sample_email_template)
|
||||||
|
create_reply_to_email(service=sample_service, email_address='foo@bar.com')
|
||||||
|
|
||||||
|
reply_to = create_reply_to_email_for_notification(
|
||||||
|
db_notification.id,
|
||||||
|
sample_service,
|
||||||
|
"test@test.com",
|
||||||
|
is_default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
send_to_providers.send_email_to_provider(
|
||||||
|
db_notification,
|
||||||
|
)
|
||||||
|
|
||||||
|
app.aws_ses_client.send_email.assert_called_once_with(
|
||||||
|
ANY,
|
||||||
|
ANY,
|
||||||
|
ANY,
|
||||||
|
body=ANY,
|
||||||
|
html_body=ANY,
|
||||||
|
reply_to_address=reply_to.email_address
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_email_to_provider_get_linked_email_reply_to_create_service_email_after_notification_mapping(
|
||||||
|
sample_service,
|
||||||
|
sample_email_template,
|
||||||
|
mocker):
|
||||||
|
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||||
|
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||||
|
|
||||||
|
db_notification = create_notification(template=sample_email_template)
|
||||||
|
|
||||||
|
reply_to = create_reply_to_email_for_notification(
|
||||||
|
db_notification.id,
|
||||||
|
sample_service,
|
||||||
|
"test@test.com"
|
||||||
|
)
|
||||||
|
|
||||||
|
create_reply_to_email(service=sample_service, email_address='foo@bar.com', is_default=False)
|
||||||
|
|
||||||
|
send_to_providers.send_email_to_provider(
|
||||||
|
db_notification,
|
||||||
|
)
|
||||||
|
|
||||||
|
app.aws_ses_client.send_email.assert_called_once_with(
|
||||||
|
ANY,
|
||||||
|
ANY,
|
||||||
|
ANY,
|
||||||
|
body=ANY,
|
||||||
|
html_body=ANY,
|
||||||
|
reply_to_address=reply_to.email_address
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user