mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 22:39:43 -04:00
Set job notifications reply_to_text from the template.reply_to
When creating notification objects from the job sets the reply_to_text from template's reply_to if it's present. Otherwise uses the service default.
This commit is contained in:
@@ -203,6 +203,7 @@ def save_sms(self,
|
|||||||
key_type=KEY_TYPE_NORMAL):
|
key_type=KEY_TYPE_NORMAL):
|
||||||
notification = encryption.decrypt(encrypted_notification)
|
notification = encryption.decrypt(encrypted_notification)
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
|
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||||
|
|
||||||
if not service_allowed_to_send_to(notification['to'], service, key_type):
|
if not service_allowed_to_send_to(notification['to'], service, key_type):
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
@@ -224,7 +225,7 @@ def save_sms(self,
|
|||||||
job_id=notification.get('job', None),
|
job_id=notification.get('job', None),
|
||||||
job_row_number=notification.get('row_number', None),
|
job_row_number=notification.get('row_number', None),
|
||||||
notification_id=notification_id,
|
notification_id=notification_id,
|
||||||
reply_to_text=service.get_default_sms_sender()
|
reply_to_text=template.get_reply_to_text()
|
||||||
)
|
)
|
||||||
|
|
||||||
provider_tasks.deliver_sms.apply_async(
|
provider_tasks.deliver_sms.apply_async(
|
||||||
@@ -252,7 +253,9 @@ def save_email(self,
|
|||||||
api_key_id=None,
|
api_key_id=None,
|
||||||
key_type=KEY_TYPE_NORMAL):
|
key_type=KEY_TYPE_NORMAL):
|
||||||
notification = encryption.decrypt(encrypted_notification)
|
notification = encryption.decrypt(encrypted_notification)
|
||||||
|
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
|
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||||
|
|
||||||
if not service_allowed_to_send_to(notification['to'], service, key_type):
|
if not service_allowed_to_send_to(notification['to'], service, key_type):
|
||||||
current_app.logger.info("Email {} failed as restricted service".format(notification_id))
|
current_app.logger.info("Email {} failed as restricted service".format(notification_id))
|
||||||
@@ -272,7 +275,7 @@ def save_email(self,
|
|||||||
job_id=notification.get('job', None),
|
job_id=notification.get('job', None),
|
||||||
job_row_number=notification.get('row_number', None),
|
job_row_number=notification.get('row_number', None),
|
||||||
notification_id=notification_id,
|
notification_id=notification_id,
|
||||||
reply_to_text=service.get_default_reply_to_email_address()
|
reply_to_text=template.get_reply_to_text()
|
||||||
)
|
)
|
||||||
|
|
||||||
provider_tasks.deliver_email.apply_async(
|
provider_tasks.deliver_email.apply_async(
|
||||||
@@ -299,6 +302,8 @@ def save_letter(
|
|||||||
recipient = notification['personalisation']['addressline1']
|
recipient = notification['personalisation']['addressline1']
|
||||||
|
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
|
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
saved_notification = persist_notification(
|
saved_notification = persist_notification(
|
||||||
template_id=notification['template'],
|
template_id=notification['template'],
|
||||||
@@ -314,7 +319,7 @@ def save_letter(
|
|||||||
job_row_number=notification['row_number'],
|
job_row_number=notification['row_number'],
|
||||||
notification_id=notification_id,
|
notification_id=notification_id,
|
||||||
reference=create_random_identifier(),
|
reference=create_random_identifier(),
|
||||||
reply_to_text=service.get_default_letter_contact()
|
reply_to_text=template.get_reply_to_text()
|
||||||
)
|
)
|
||||||
|
|
||||||
if service.has_permission('letters_as_pdf'):
|
if service.has_permission('letters_as_pdf'):
|
||||||
|
|||||||
@@ -1040,6 +1040,47 @@ def test_save_letter_saves_letter_to_database(mocker, notify_db_session):
|
|||||||
assert notification_db.reply_to_text == "Address contact"
|
assert notification_db.reply_to_text == "Address contact"
|
||||||
|
|
||||||
|
|
||||||
|
def test_save_letter_uses_template_reply_to_text(mocker, notify_db_session):
|
||||||
|
service = create_service()
|
||||||
|
create_letter_contact(service=service, contact_block="Address contact", is_default=True)
|
||||||
|
template_contact = create_letter_contact(
|
||||||
|
service=service,
|
||||||
|
contact_block="Template address contact",
|
||||||
|
is_default=False
|
||||||
|
)
|
||||||
|
template = create_template(
|
||||||
|
service=service,
|
||||||
|
template_type=LETTER_TYPE,
|
||||||
|
reply_to=template_contact.id
|
||||||
|
)
|
||||||
|
|
||||||
|
job = create_job(template=template)
|
||||||
|
|
||||||
|
mocker.patch('app.celery.tasks.create_random_identifier', return_value="this-is-random-in-real-life")
|
||||||
|
|
||||||
|
personalisation = {
|
||||||
|
'addressline1': 'Foo',
|
||||||
|
'addressline2': 'Bar',
|
||||||
|
'postcode': 'Flob',
|
||||||
|
}
|
||||||
|
notification_json = _notification_json(
|
||||||
|
template=job.template,
|
||||||
|
to='Foo',
|
||||||
|
personalisation=personalisation,
|
||||||
|
job_id=job.id,
|
||||||
|
row_number=1
|
||||||
|
)
|
||||||
|
|
||||||
|
save_letter(
|
||||||
|
job.service_id,
|
||||||
|
uuid.uuid4(),
|
||||||
|
encryption.encrypt(notification_json),
|
||||||
|
)
|
||||||
|
|
||||||
|
notification_db = Notification.query.one()
|
||||||
|
assert notification_db.reply_to_text == "Template address contact"
|
||||||
|
|
||||||
|
|
||||||
def test_save_letter_calls_update_noti_to_sent_task_with_letters_as_pdf_permission_in_research_mode(
|
def test_save_letter_calls_update_noti_to_sent_task_with_letters_as_pdf_permission_in_research_mode(
|
||||||
mocker, notify_db_session, sample_letter_job):
|
mocker, notify_db_session, sample_letter_job):
|
||||||
sample_letter_job.service.research_mode = True
|
sample_letter_job.service.research_mode = True
|
||||||
|
|||||||
Reference in New Issue
Block a user