mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Added the mapping between notification and reply to email to the database and persisted the mapping when the request is received by the end point. the end point also checks if the reply to email id exists and if not returns an error. Also added tests to test the functionality.
This commit is contained in:
@@ -40,7 +40,7 @@ from app.models import (
|
||||
KEY_TYPE_NORMAL, KEY_TYPE_TEST,
|
||||
LETTER_TYPE,
|
||||
NOTIFICATION_SENT,
|
||||
)
|
||||
NotificationEmailReplyTo, ServiceEmailReplyTo)
|
||||
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.statsd_decorators import statsd
|
||||
@@ -603,3 +603,23 @@ def dao_set_created_live_letter_api_notifications_to_pending():
|
||||
db.session.commit()
|
||||
|
||||
return notifications
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_create_notification_email_reply_to_mapping(notification_id, email_reply_to_id):
|
||||
notification_email_reply_to = NotificationEmailReplyTo(
|
||||
notification_id=notification_id,
|
||||
service_email_reply_to_id=email_reply_to_id
|
||||
)
|
||||
db.session.add(notification_email_reply_to)
|
||||
|
||||
|
||||
def dao_get_notification_email_reply_for_notification(notification_id):
|
||||
email_reply_to = ServiceEmailReplyTo.query.join(
|
||||
NotificationEmailReplyTo
|
||||
).filter(
|
||||
NotificationEmailReplyTo.notification_id == notification_id
|
||||
).all()
|
||||
|
||||
if len(email_reply_to) == 1:
|
||||
return email_reply_to[0].email_address
|
||||
|
||||
@@ -16,7 +16,8 @@ from app.config import QueueNames
|
||||
from app.models import SMS_TYPE, Notification, KEY_TYPE_TEST, EMAIL_TYPE, NOTIFICATION_CREATED, ScheduledNotification
|
||||
from app.dao.notifications_dao import (dao_create_notification,
|
||||
dao_delete_notifications_and_history_by_id,
|
||||
dao_created_scheduled_notification)
|
||||
dao_created_scheduled_notification,
|
||||
dao_create_notification_email_reply_to_mapping)
|
||||
from app.v2.errors import BadRequestError
|
||||
from app.utils import get_template_instance, cache_key_for_service_template_counter, convert_bst_to_utc
|
||||
|
||||
@@ -141,3 +142,7 @@ def persist_scheduled_notification(notification_id, scheduled_for):
|
||||
scheduled_notification = ScheduledNotification(notification_id=notification_id,
|
||||
scheduled_for=scheduled_datetime)
|
||||
dao_created_scheduled_notification(scheduled_notification)
|
||||
|
||||
|
||||
def persist_email_reply_to_id_for_notification(notification_id, email_reply_to_id):
|
||||
dao_create_notification_email_reply_to_mapping(notification_id, email_reply_to_id)
|
||||
|
||||
@@ -19,7 +19,7 @@ from app.notifications.process_notifications import (
|
||||
persist_notification,
|
||||
send_notification_to_queue,
|
||||
simulated_recipient,
|
||||
persist_scheduled_notification)
|
||||
persist_scheduled_notification, persist_email_reply_to_id_for_notification)
|
||||
from app.notifications.process_letter_notifications import (
|
||||
create_letter_notification
|
||||
)
|
||||
@@ -140,6 +140,10 @@ def process_sms_or_email_notification(*, form, notification_type, api_key, templ
|
||||
simulated=simulated
|
||||
)
|
||||
|
||||
email_reply_to_id = form.get("email_reply_to_id", None)
|
||||
if email_reply_to_id is not None:
|
||||
persist_email_reply_to_id_for_notification(notification.id, email_reply_to_id)
|
||||
|
||||
scheduled_for = form.get("scheduled_for", None)
|
||||
if scheduled_for:
|
||||
persist_scheduled_notification(notification.id, form["scheduled_for"])
|
||||
|
||||
Reference in New Issue
Block a user