mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Respect template’s redaction preference
If a template has the `redact_personalisation` flag set, then this commit removes the personalisation from the notification before rehydrating the template. We’re doing this because we have a need to not show things like one time passwords or two factor codes when we show the content of messages. By passing through empty personalisation, and the `redact_missing` flag, the `Template` instance will make use of the work done in: - [x] https://github.com/alphagov/notifications-utils/pull/171
This commit is contained in:
@@ -390,12 +390,29 @@ def get_job_partials(job):
|
||||
|
||||
|
||||
def add_preview_of_content_to_notifications(notifications):
|
||||
|
||||
for notification in notifications:
|
||||
yield dict(
|
||||
preview_of_content=(
|
||||
str(Template(notification['template'], notification['personalisation']))
|
||||
if notification['template']['template_type'] == 'sms' else
|
||||
WithSubjectTemplate(notification['template'], notification['personalisation']).subject
|
||||
),
|
||||
**notification
|
||||
)
|
||||
|
||||
if notification['template'].get('redact_personalisation'):
|
||||
notification['personalisation'] = {}
|
||||
|
||||
if notification['template']['template_type'] == 'sms':
|
||||
yield dict(
|
||||
preview_of_content=str(Template(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
redact_missing_personalisation=True,
|
||||
)),
|
||||
**notification
|
||||
)
|
||||
else:
|
||||
yield dict(
|
||||
preview_of_content=(
|
||||
WithSubjectTemplate(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
redact_missing_personalisation=True,
|
||||
).subject
|
||||
),
|
||||
**notification
|
||||
)
|
||||
|
||||
@@ -56,6 +56,7 @@ def view_notification(service_id, notification_id):
|
||||
filetype='png',
|
||||
),
|
||||
show_recipient=True,
|
||||
redact_missing_personalisation=True,
|
||||
)
|
||||
template.values = get_all_personalisation_from_notification(notification)
|
||||
if notification['job']:
|
||||
@@ -109,15 +110,21 @@ def get_single_notification_partials(notification):
|
||||
|
||||
|
||||
def get_all_personalisation_from_notification(notification):
|
||||
|
||||
if notification['template'].get('redact_personalisation'):
|
||||
notification['personalisation'] = {}
|
||||
|
||||
if notification['template']['template_type'] == 'email':
|
||||
return dict(
|
||||
email_address=notification['to'],
|
||||
**notification['personalisation']
|
||||
)
|
||||
|
||||
if notification['template']['template_type'] == 'sms':
|
||||
return dict(
|
||||
phone_number=notification['to'],
|
||||
**notification['personalisation']
|
||||
)
|
||||
|
||||
if notification['template']['template_type'] == 'letter':
|
||||
return notification['personalisation']
|
||||
|
||||
Reference in New Issue
Block a user