mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 10:03:21 -04:00
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:
@@ -42,6 +42,7 @@ from app.main.forms import (
|
|||||||
SetSenderForm,
|
SetSenderForm,
|
||||||
get_placeholder_form_instance,
|
get_placeholder_form_instance,
|
||||||
)
|
)
|
||||||
|
from app.models.contact_list import ContactList
|
||||||
from app.models.user import Users
|
from app.models.user import Users
|
||||||
from app.s3_client.s3_csv_client import (
|
from app.s3_client.s3_csv_client import (
|
||||||
s3download,
|
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'))
|
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):
|
def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_pdf=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -51,6 +51,22 @@ class ContactList(JSONModel):
|
|||||||
bucket=ContactList.get_bucket_name(),
|
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
|
@classmethod
|
||||||
def create(cls, service_id, upload_id):
|
def create(cls, service_id, upload_id):
|
||||||
|
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ class HeaderNavigation(Navigation):
|
|||||||
'send_test',
|
'send_test',
|
||||||
'no_cookie.send_test_preview',
|
'no_cookie.send_test_preview',
|
||||||
'send_test_step',
|
'send_test_step',
|
||||||
|
'send_from_contact_list',
|
||||||
'send_uploaded_letter',
|
'send_uploaded_letter',
|
||||||
'service_add_email_reply_to',
|
'service_add_email_reply_to',
|
||||||
'service_add_letter_contact',
|
'service_add_letter_contact',
|
||||||
@@ -594,6 +595,7 @@ class MainNavigation(Navigation):
|
|||||||
'robots',
|
'robots',
|
||||||
'security',
|
'security',
|
||||||
'send_notification',
|
'send_notification',
|
||||||
|
'send_from_contact_list',
|
||||||
'send_uploaded_letter',
|
'send_uploaded_letter',
|
||||||
'service_dashboard_updates',
|
'service_dashboard_updates',
|
||||||
'service_delete_email_reply_to',
|
'service_delete_email_reply_to',
|
||||||
@@ -847,6 +849,7 @@ class CaseworkNavigation(Navigation):
|
|||||||
'send_messages',
|
'send_messages',
|
||||||
'send_notification',
|
'send_notification',
|
||||||
'no_cookie.send_test_preview',
|
'no_cookie.send_test_preview',
|
||||||
|
'send_from_contact_list',
|
||||||
'send_uploaded_letter',
|
'send_uploaded_letter',
|
||||||
'service_add_email_reply_to',
|
'service_add_email_reply_to',
|
||||||
'service_add_letter_contact',
|
'service_add_letter_contact',
|
||||||
@@ -1136,6 +1139,7 @@ class OrgNavigation(Navigation):
|
|||||||
'send_test',
|
'send_test',
|
||||||
'no_cookie.send_test_preview',
|
'no_cookie.send_test_preview',
|
||||||
'send_test_step',
|
'send_test_step',
|
||||||
|
'send_from_contact_list',
|
||||||
'send_uploaded_letter',
|
'send_uploaded_letter',
|
||||||
'service_add_email_reply_to',
|
'service_add_email_reply_to',
|
||||||
'service_add_letter_contact',
|
'service_add_letter_contact',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from glob import glob
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from os import path
|
from os import path
|
||||||
|
from unittest.mock import ANY
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from zipfile import BadZipFile
|
from zipfile import BadZipFile
|
||||||
|
|
||||||
@@ -3780,3 +3781,43 @@ def test_redirects_to_template_if_job_exists_already(
|
|||||||
_external=True,
|
_external=True,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_from_contact_list(
|
||||||
|
mocker,
|
||||||
|
client_request,
|
||||||
|
fake_uuid,
|
||||||
|
):
|
||||||
|
new_uuid = uuid.uuid4()
|
||||||
|
mock_download = mocker.patch('app.models.contact_list.s3download', return_value='contents')
|
||||||
|
mock_get_metadata = mocker.patch('app.models.contact_list.get_csv_metadata', return_value={
|
||||||
|
'example_key': 'example value',
|
||||||
|
})
|
||||||
|
mock_upload = mocker.patch('app.models.contact_list.s3upload', return_value=new_uuid)
|
||||||
|
mock_set_metadata = mocker.patch('app.models.contact_list.set_metadata_on_csv_upload')
|
||||||
|
client_request.get(
|
||||||
|
'main.send_from_contact_list',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
template_id=fake_uuid,
|
||||||
|
contact_list_id=fake_uuid,
|
||||||
|
_expected_status=302,
|
||||||
|
_expected_redirect=url_for(
|
||||||
|
'main.check_messages',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
template_id=fake_uuid,
|
||||||
|
upload_id=new_uuid,
|
||||||
|
_external=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
mock_download.assert_called_once_with(
|
||||||
|
SERVICE_ONE_ID, fake_uuid, bucket='test-contact-list'
|
||||||
|
)
|
||||||
|
mock_get_metadata.assert_called_once_with(
|
||||||
|
SERVICE_ONE_ID, fake_uuid, bucket='test-contact-list'
|
||||||
|
)
|
||||||
|
mock_upload.assert_called_once_with(
|
||||||
|
SERVICE_ONE_ID, 'contents', ANY
|
||||||
|
)
|
||||||
|
mock_set_metadata.assert_called_once_with(
|
||||||
|
SERVICE_ONE_ID, new_uuid, example_key='example value'
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user