Remove the use of schedule_for in post_notifications.

Years ago we started to implement a way to schedule a notification. We hit a problem but we never came up with a good solution and the feature never made it back to the top of the priority list.

This PR removes the code for scheduled_for. There will be another PR to drop the scheduled_notifications table and remove the schedule_notifications service permission

Unfortunately, I don't think we can remove the `scheduled_for` attribute from the notification.serialized method because out clients might fail if something is missing. For now I have left it in but defaulted the value to None.
This commit is contained in:
Rebecca Law
2020-06-24 07:34:58 +01:00
parent d108c644bc
commit ce32e577b7
12 changed files with 34 additions and 178 deletions

View File

@@ -2,10 +2,10 @@
def create_post_sms_response_from_notification(
notification_id, client_reference, template_id, template_version, service_id,
content, from_number, url_root, scheduled_for
content, from_number, url_root
):
resp = __create_notification_response(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
notification_id, client_reference, template_id, template_version, service_id, url_root
)
resp['content'] = {
'from_number': from_number,
@@ -24,10 +24,9 @@ def create_post_email_response_from_notification(
subject,
email_from,
url_root,
scheduled_for
):
resp = __create_notification_response(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
notification_id, client_reference, template_id, template_version, service_id, url_root
)
resp['content'] = {
"from_email": email_from,
@@ -39,10 +38,10 @@ def create_post_email_response_from_notification(
def create_post_letter_response_from_notification(
notification_id, client_reference, template_id, template_version, service_id,
content, subject, url_root, scheduled_for
content, subject, url_root
):
resp = __create_notification_response(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
notification_id, client_reference, template_id, template_version, service_id, url_root
)
resp['content'] = {
"body": content,
@@ -52,7 +51,7 @@ def create_post_letter_response_from_notification(
def __create_notification_response(
notification_id, client_reference, template_id, template_version, service_id, url_root, scheduled_for
notification_id, client_reference, template_id, template_version, service_id, url_root
):
return {
"id": notification_id,
@@ -67,5 +66,5 @@ def __create_notification_response(
str(template_id)
)
},
"scheduled_for": scheduled_for if scheduled_for else None
"scheduled_for": None
}

View File

@@ -43,13 +43,11 @@ from app.notifications.process_letter_notifications import (
)
from app.notifications.process_notifications import (
persist_notification,
persist_scheduled_notification,
simulated_recipient,
send_notification_to_queue_detached)
from app.notifications.validators import (
check_if_service_can_send_files_by_email,
check_rate_limiting,
check_service_can_schedule_notification,
check_service_email_reply_to_id,
check_service_has_permission,
check_service_sms_sender_id,
@@ -127,10 +125,6 @@ def post_notification(notification_type):
check_service_has_permission(notification_type, authenticated_service.permissions)
scheduled_for = form.get("scheduled_for", None)
check_service_can_schedule_notification(authenticated_service.permissions, scheduled_for)
check_rate_limiting(authenticated_service, api_user)
template, template_with_content = validate_template(
@@ -206,8 +200,8 @@ def process_sms_or_email_notification(
service_id=service.id,
notification_type=notification_type,
reply_to=reply_to_text,
scheduled_for=form.get("scheduled_for", None),
template_with_content=template_with_content)
template_with_content=template_with_content
)
if str(service.id) in current_app.config.get('HIGH_VOLUME_SERVICE') and api_key.key_type == KEY_TYPE_NORMAL \
and notification_type == EMAIL_TYPE:
@@ -251,21 +245,17 @@ def process_sms_or_email_notification(
document_download_count=document_download_count
)
scheduled_for = form.get("scheduled_for", None)
if scheduled_for:
persist_scheduled_notification(notification_id, form["scheduled_for"])
if not simulated:
queue_name = QueueNames.PRIORITY if template_process_type == PRIORITY else None
send_notification_to_queue_detached(
key_type=key_type,
notification_type=notification_type,
notification_id=notification_id,
research_mode=service_in_research_mode, # research_mode is deprecated
queue=queue_name
)
else:
if not simulated:
queue_name = QueueNames.PRIORITY if template_process_type == PRIORITY else None
send_notification_to_queue_detached(
key_type=key_type,
notification_type=notification_type,
notification_id=notification_id,
research_mode=service_in_research_mode, # research_mode is deprecated
queue=queue_name
)
else:
current_app.logger.debug("POST simulated notification for id: {}".format(notification_id))
current_app.logger.debug("POST simulated notification for id: {}".format(notification_id))
return resp
@@ -395,7 +385,6 @@ def process_letter_notification(
template_version=notification.template_version,
notification_type=notification.notification_type,
reply_to=reply_to_text,
scheduled_for=letter_data.get('scheduled_for', None),
service_id=notification.service_id,
template_with_content=template_with_content
)
@@ -490,9 +479,16 @@ def get_reply_to_text(notification_type, form, template):
return reply_to
def create_response_for_post_notification(notification_id, client_reference, template_id, template_version, service_id,
notification_type, reply_to, scheduled_for,
template_with_content):
def create_response_for_post_notification(
notification_id,
client_reference,
template_id,
template_version,
service_id,
notification_type,
reply_to,
template_with_content
):
if notification_type == SMS_TYPE:
create_resp_partial = functools.partial(
create_post_sms_response_from_notification,
@@ -512,7 +508,6 @@ def create_response_for_post_notification(notification_id, client_reference, tem
resp = create_resp_partial(
notification_id, client_reference, template_id, template_version, service_id,
url_root=request.url_root,
scheduled_for=scheduled_for,
content=template_with_content.content_with_placeholders_filled_in,
)
return resp