Save reply_to_text for one off notiications and csv notificaitons.

This commit is contained in:
Rebecca Law
2017-11-25 11:31:36 +00:00
parent d779751bae
commit 049daa0cb8
7 changed files with 140 additions and 43 deletions

View File

@@ -213,7 +213,8 @@ def save_sms(self,
created_at=datetime.utcnow(),
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
notification_id=notification_id
notification_id=notification_id,
reply_to_text=service.get_default_sms_sender()
)
provider_tasks.deliver_sms.apply_async(
@@ -260,7 +261,8 @@ def save_email(self,
created_at=datetime.utcnow(),
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
notification_id=notification_id
notification_id=notification_id,
reply_to_text=service.get_default_reply_to_email_address()
)
provider_tasks.deliver_email.apply_async(

View File

@@ -1,8 +1,10 @@
from app.config import QueueNames
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
from app.notifications.validators import (
check_service_over_daily_message_limit,
validate_and_format_recipient,
validate_template)
validate_template, check_service_sms_sender_id)
from app.notifications.process_notifications import (
persist_notification,
send_notification_to_queue,
@@ -13,7 +15,7 @@ from app.models import (
KEY_TYPE_NORMAL,
PRIORITY,
SMS_TYPE,
EMAIL_TYPE)
EMAIL_TYPE, LETTER_TYPE)
from app.dao.services_dao import dao_fetch_service_by_id
from app.dao.templates_dao import dao_get_template_by_id_and_service_id
from app.dao.users_dao import get_user_by_id
@@ -52,6 +54,8 @@ def send_one_off_notification(service_id, post_data):
validate_created_by(service, post_data['created_by'])
sender_id = post_data.get('sender_id', None)
reply_to = get_reply_to_text(notification_type=template.template_type, sender_id=sender_id, service=service)
notification = persist_notification(
template_id=template.id,
template_version=template.version,
@@ -61,9 +65,9 @@ def send_one_off_notification(service_id, post_data):
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
created_by_id=post_data['created_by']
created_by_id=post_data['created_by'],
reply_to_text=reply_to
)
sender_id = post_data.get('sender_id', None)
if sender_id:
if template.template_type == EMAIL_TYPE:
persist_email_reply_to_id_for_notification(notification.id, sender_id)
@@ -78,3 +82,23 @@ def send_one_off_notification(service_id, post_data):
)
return {'id': str(notification.id)}
def get_reply_to_text(notification_type, sender_id, service):
reply_to = None
if notification_type == EMAIL_TYPE:
if sender_id:
reply_to = dao_get_reply_to_by_id(service.id, sender_id).email_address
else:
service.get_default_reply_to_email_address()
elif notification_type == SMS_TYPE:
if sender_id:
reply_to = dao_get_service_sms_senders_by_id(service.id, sender_id).sms_sender
else:
reply_to = service.get_default_sms_sender()
elif notification_type == LETTER_TYPE:
reply_to = service.get_default_letter_contact()
return reply_to