Allow the admin app to send one-off letters

This commit modifies the code paths the admin app uses to send one off
emails and text messages to also accept letters.

This mostly worked already, the two changes were:
- making sure that one-off letters are processed by the correct task,
  from the correct queue
- one-off letters sent from a service in research mode don’t get put on
  a queue and go straight to `delivered` (because we don’t want to send
  them for real)
This commit is contained in:
Chris Hill-Scott
2018-10-31 14:30:46 +00:00
parent 87017fc3d1
commit 674cdbd265
4 changed files with 65 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ from notifications_utils.recipients import (
from app import redis_store
from app.celery import provider_tasks
from app.celery.letters_pdf_tasks import create_letters_pdf
from app.config import QueueNames
from app.models import (
@@ -149,6 +150,10 @@ def send_notification_to_queue(notification, research_mode, queue=None):
if not queue:
queue = QueueNames.SEND_EMAIL
deliver_task = provider_tasks.deliver_email
if notification.notification_type == LETTER_TYPE:
if not queue:
queue = QueueNames.CREATE_LETTERS_PDF
deliver_task = create_letters_pdf
try:
deliver_task.apply_async([str(notification.id)], queue=queue)

View File

@@ -1,6 +1,7 @@
from sqlalchemy.orm.exc import NoResultFound
from app.config import QueueNames
from app.dao.notifications_dao import _update_notification_status
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 (
@@ -17,6 +18,8 @@ from app.models import (
PRIORITY,
SMS_TYPE,
EMAIL_TYPE,
LETTER_TYPE,
NOTIFICATION_DELIVERED,
)
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
@@ -78,11 +81,18 @@ def send_one_off_notification(service_id, post_data):
)
queue_name = QueueNames.PRIORITY if template.process_type == PRIORITY else None
send_notification_to_queue(
notification=notification,
research_mode=service.research_mode,
queue=queue_name
)
if template.template_type == LETTER_TYPE and service.research_mode:
_update_notification_status(
notification,
NOTIFICATION_DELIVERED,
)
else:
send_notification_to_queue(
notification=notification,
research_mode=service.research_mode,
queue=queue_name,
)
return {'id': str(notification.id)}