Store the sender_id that should be used for a job in S3 metadata

Currently, a user can select a reply-to email address or text message
sender when uploading a CSV file but this is ignored and the default is
always used instead. As a first step towards changing this, this adds
the sender_id (if selected) to the S3 metadata so that this information
can be used when processing the job.
This commit is contained in:
Katie Smith
2018-11-06 14:22:22 +00:00
parent 8dc7e6e5f8
commit 0f90bde958
2 changed files with 65 additions and 9 deletions

View File

@@ -115,9 +115,16 @@ def send_messages(service_id, template_id):
session['file_uploads'].keys())
)
session['sender_id'] = None
db_template = service_api_client.get_service_template(service_id, template_id)['data']
email_reply_to = None
sms_sender = None
if db_template['template_type'] == 'email':
email_reply_to = get_email_reply_to_address_from_session()
elif db_template['template_type'] == 'sms':
sms_sender = get_sms_sender_from_session()
if email_or_sms_not_enabled(db_template['template_type'], current_service.permissions):
return redirect(url_for(
'.action_blocked',
@@ -139,6 +146,8 @@ def send_messages(service_id, template_id):
filetype='png',
page_count=get_page_count_for_letter(db_template),
),
email_reply_to=email_reply_to,
sms_sender=sms_sender,
)
form = CsvUploadForm()
@@ -626,17 +635,20 @@ def check_messages(service_id, template_id, upload_id, row_index=2):
data['original_file_name'] = SanitiseASCII.encode(data.get('original_file_name', ''))
set_metadata_on_csv_upload(
service_id,
upload_id,
notification_count=data['count_of_recipients'],
template_id=str(template_id),
valid=True,
original_file_name=unicode_truncate(
metadata_kwargs = {
'notification_count': data['count_of_recipients'],
'template_id': str(template_id),
'valid': True,
'original_file_name': unicode_truncate(
data['original_file_name'],
1600,
),
)
}
if session.get('sender_id'):
metadata_kwargs['sender_id'] = session['sender_id']
set_metadata_on_csv_upload(service_id, upload_id, **metadata_kwargs)
return render_template('views/check/ok.html', **data)
@@ -696,6 +708,8 @@ def start_job(service_id, upload_id):
scheduled_for=request.form.get('scheduled_for', '')
)
session.pop('sender_id', None)
return redirect(
url_for(
'main.view_job',