fix tests

This commit is contained in:
Kenneth Kehl
2024-01-22 10:55:09 -08:00
parent ed3a356ad1
commit 6dc9828663
19 changed files with 282 additions and 99 deletions

View File

@@ -76,7 +76,6 @@ def dao_create_notification(notification):
# 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:

View File

@@ -10,7 +10,7 @@ from notifications_utils.template import (
)
from app import create_uuid, db, notification_provider_clients, redis_store
from app.aws.s3 import get_phone_number_from_s3
from app.aws.s3 import 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
@@ -30,6 +30,15 @@ from app.serialised_models import SerialisedService, SerialisedTemplate
def send_sms_to_provider(notification):
# we no longer store the personalisation in the db,
# need to retrieve from s3 before generating content
personalisation = get_personalisation_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
notification.personalisation = personalisation
service = SerialisedService.from_id(notification.service_id)
message_id = None
if not service.active:

View File

@@ -2,6 +2,7 @@ from flask import Blueprint, current_app, jsonify, request
from notifications_utils import SMS_CHAR_COUNT_LIMIT
from app import api_user, authenticated_service
from app.aws.s3 import get_personalisation_from_s3, get_phone_number_from_s3
from app.config import QueueNames
from app.dao import notifications_dao
from app.errors import InvalidRequest, register_errors
@@ -36,6 +37,19 @@ def get_notification_by_id(notification_id):
notification = notifications_dao.get_notification_with_personalisation(
str(authenticated_service.id), notification_id, key_type=None
)
if notification.job_id is not None:
notification.personalisation = get_personalisation_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
recipient = get_phone_number_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
notification.to = recipient
notification.normalised_to = recipient
return (
jsonify(
data={
@@ -67,6 +81,21 @@ def get_all_notifications():
key_type=api_user.key_type,
include_jobs=include_jobs,
)
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,
)
recipient = get_phone_number_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
notification.to = recipient
notification.normalised_to = recipient
return (
jsonify(
notifications=notification_with_personalisation_schema.dump(

View File

@@ -47,28 +47,30 @@ def invite_user_to_org(organization_id):
current_app.config["ORGANIZATION_INVITATION_EMAIL_TEMPLATE_ID"]
)
personalisation = {
"user_name": (
"The GOV.UK Notify team"
if invited_org_user.invited_by.platform_admin
else invited_org_user.invited_by.name
),
"organization_name": invited_org_user.organization.name,
"url": invited_org_user_url(
invited_org_user.id,
data.get("invite_link_host"),
),
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=invited_org_user.email_address,
service=template.service,
personalisation={
"user_name": (
"The GOV.UK Notify team"
if invited_org_user.invited_by.platform_admin
else invited_org_user.invited_by.name
),
"organization_name": invited_org_user.organization.name,
"url": invited_org_user_url(
invited_org_user.id,
data.get("invite_link_host"),
),
},
personalisation={},
notification_type=EMAIL_TYPE,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=invited_org_user.invited_by.email_address,
)
saved_notification.personalisation = personalisation
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

View File

@@ -202,12 +202,13 @@ def send_notifications_on_mou_signed(organization_id):
template_version=template.version,
recipient=recipient,
service=notify_service,
personalisation=personalisation,
personalisation={},
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=notify_service.get_default_reply_to_email_address(),
)
saved_notification.personalisation = personalisation
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
personalisation = {

View File

@@ -33,23 +33,23 @@ def _create_service_invite(invited_user, invite_link_host):
template = dao_get_template_by_id(template_id)
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
personalisation = {
"user_name": invited_user.from_user.name,
"service_name": invited_user.service.name,
"url": invited_user_url(invited_user.id, invite_link_host),
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=invited_user.email_address,
service=service,
personalisation={
"user_name": invited_user.from_user.name,
"service_name": invited_user.service.name,
"url": invited_user_url(invited_user.id, invite_link_host),
},
personalisation={},
notification_type=EMAIL_TYPE,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=invited_user.from_user.email_address,
)
saved_notification.personalisation = personalisation
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

View File

@@ -120,22 +120,23 @@ def update_user_attribute(user_id):
else:
return jsonify(data=user_to_update.serialize()), 200
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
personalisation = {
"name": user_to_update.name,
"servicemanagername": updated_by.name,
"email address": user_to_update.email_address,
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=recipient,
service=service,
personalisation={
"name": user_to_update.name,
"servicemanagername": updated_by.name,
"email address": user_to_update.email_address,
},
personalisation={},
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=reply_to,
)
saved_notification.personalisation = personalisation
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
@@ -371,24 +372,25 @@ def send_user_confirm_new_email(user_id):
current_app.config["CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID"]
)
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
personalisation = {
"name": user_to_send_to.name,
"url": _create_confirmation_url(
user=user_to_send_to, email_address=email["email"]
),
"feedback_url": current_app.config["ADMIN_BASE_URL"] + "/support",
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=email["email"],
service=service,
personalisation={
"name": user_to_send_to.name,
"url": _create_confirmation_url(
user=user_to_send_to, email_address=email["email"]
),
"feedback_url": current_app.config["ADMIN_BASE_URL"] + "/support",
},
personalisation={},
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=service.get_default_reply_to_email_address(),
)
saved_notification.personalisation = personalisation
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
return jsonify({}), 204
@@ -409,24 +411,25 @@ def send_new_user_email_verification(user_id):
current_app.logger.info("template.id is {}".format(template.id))
current_app.logger.info("service.id is {}".format(service.id))
personalisation = {
"name": user_to_send_to.name,
"url": _create_verification_url(
user_to_send_to,
base_url=request_json.get("admin_base_url"),
),
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=user_to_send_to.email_address,
service=service,
personalisation={
"name": user_to_send_to.name,
"url": _create_verification_url(
user_to_send_to,
base_url=request_json.get("admin_base_url"),
),
},
personalisation={},
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=service.get_default_reply_to_email_address(),
)
saved_notification.personalisation = personalisation
redis_store.set(
f"email-address-{saved_notification.id}",
@@ -456,23 +459,24 @@ def send_already_registered_email(user_id):
current_app.logger.info("template.id is {}".format(template.id))
current_app.logger.info("service.id is {}".format(service.id))
personalisation = {
"signin_url": current_app.config["ADMIN_BASE_URL"] + "/sign-in",
"forgot_password_url": current_app.config["ADMIN_BASE_URL"]
+ "/forgot-password",
"feedback_url": current_app.config["ADMIN_BASE_URL"] + "/support",
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=to["email"],
service=service,
personalisation={
"signin_url": current_app.config["ADMIN_BASE_URL"] + "/sign-in",
"forgot_password_url": current_app.config["ADMIN_BASE_URL"]
+ "/forgot-password",
"feedback_url": current_app.config["ADMIN_BASE_URL"] + "/support",
},
personalisation={},
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=service.get_default_reply_to_email_address(),
)
saved_notification.personalisation = personalisation
current_app.logger.info("Sending notification to queue")
@@ -572,24 +576,26 @@ def send_user_reset_password():
user_to_send_to = get_user_by_email(email["email"])
template = dao_get_template_by_id(current_app.config["PASSWORD_RESET_TEMPLATE_ID"])
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
personalisation = {
"user_name": user_to_send_to.name,
"url": _create_reset_password_url(
user_to_send_to.email_address,
base_url=request_json.get("admin_base_url"),
next_redirect=request_json.get("next"),
),
}
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=email["email"],
service=service,
personalisation={
"user_name": user_to_send_to.name,
"url": _create_reset_password_url(
user_to_send_to.email_address,
base_url=request_json.get("admin_base_url"),
next_redirect=request_json.get("next"),
),
},
personalisation=None,
notification_type=template.template_type,
api_key_id=None,
key_type=KEY_TYPE_NORMAL,
reply_to_text=service.get_default_reply_to_email_address(),
)
saved_notification.personalisation = personalisation
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

View File

@@ -18,6 +18,11 @@ def get_notification_by_id(notification_id):
notification = notifications_dao.get_notification_with_personalisation(
authenticated_service.id, notification_id, key_type=None
)
notification.personalisation = get_personalisation_from_s3(
notification.service_id,
notification.job_id,
notification.job_row_number,
)
return jsonify(notification.serialize()), 200