mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 18:23:01 -04:00
Create a new task called send_email_v2 so that I can get rid of the from_address in the signature.
This is done to make sure we do not lose any messages in the queue during deployment.
This commit is contained in:
+8
-4
@@ -180,7 +180,7 @@ def process_job(job_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if template.template_type == 'email':
|
if template.template_type == 'email':
|
||||||
send_email.apply_async((
|
send_email_v2.apply_async((
|
||||||
str(job.service_id),
|
str(job.service_id),
|
||||||
create_uuid(),
|
create_uuid(),
|
||||||
'',
|
'',
|
||||||
@@ -290,6 +290,11 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
|||||||
|
|
||||||
@notify_celery.task(name="send-email")
|
@notify_celery.task(name="send-email")
|
||||||
def send_email(service_id, notification_id, from_address, encrypted_notification, created_at, reply_to_addresses=None):
|
def send_email(service_id, notification_id, from_address, encrypted_notification, created_at, reply_to_addresses=None):
|
||||||
|
send_email_v2(service_id, notification_id, encrypted_notification, created_at, reply_to_addresses=None)
|
||||||
|
|
||||||
|
|
||||||
|
@notify_celery.task(name="send-email-v2")
|
||||||
|
def send_email_v2(service_id, notification_id, encrypted_notification, created_at, reply_to_addresses=None):
|
||||||
task_start = monotonic()
|
task_start = monotonic()
|
||||||
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)
|
||||||
@@ -337,9 +342,8 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
|
|||||||
(provider.get_name(), str(reference), notification['to']), queue='research-mode'
|
(provider.get_name(), str(reference), notification['to']), queue='research-mode'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# First step setting the from_address here rather than the method creating the task
|
from_address = '"{}" <{}@{}>'.format(service.name, service.email_from,
|
||||||
from_address = '"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config[
|
current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||||
'NOTIFY_EMAIL_DOMAIN']) if from_address == "" else from_address
|
|
||||||
reference = provider.send_email(
|
reference = provider.send_email(
|
||||||
from_address,
|
from_address,
|
||||||
notification['to'],
|
notification['to'],
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ from app.schemas import (
|
|||||||
day_schema,
|
day_schema,
|
||||||
unarchived_template_schema
|
unarchived_template_schema
|
||||||
)
|
)
|
||||||
from app.celery.tasks import send_sms, send_email
|
from app.celery.tasks import send_sms, send_email_v2
|
||||||
|
|
||||||
notifications = Blueprint('notifications', __name__)
|
notifications = Blueprint('notifications', __name__)
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ def send_notification(notification_type):
|
|||||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||||
), queue='sms')
|
), queue='sms')
|
||||||
else:
|
else:
|
||||||
send_email.apply_async((
|
send_email_v2.apply_async((
|
||||||
service_id,
|
service_id,
|
||||||
notification_id,
|
notification_id,
|
||||||
'',
|
'',
|
||||||
|
|||||||
+2
-4
@@ -28,8 +28,7 @@ from app.schemas import (
|
|||||||
from app.celery.tasks import (
|
from app.celery.tasks import (
|
||||||
send_sms,
|
send_sms,
|
||||||
email_reset_password,
|
email_reset_password,
|
||||||
email_registration_verification,
|
send_email_v2)
|
||||||
send_email)
|
|
||||||
|
|
||||||
from app.errors import register_errors
|
from app.errors import register_errors
|
||||||
|
|
||||||
@@ -167,10 +166,9 @@ def send_user_email_verification(user_id):
|
|||||||
'url': _create_verification_url(user_to_send_to, secret_code)
|
'url': _create_verification_url(user_to_send_to, secret_code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
send_email.apply_async((
|
send_email_v2.apply_async((
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
str(uuid.uuid4()),
|
str(uuid.uuid4()),
|
||||||
'',
|
|
||||||
encryption.encrypt(message),
|
encryption.encrypt(message),
|
||||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||||
), queue='email-registration-verification')
|
), queue='email-registration-verification')
|
||||||
|
|||||||
@@ -775,7 +775,7 @@ def test_create_email_should_reject_if_missing_required_fields(notify_api, sampl
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email_v2.apply_async.assert_not_called()
|
||||||
assert json_resp['result'] == 'error'
|
assert json_resp['result'] == 'error'
|
||||||
assert 'Missing data for required field.' in json_resp['message']['to'][0]
|
assert 'Missing data for required field.' in json_resp['message']['to'][0]
|
||||||
assert 'Missing data for required field.' in json_resp['message']['template'][0]
|
assert 'Missing data for required field.' in json_resp['message']['template'][0]
|
||||||
@@ -799,7 +799,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
data = json.loads(response.get_data(as_text=True))
|
data = json.loads(response.get_data(as_text=True))
|
||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email_v2.apply_async.assert_not_called()
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert data['result'] == 'error'
|
assert data['result'] == 'error'
|
||||||
assert data['message']['to'][0] == 'Not a valid email address'
|
assert data['message']['to'][0] == 'Not a valid email address'
|
||||||
@@ -822,7 +822,7 @@ def test_should_reject_email_notification_with_template_id_that_cant_be_found(
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
data = json.loads(response.get_data(as_text=True))
|
data = json.loads(response.get_data(as_text=True))
|
||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email_v2.apply_async.assert_not_called()
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
assert data['result'] == 'error'
|
assert data['result'] == 'error'
|
||||||
test_string = 'No result found'
|
test_string = 'No result found'
|
||||||
@@ -854,7 +854,7 @@ def test_should_not_allow_email_template_from_another_service(notify_api, servic
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email_v2.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
test_string = 'No result found'
|
test_string = 'No result found'
|
||||||
@@ -882,7 +882,7 @@ def test_should_not_send_email_if_restricted_and_not_a_service_user(notify_api,
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email_v2.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
||||||
@@ -914,7 +914,7 @@ def test_should_not_send_email_for_job_if_restricted_and_not_a_service_user(
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
app.celery.tasks.send_email.apply_async.assert_not_called()
|
app.celery.tasks.send_email_v2.apply_async.assert_not_called()
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
assert 'Invalid email address for restricted service' in json_resp['message']['to']
|
||||||
@@ -943,7 +943,7 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template
|
|||||||
assert app.encryption.encrypt.call_args[0][0]['to'] == 'ok@ok.com'
|
assert app.encryption.encrypt.call_args[0][0]['to'] == 'ok@ok.com'
|
||||||
assert app.encryption.encrypt.call_args[0][0]['template'] == str(sample_email_template.id)
|
assert app.encryption.encrypt.call_args[0][0]['template'] == str(sample_email_template.id)
|
||||||
assert app.encryption.encrypt.call_args[0][0]['template_version'] == sample_email_template.version
|
assert app.encryption.encrypt.call_args[0][0]['template_version'] == sample_email_template.version
|
||||||
app.celery.tasks.send_email.apply_async.assert_called_once_with(
|
app.celery.tasks.send_email_v2.apply_async.assert_called_once_with(
|
||||||
(str(sample_email_template.service_id),
|
(str(sample_email_template.service_id),
|
||||||
notification_id,
|
notification_id,
|
||||||
"",
|
"",
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ def test_send_user_email_verification(notify_api,
|
|||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
headers=[('Content-Type', 'application/json'), auth_header])
|
||||||
assert resp.status_code == 204
|
assert resp.status_code == 204
|
||||||
assert mocked.call_count == 1
|
assert mocked.call_count == 1
|
||||||
app.celery.tasks.send_email.apply_async.assert_called_once_with(
|
app.celery.tasks.send_email_v2.apply_async.assert_called_once_with(
|
||||||
(str(current_app.config['NOTIFY_SERVICE_ID']),
|
(str(current_app.config['NOTIFY_SERVICE_ID']),
|
||||||
'some_uuid',
|
'some_uuid',
|
||||||
'',
|
'',
|
||||||
|
|||||||
Reference in New Issue
Block a user