mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
fix personalization_bug for one-offs
This commit is contained in:
@@ -13,7 +13,11 @@ from app import (
|
||||
notification_provider_clients,
|
||||
redis_store,
|
||||
)
|
||||
from app.aws.s3 import get_personalisation_from_s3, get_phone_number_from_s3
|
||||
from app.aws.s3 import (
|
||||
get_job_from_s3,
|
||||
get_personalisation_from_s3,
|
||||
get_phone_number_from_s3,
|
||||
)
|
||||
from app.celery.test_key_tasks import send_email_response, send_sms_response
|
||||
from app.dao.email_branding_dao import dao_get_email_branding_by_id
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
@@ -36,17 +40,32 @@ def send_sms_to_provider(notification):
|
||||
Get data for recipient, template,
|
||||
notification and send it to sns.
|
||||
"""
|
||||
# we no longer store the personalisation in the db,
|
||||
# need to retrieve from s3 before generating content
|
||||
# However, we are still sending the initial verify code through personalisation
|
||||
# so if there is some value there, don't overwrite it
|
||||
if not notification.personalisation:
|
||||
personalisation = get_personalisation_from_s3(
|
||||
notification.service_id,
|
||||
notification.job_id,
|
||||
notification.job_row_number,
|
||||
)
|
||||
notification.personalisation = personalisation
|
||||
# Take this path for report generation, where we know
|
||||
# everything is in the cache.
|
||||
personalisation = get_personalisation_from_s3(
|
||||
notification.service_id,
|
||||
notification.job_id,
|
||||
notification.job_row_number,
|
||||
)
|
||||
|
||||
# For one-off sends, they may not get into the cache
|
||||
# by the time we get here, so do this slow direct-from-s3
|
||||
# approach. It is okay to be slow, since one-offs have
|
||||
# to be typed in by hand.
|
||||
if personalisation == {}:
|
||||
job = get_job_from_s3(notification.service_id, notification.job_id)
|
||||
job = job.split("\r\n")
|
||||
first_row = job[0]
|
||||
job.pop(0)
|
||||
first_row = first_row.split(",")
|
||||
personalisation = {}
|
||||
job_row = 0
|
||||
for row in job:
|
||||
row = row.split(",")
|
||||
temp = dict(zip(first_row, row))
|
||||
personalisation[job_row] = temp
|
||||
job_row = job_row + 1
|
||||
notification.personalisation = personalisation[notification.job_row_number]
|
||||
|
||||
service = SerialisedService.from_id(notification.service_id)
|
||||
message_id = None
|
||||
|
||||
Reference in New Issue
Block a user