mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 16:53:42 -04:00
Update invite user endpoint to set the reply_to_text on the notification.
Update v1 post notifications to set the reply_to_text on the notification.
This commit is contained in:
@@ -42,7 +42,8 @@ def create_invited_user(service_id):
|
|||||||
},
|
},
|
||||||
notification_type=EMAIL_TYPE,
|
notification_type=EMAIL_TYPE,
|
||||||
api_key_id=None,
|
api_key_id=None,
|
||||||
key_type=KEY_TYPE_NORMAL
|
key_type=KEY_TYPE_NORMAL,
|
||||||
|
reply_to_text=service.get_default_reply_to_email_address()
|
||||||
)
|
)
|
||||||
|
|
||||||
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
|
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ def send_notification(notification_type):
|
|||||||
|
|
||||||
if notification_type == SMS_TYPE:
|
if notification_type == SMS_TYPE:
|
||||||
_service_can_send_internationally(authenticated_service, notification_form['to'])
|
_service_can_send_internationally(authenticated_service, notification_form['to'])
|
||||||
|
reply_to = get_reply_to_text(notification_type)
|
||||||
# Do not persist or send notification to the queue if it is a simulated recipient
|
# Do not persist or send notification to the queue if it is a simulated recipient
|
||||||
simulated = simulated_recipient(notification_form['to'], notification_type)
|
simulated = simulated_recipient(notification_form['to'], notification_type)
|
||||||
notification_model = persist_notification(template_id=template.id,
|
notification_model = persist_notification(template_id=template.id,
|
||||||
@@ -130,7 +130,9 @@ def send_notification(notification_type):
|
|||||||
notification_type=notification_type,
|
notification_type=notification_type,
|
||||||
api_key_id=api_user.id,
|
api_key_id=api_user.id,
|
||||||
key_type=api_user.key_type,
|
key_type=api_user.key_type,
|
||||||
simulated=simulated)
|
simulated=simulated,
|
||||||
|
reply_to_text=reply_to
|
||||||
|
)
|
||||||
if not simulated:
|
if not simulated:
|
||||||
queue_name = QueueNames.PRIORITY if template.process_type == PRIORITY else None
|
queue_name = QueueNames.PRIORITY if template.process_type == PRIORITY else None
|
||||||
send_notification_to_queue(notification=notification_model,
|
send_notification_to_queue(notification=notification_model,
|
||||||
@@ -148,6 +150,16 @@ def send_notification(notification_type):
|
|||||||
), 201
|
), 201
|
||||||
|
|
||||||
|
|
||||||
|
def get_reply_to_text(notification_type):
|
||||||
|
if notification_type == EMAIL_TYPE:
|
||||||
|
return authenticated_service.get_default_reply_to_email_address()
|
||||||
|
if notification_type == SMS_TYPE:
|
||||||
|
return authenticated_service.get_default_sms_sender()
|
||||||
|
if notification_type == LETTER_TYPE:
|
||||||
|
return authenticated_service.get_default_letter_contact()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_notification_return_data(notification_id, notification, template):
|
def get_notification_return_data(notification_id, notification, template):
|
||||||
output = {
|
output = {
|
||||||
'body': str(template),
|
'body': str(template),
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ from app.models import (
|
|||||||
ServiceWhitelist,
|
ServiceWhitelist,
|
||||||
KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM,
|
KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM,
|
||||||
MOBILE_TYPE, EMAIL_TYPE, INBOUND_SMS_TYPE, SMS_TYPE, LETTER_TYPE, NOTIFICATION_STATUS_TYPES_COMPLETED,
|
MOBILE_TYPE, EMAIL_TYPE, INBOUND_SMS_TYPE, SMS_TYPE, LETTER_TYPE, NOTIFICATION_STATUS_TYPES_COMPLETED,
|
||||||
SERVICE_PERMISSION_TYPES)
|
SERVICE_PERMISSION_TYPES, ServiceEmailReplyTo
|
||||||
|
)
|
||||||
from app.dao.users_dao import (create_user_code, create_secret_code)
|
from app.dao.users_dao import (create_user_code, create_secret_code)
|
||||||
from app.dao.services_dao import (dao_create_service, dao_add_user_to_service)
|
from app.dao.services_dao import (dao_create_service, dao_add_user_to_service)
|
||||||
from app.dao.templates_dao import dao_create_template
|
from app.dao.templates_dao import dao_create_template
|
||||||
@@ -985,17 +986,26 @@ def notify_service(notify_db, notify_db_session):
|
|||||||
user = create_user()
|
user = create_user()
|
||||||
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
|
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
|
||||||
if not service:
|
if not service:
|
||||||
|
service = Service(
|
||||||
|
name='Notify Service',
|
||||||
|
message_limit=1000,
|
||||||
|
restricted=False,
|
||||||
|
email_from='notify.service',
|
||||||
|
created_by=user,
|
||||||
|
prefix_sms=False,
|
||||||
|
)
|
||||||
|
dao_create_service(service=service, service_id=current_app.config['NOTIFY_SERVICE_ID'], user=user)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': current_app.config['NOTIFY_SERVICE_ID'],
|
'service': service,
|
||||||
'name': 'Notify Service',
|
'email_address': "notify@gov.uk",
|
||||||
'message_limit': 1000,
|
'is_default': True,
|
||||||
'active': True,
|
|
||||||
'restricted': False,
|
|
||||||
'email_from': 'notify.service',
|
|
||||||
'created_by': user,
|
|
||||||
}
|
}
|
||||||
service = Service(**data)
|
reply_to = ServiceEmailReplyTo(**data)
|
||||||
db.session.add(service)
|
|
||||||
|
db.session.add(reply_to)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
return service, user
|
return service, user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ def test_create_invited_user(admin_request, sample_service, mocker, invitation_e
|
|||||||
assert json_resp['data']['id']
|
assert json_resp['data']['id']
|
||||||
|
|
||||||
notification = Notification.query.first()
|
notification = Notification.query.first()
|
||||||
|
assert notification.reply_to_text == "notify@gov.uk"
|
||||||
mocked.assert_called_once_with([(str(notification.id))], queue="notify-internal-tasks")
|
mocked.assert_called_once_with([(str(notification.id))], queue="notify-internal-tasks")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from tests.app.conftest import (
|
|||||||
|
|
||||||
from app.models import Template
|
from app.models import Template
|
||||||
from app.errors import InvalidRequest
|
from app.errors import InvalidRequest
|
||||||
|
from tests.app.db import create_service, create_reply_to_email
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('template_type',
|
@pytest.mark.parametrize('template_type',
|
||||||
@@ -1219,3 +1220,34 @@ def test_should_throw_exception_if_notification_type_is_invalid(client, sample_s
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert json.loads(response.get_data(as_text=True))["message"] == err_msg
|
assert json.loads(response.get_data(as_text=True))["message"] == err_msg
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("notification_type, recipient",
|
||||||
|
[("sms", '07700 900 855'),
|
||||||
|
("email", "test@gov.uk")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_post_notification_should_set_reply_to_text(client, notify_db, notify_db_session, mocker, notification_type,
|
||||||
|
recipient):
|
||||||
|
mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
|
||||||
|
service = create_service()
|
||||||
|
template = create_sample_template(notify_db=notify_db, notify_db_session=notify_db_session,
|
||||||
|
service=service, template_type=notification_type)
|
||||||
|
expected_reply_to = current_app.config['FROM_NUMBER']
|
||||||
|
if notification_type == EMAIL_TYPE:
|
||||||
|
expected_reply_to = 'reply_to@gov.uk'
|
||||||
|
create_reply_to_email(service=service, email_address=expected_reply_to, is_default=True)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'to': recipient,
|
||||||
|
'template': str(template.id)
|
||||||
|
}
|
||||||
|
response = client.post("/notifications/{}".format(notification_type),
|
||||||
|
data=json.dumps(data),
|
||||||
|
headers=[('Content-Type', 'application/json'),
|
||||||
|
create_authorization_header(service_id=service.id)]
|
||||||
|
)
|
||||||
|
assert response.status_code == 201
|
||||||
|
notifications = Notification.query.all()
|
||||||
|
assert len(notifications) == 1
|
||||||
|
assert notifications[0].reply_to_text == expected_reply_to
|
||||||
|
|||||||
Reference in New Issue
Block a user