Skip to content

Commit

Permalink
Merge pull request #854 from GSA/notify-api-853
Browse files Browse the repository at this point in the history
fix email notifications missing personalisation (notify-api-853)
  • Loading branch information
ccostino authored Mar 13, 2024
2 parents 8fe70fe + a8640a6 commit 30ecc21
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/organization/rest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json

from flask import Blueprint, abort, current_app, jsonify, request
from sqlalchemy.exc import IntegrityError

from app import redis_store
from app.config import QueueNames
from app.dao.annual_billing_dao import set_default_free_allowance_for_service
from app.dao.dao_utils import transaction
Expand Down Expand Up @@ -210,6 +213,12 @@ def _send_notification(template_id, recipient, personalisation):
reply_to_text=notify_service.get_default_reply_to_email_address(),
)
saved_notification.personalisation = personalisation

redis_store.set(
f"email-personalisation-{saved_notification.id}",
json.dumps(personalisation),
ex=60 * 60,
)
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

personalisation = {
Expand Down
27 changes: 27 additions & 0 deletions app/user/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def update_user_attribute(user_id):
)
saved_notification.personalisation = personalisation

redis_store.set(
f"email-personalisation-{saved_notification.id}",
json.dumps(personalisation),
ex=60 * 60,
)
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

return jsonify(data=user_to_update.serialize()), 200
Expand Down Expand Up @@ -361,6 +366,12 @@ def create_2fa_code(
# Assume that we never want to observe the Notify service's research mode
# setting for this notification - we still need to be able to log into the
# admin even if we're doing user research using this service:

redis_store.set(
f"email-personalisation-{saved_notification.id}",
json.dumps(personalisation),
ex=60 * 60,
)
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)


Expand Down Expand Up @@ -394,6 +405,11 @@ def send_user_confirm_new_email(user_id):
)
saved_notification.personalisation = personalisation

redis_store.set(
f"email-personalisation-{saved_notification.id}",
json.dumps(personalisation),
ex=60 * 60,
)
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)
return jsonify({}), 204

Expand Down Expand Up @@ -487,6 +503,12 @@ def send_already_registered_email(user_id):

current_app.logger.info("Sending notification to queue")

redis_store.set(
f"email-personalisation-{saved_notification.id}",
json.dumps(personalisation),
ex=60 * 60,
)

send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

current_app.logger.info("Sent notification to queue")
Expand Down Expand Up @@ -614,6 +636,11 @@ def send_user_reset_password():
)
saved_notification.personalisation = personalisation

redis_store.set(
f"email-personalisation-{saved_notification.id}",
json.dumps(personalisation),
ex=60 * 60,
)
send_notification_to_queue(saved_notification, queue=QueueNames.NOTIFY)

return jsonify({}), 204
Expand Down

0 comments on commit 30ecc21

Please sign in to comment.