mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Use same template to validate and send notification
To be absolutely sure that we can send a message we should also validate it using the same template class that we use to render it.
This commit is contained in:
@@ -8,6 +8,7 @@ from flask import request, jsonify, current_app, abort
|
||||
from notifications_utils.recipients import (
|
||||
format_postcode_for_printing, is_a_real_uk_postcode, try_validate_and_format_phone_number
|
||||
)
|
||||
from notifications_utils.template import WithSubjectTemplate
|
||||
|
||||
from app import (
|
||||
api_user,
|
||||
@@ -166,23 +167,25 @@ def post_notification(notification_type):
|
||||
if notification_type == SMS_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_sms_response_from_notification,
|
||||
from_number=reply_to
|
||||
from_number=reply_to,
|
||||
content=str(template_with_content),
|
||||
)
|
||||
elif notification_type == EMAIL_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_email_response_from_notification,
|
||||
subject=template_with_content.subject,
|
||||
email_from='{}@{}'.format(authenticated_service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||
email_from='{}@{}'.format(authenticated_service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
content=WithSubjectTemplate.__str__(template_with_content),
|
||||
)
|
||||
elif notification_type == LETTER_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_letter_response_from_notification,
|
||||
subject=template_with_content.subject,
|
||||
content=WithSubjectTemplate.__str__(template_with_content),
|
||||
)
|
||||
|
||||
resp = create_resp_partial(
|
||||
notification=notification,
|
||||
content=str(template_with_content),
|
||||
url_root=request.url_root,
|
||||
scheduled_for=scheduled_for
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user