Send verifcation email to a new reply-to email address

This commit is contained in:
Pea Tyczynska
2019-05-10 15:32:24 +01:00
parent c8a8a614a6
commit 615ea6a98a
4 changed files with 66 additions and 2 deletions

View File

@@ -150,6 +150,7 @@ class Config(object):
ORGANISATION_INVITATION_EMAIL_TEMPLATE_ID = '203566f0-d835-47c5-aa06-932439c86573'
TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID = 'c73f1d71-4049-46d5-a647-d013bdeca3f0'
TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID = '8a31520f-4751-4789-8ea1-fe54496725eb'
REPLY_TO_EMAIL_ADDRESS_VERIFICATION_TEMPLATE_ID = '2d1ff26c-4d20-4cb2-8918-a0bec4002c9e'
BROKER_URL = 'sqs://'
BROKER_TRANSPORT_OPTIONS = {

View File

@@ -12,6 +12,7 @@ from notifications_utils.timezones import convert_utc_to_bst
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound
from app.config import QueueNames
from app.dao import notifications_dao
from app.dao.dao_utils import dao_rollback
from app.dao.date_util import get_financial_year
@@ -77,13 +78,17 @@ from app.dao.service_letter_contact_dao import (
add_letter_contact_for_service,
update_letter_contact
)
from app.dao.templates_dao import dao_get_template_by_id
from app.dao.users_dao import get_user_by_id
from app.errors import (
InvalidRequest,
register_errors
)
from app.letters.utils import letter_print_day
from app.models import LETTER_TYPE, NOTIFICATION_CANCELLED, Permission, Service, EmailBranding, LetterBranding
from app.models import (
KEY_TYPE_NORMAL, LETTER_TYPE, NOTIFICATION_CANCELLED, Permission, Service, EmailBranding, LetterBranding
)
from app.notifications.process_notifications import persist_notification, send_notification_to_queue
from app.schema_validation import validate
from app.service import statistics
from app.service.service_data_retention_schema import (
@@ -103,7 +108,8 @@ from app.schemas import (
api_key_schema,
notification_with_template_schema,
notifications_filter_schema,
detailed_service_schema
detailed_service_schema,
email_data_request_schema
)
from app.user.users_schema import post_set_permissions_schema
from app.utils import pagination_links
@@ -644,6 +650,28 @@ def get_email_reply_to_address(service_id, reply_to_id):
return jsonify(result.serialize()), 200
@service_blueprint.route('/email-reply-to/verify', methods=['POST'])
def verify_new_service_reply_to_email_address():
email_address, errors = email_data_request_schema.load(request.get_json())
template = dao_get_template_by_id(current_app.config['REPLY_TO_EMAIL_ADDRESS_VERIFICATION_TEMPLATE_ID'])
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
saved_notification = persist_notification(
template_id=template.id,
template_version=template.version,
recipient=email_address["email"],
service=service,
personalisation='',
notification_type=template.template_type,
api_key_id=None,
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)
return jsonify(data={"id": saved_notification.id}), 201
@service_blueprint.route('/<uuid:service_id>/email-reply-to', methods=['POST'])
def add_service_reply_to_email_address(service_id):
# validate the service exists, throws ResultNotFound exception.