mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge branch 'add-reply-to-notifications' of github.com:alphagov/notifications-api into add-reply-to-notifications
This commit is contained in:
@@ -138,11 +138,8 @@ def validate_template(template_id, personalisation, service, notification_type):
|
||||
|
||||
def check_service_email_reply_to_id(service_id, reply_to_id, notification_type):
|
||||
if reply_to_id:
|
||||
if notification_type != EMAIL_TYPE:
|
||||
message = 'email_reply_to_id is not a valid option for {} notification'.format(notification_type)
|
||||
raise BadRequestError(message=message)
|
||||
try:
|
||||
dao_get_reply_to_by_id(service_id, reply_to_id)
|
||||
return dao_get_reply_to_by_id(service_id, reply_to_id).email_address
|
||||
except NoResultFound:
|
||||
message = 'email_reply_to_id {} does not exist in database for service id {}'\
|
||||
.format(reply_to_id, service_id)
|
||||
@@ -151,9 +148,6 @@ def check_service_email_reply_to_id(service_id, reply_to_id, notification_type):
|
||||
|
||||
def check_service_sms_sender_id(service_id, sms_sender_id, notification_type):
|
||||
if sms_sender_id:
|
||||
if notification_type != SMS_TYPE:
|
||||
message = 'sms_sender_id is not a valid option for {} notification'.format(notification_type)
|
||||
raise BadRequestError(message=message)
|
||||
try:
|
||||
return dao_get_service_sms_senders_by_id(service_id, sms_sender_id).sms_sender
|
||||
except NoResultFound:
|
||||
|
||||
@@ -127,7 +127,8 @@ post_sms_request = {
|
||||
"scheduled_for": {"type": ["string", "null"], "format": "datetime"},
|
||||
"sms_sender_id": uuid
|
||||
},
|
||||
"required": ["phone_number", "template_id"]
|
||||
"required": ["phone_number", "template_id"],
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
sms_content = {
|
||||
@@ -172,7 +173,8 @@ post_email_request = {
|
||||
"scheduled_for": {"type": ["string", "null"], "format": "datetime"},
|
||||
"email_reply_to_id": uuid
|
||||
},
|
||||
"required": ["email_address", "template_id"]
|
||||
"required": ["email_address", "template_id"],
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
email_content = {
|
||||
@@ -215,7 +217,8 @@ post_letter_request = {
|
||||
"template_id": uuid,
|
||||
"personalisation": letter_personalisation
|
||||
},
|
||||
"required": ["template_id", "personalisation"]
|
||||
"required": ["template_id", "personalisation"],
|
||||
"additionalProperties": False
|
||||
}
|
||||
|
||||
letter_content = {
|
||||
|
||||
@@ -63,15 +63,12 @@ def post_notification(notification_type):
|
||||
check_service_has_permission(notification_type, authenticated_service.permissions)
|
||||
|
||||
scheduled_for = form.get("scheduled_for", None)
|
||||
service_email_reply_to_id = form.get("email_reply_to_id", None)
|
||||
service_sms_sender_id = form.get("sms_sender_id", None)
|
||||
|
||||
check_service_can_schedule_notification(authenticated_service.permissions, scheduled_for)
|
||||
|
||||
check_rate_limiting(authenticated_service, api_user)
|
||||
|
||||
check_service_email_reply_to_id(str(authenticated_service.id), service_email_reply_to_id, notification_type)
|
||||
sms_sender = check_service_sms_sender_id(str(authenticated_service.id), service_sms_sender_id, notification_type)
|
||||
reply_to = get_reply_to_text(notification_type, form)
|
||||
|
||||
template, template_with_content = validate_template(
|
||||
form['template_id'],
|
||||
@@ -93,13 +90,13 @@ def post_notification(notification_type):
|
||||
api_key=api_user,
|
||||
template=template,
|
||||
service=authenticated_service,
|
||||
reply_to_text=sms_sender,
|
||||
reply_to_text=reply_to
|
||||
)
|
||||
|
||||
if notification_type == SMS_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_sms_response_from_notification,
|
||||
from_number=sms_sender or authenticated_service.get_default_sms_sender()
|
||||
from_number=reply_to
|
||||
)
|
||||
elif notification_type == EMAIL_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
@@ -196,3 +193,23 @@ def process_letter_notification(*, letter_data, api_key, template):
|
||||
)
|
||||
|
||||
return notification
|
||||
|
||||
|
||||
def get_reply_to_text(notification_type, form):
|
||||
service_email_reply_to_id = form.get("email_reply_to_id", None)
|
||||
service_sms_sender_id = form.get("sms_sender_id", None)
|
||||
reply_to = None
|
||||
if notification_type == EMAIL_TYPE:
|
||||
reply_to = check_service_email_reply_to_id(
|
||||
str(authenticated_service.id), service_email_reply_to_id, notification_type
|
||||
) or authenticated_service.get_default_reply_to_email_address()
|
||||
|
||||
elif notification_type == SMS_TYPE:
|
||||
reply_to = check_service_sms_sender_id(
|
||||
str(authenticated_service.id), service_sms_sender_id, notification_type
|
||||
) or authenticated_service.get_default_sms_sender()
|
||||
|
||||
elif notification_type == LETTER_TYPE:
|
||||
reply_to = authenticated_service.get_default_letter_contact()
|
||||
|
||||
return reply_to
|
||||
|
||||
Reference in New Issue
Block a user