Add endpoint to redirect from contact list to send

In order to use a contact list we’re going to put you in the normal
upload a spreadsheet journey. Except without having to upload again.

So this commit adds an endpoint that takes the file from the contact
list bucket, puts it in the same place it would have gone if you’d
uploaded it, then sends you on your way.
This commit is contained in:
Chris Hill-Scott
2020-03-13 14:38:43 +00:00
parent 03f2368deb
commit 460b779d11
4 changed files with 76 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ from app.main.forms import (
SetSenderForm,
get_placeholder_form_instance,
)
from app.models.contact_list import ContactList
from app.models.user import Users
from app.s3_client.s3_csv_client import (
s3download,
@@ -491,6 +492,20 @@ def send_test_preview(service_id, template_id, filetype):
return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page'))
@main.route(
'/services/<uuid:service_id>/send/<uuid:template_id>'
'/from-contact-list/<uuid:contact_list_id>'
)
@user_has_permissions('send_messages')
def send_from_contact_list(service_id, template_id, contact_list_id):
return redirect(url_for(
'main.check_messages',
service_id=current_service.id,
template_id=template_id,
upload_id=ContactList.copy_to_uploads(service_id, contact_list_id),
))
def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_pdf=False):
try:

View File

@@ -51,6 +51,22 @@ class ContactList(JSONModel):
bucket=ContactList.get_bucket_name(),
)
@staticmethod
def copy_to_uploads(service_id, upload_id):
contents = ContactList.download(service_id, upload_id)
metadata = ContactList.get_metadata(service_id, upload_id)
new_upload_id = s3upload(
service_id,
contents,
current_app.config['AWS_REGION'],
)
set_metadata_on_csv_upload(
service_id,
new_upload_id,
**metadata,
)
return new_upload_id
@classmethod
def create(cls, service_id, upload_id):

View File

@@ -259,6 +259,7 @@ class HeaderNavigation(Navigation):
'send_test',
'no_cookie.send_test_preview',
'send_test_step',
'send_from_contact_list',
'send_uploaded_letter',
'service_add_email_reply_to',
'service_add_letter_contact',
@@ -594,6 +595,7 @@ class MainNavigation(Navigation):
'robots',
'security',
'send_notification',
'send_from_contact_list',
'send_uploaded_letter',
'service_dashboard_updates',
'service_delete_email_reply_to',
@@ -847,6 +849,7 @@ class CaseworkNavigation(Navigation):
'send_messages',
'send_notification',
'no_cookie.send_test_preview',
'send_from_contact_list',
'send_uploaded_letter',
'service_add_email_reply_to',
'service_add_letter_contact',
@@ -1136,6 +1139,7 @@ class OrgNavigation(Navigation):
'send_test',
'no_cookie.send_test_preview',
'send_test_step',
'send_from_contact_list',
'send_uploaded_letter',
'service_add_email_reply_to',
'service_add_letter_contact',