mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
fix personalisation
This commit is contained in:
@@ -124,6 +124,29 @@ def get_phone_number_from_s3(service_id, job_id, job_row_number):
|
||||
my_phone = re.sub(r"[\+\s\(\)\-\.]*", "", my_phone)
|
||||
return my_phone
|
||||
|
||||
def get_personalisation_from_s3(service_id, job_id, job_row_number):
|
||||
job = JOBS.get(job_id)
|
||||
if job is None:
|
||||
job = get_job_from_s3(service_id, job_id)
|
||||
JOBS[job_id] = job
|
||||
incr_jobs_cache_misses()
|
||||
else:
|
||||
incr_jobs_cache_hits()
|
||||
|
||||
job = job.split("\r\n")
|
||||
first_row = job[0]
|
||||
job.pop(0)
|
||||
first_row = first_row.split(",")
|
||||
correct_row = job[job_row_number]
|
||||
correct_row = correct_row.split(",")
|
||||
personalisation_dict = {}
|
||||
index = 0
|
||||
for header in first_row:
|
||||
personalisation_dict[header] = correct_row[index]
|
||||
index = index + 1
|
||||
print(f"get personalisation returns {personalisation_dict}")
|
||||
return personalisation_dict
|
||||
|
||||
|
||||
def get_job_metadata_from_s3(service_id, job_id):
|
||||
obj = get_s3_object(*get_job_location(service_id, job_id))
|
||||
|
||||
@@ -73,6 +73,14 @@ def dao_create_notification(notification):
|
||||
if not notification.status:
|
||||
notification.status = NOTIFICATION_CREATED
|
||||
|
||||
# notify-api-749 do not write to db
|
||||
# if we have a verify_code we know this is the authentication notification at login time
|
||||
# and not csv (containing PII) provided by the user, so allow verify_code to continue to exist
|
||||
print(f"PERSONALISATION = {notification.personalisation}")
|
||||
if "verify_code" in str(notification.personalisation):
|
||||
pass
|
||||
else:
|
||||
notification.personalisation=""
|
||||
db.session.add(notification)
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import dateutil
|
||||
import pytz
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
|
||||
from app.aws.s3 import get_job_metadata_from_s3
|
||||
from app.aws.s3 import get_job_metadata_from_s3, get_personalisation_from_s3
|
||||
from app.celery.tasks import process_job
|
||||
from app.config import QueueNames
|
||||
from app.dao.fact_notification_status_dao import fetch_notification_statuses_for_job
|
||||
@@ -87,6 +87,12 @@ def get_all_notifications_for_service_job(service_id, job_id):
|
||||
paginated_notifications.items, many=True
|
||||
)
|
||||
|
||||
for notification in paginated_notifications.items:
|
||||
if notification.job_id is not None:
|
||||
notification.personalisation = get_personalisation_from_s3(
|
||||
notification.service_id, notification.job_id, notification.job_row_number
|
||||
)
|
||||
|
||||
return (
|
||||
jsonify(
|
||||
notifications=notifications,
|
||||
|
||||
@@ -2,6 +2,7 @@ import itertools
|
||||
from datetime import datetime
|
||||
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
from app.aws.s3 import get_personalisation_from_s3
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from werkzeug.datastructures import MultiDict
|
||||
@@ -425,6 +426,12 @@ def get_all_notifications_for_service(service_id):
|
||||
include_one_off=include_one_off,
|
||||
)
|
||||
|
||||
for notification in pagination.items:
|
||||
if notification.job_id is not None:
|
||||
notification.personalisation = get_personalisation_from_s3(
|
||||
notification.service_id, notification.job_id, notification.job_row_number
|
||||
)
|
||||
|
||||
kwargs = request.args.to_dict()
|
||||
kwargs["service_id"] = service_id
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from flask import current_app, jsonify, request, url_for
|
||||
|
||||
from app import api_user, authenticated_service
|
||||
from app.aws.s3 import get_personalisation_from_s3
|
||||
from app.dao import notifications_dao
|
||||
from app.schema_validation import validate
|
||||
from app.v2.notifications import v2_notification_blueprint
|
||||
@@ -49,6 +50,12 @@ def get_notifications():
|
||||
count_pages=False,
|
||||
)
|
||||
|
||||
for notification in paginated_notifications.items:
|
||||
if notification.job_id is not None:
|
||||
notification.personalisation = get_personalisation_from_s3(
|
||||
notification.service_id, notification.job_id, notification.job_row_number
|
||||
)
|
||||
|
||||
def _build_links(notifications):
|
||||
_links = {
|
||||
"current": url_for(".get_notifications", _external=True, **data),
|
||||
|
||||
Reference in New Issue
Block a user