mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-05 23:38:25 -04:00
Merge pull request #1301 from alphagov/rc_populate_reply_to_address
Task 4 - Allow API calls to specify the reply address option
This commit is contained in:
@@ -8,7 +8,10 @@ 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 +113,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)
|
||||||
|
|||||||
@@ -1,34 +1,33 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from app import db, create_random_identifier
|
from app import db
|
||||||
from app.dao.jobs_dao import dao_create_job
|
from app.dao.jobs_dao import dao_create_job
|
||||||
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
||||||
from app.models import (
|
from app.models import (
|
||||||
ApiKey,
|
ApiKey,
|
||||||
EMAIL_TYPE,
|
|
||||||
SMS_TYPE,
|
|
||||||
KEY_TYPE_NORMAL,
|
|
||||||
Service,
|
|
||||||
User,
|
|
||||||
Template,
|
|
||||||
MonthlyBilling,
|
|
||||||
Notification,
|
|
||||||
ScheduledNotification,
|
|
||||||
ServicePermission,
|
|
||||||
Rate,
|
|
||||||
Job,
|
|
||||||
InboundSms,
|
InboundSms,
|
||||||
InboundNumber,
|
InboundNumber,
|
||||||
|
Job,
|
||||||
|
MonthlyBilling,
|
||||||
|
Notification,
|
||||||
|
NotificationEmailReplyTo,
|
||||||
Organisation,
|
Organisation,
|
||||||
|
Rate,
|
||||||
|
Service,
|
||||||
|
ServiceEmailReplyTo,
|
||||||
|
ServiceInboundApi,
|
||||||
|
ServiceLetterContact,
|
||||||
|
ScheduledNotification,
|
||||||
|
ServicePermission,
|
||||||
|
ServiceSmsSender,
|
||||||
|
Template,
|
||||||
|
User,
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
LETTER_TYPE,
|
|
||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
INBOUND_SMS_TYPE,
|
INBOUND_SMS_TYPE,
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL
|
||||||
ServiceInboundApi,
|
)
|
||||||
ServiceEmailReplyTo,
|
|
||||||
ServiceLetterContact, ServiceSmsSender)
|
|
||||||
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 +383,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
|
||||||
|
|||||||
@@ -21,10 +21,17 @@ from app.models import (
|
|||||||
BRANDING_ORG,
|
BRANDING_ORG,
|
||||||
BRANDING_GOVUK,
|
BRANDING_GOVUK,
|
||||||
BRANDING_BOTH,
|
BRANDING_BOTH,
|
||||||
BRANDING_ORG_BANNER)
|
BRANDING_ORG_BANNER
|
||||||
|
)
|
||||||
|
|
||||||
from tests.app.db import create_service, create_template, create_notification, create_inbound_number, \
|
from tests.app.db import (
|
||||||
create_reply_to_email
|
create_service,
|
||||||
|
create_template,
|
||||||
|
create_notification,
|
||||||
|
create_inbound_number,
|
||||||
|
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 +704,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