mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Send email invitation to invited user
This commit is contained in:
@@ -161,11 +161,20 @@ def send_email_code(encrypted_verification_message):
|
||||
# TODO: when placeholders in templates work, this will be a real template
|
||||
def invitation_template(user_name, service_name, url, expiry_date):
|
||||
from string import Template
|
||||
t = Template('You are invited to use GOV.UK Notify by $user_name for service $service_name.'
|
||||
' The url to join is $url. This url will expire on $expiry_date')
|
||||
t = Template(
|
||||
'$user_name has invited you to collaborate on $service_name on GOV.UK Notify.\n\n'
|
||||
'GOV.UK Notify makes it easy to keep people updated, by helping you send text messages, emails and letters.\n\n'
|
||||
'Click this link to create an account on GOV.UK Notify:\n$url\n\n'
|
||||
'This invitation will stop working at midnight tomorrow. This is to keep $service_name secure.')
|
||||
return t.substitute(user_name=user_name, service_name=service_name, url=url, expiry_date=expiry_date)
|
||||
|
||||
|
||||
def invitation_subject_line(user_name, service_name):
|
||||
from string import Template
|
||||
t = Template('$user_name has invited you to collaborate on $service_name on GOV.UK Notify')
|
||||
return t.substitute(user_name=user_name, service_name=service_name)
|
||||
|
||||
|
||||
def invited_user_url(base_url, token):
|
||||
return '{0}/invitation/{1}'.format(base_url, token)
|
||||
|
||||
@@ -180,7 +189,12 @@ def email_invited_user(encrypted_invitation):
|
||||
url,
|
||||
invitation['expiry_date'])
|
||||
try:
|
||||
aws_ses_client.send_email(current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
|
||||
email_from = "{}@{}".format(current_app.config['INVITATION_EMAIL_FROM'],
|
||||
current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||
current_app.logger.info('email_from: {} invitation_content: {} to: {}'.format(email_from,
|
||||
invitation_content,
|
||||
invitation['to']))
|
||||
aws_ses_client.send_email(email_from,
|
||||
invitation['to'],
|
||||
'Invitation to GOV.UK Notify',
|
||||
invitation_content)
|
||||
|
||||
@@ -6,6 +6,7 @@ from flask import (
|
||||
jsonify,
|
||||
current_app)
|
||||
|
||||
from app import encryption
|
||||
from app.dao.invited_user_dao import (
|
||||
save_invited_user,
|
||||
get_invited_user,
|
||||
@@ -13,7 +14,7 @@ from app.dao.invited_user_dao import (
|
||||
)
|
||||
|
||||
from app.schemas import invited_user_schema
|
||||
from app.celery.tasks import email_invited_user
|
||||
from app.celery.tasks import (email_invited_user)
|
||||
|
||||
invite = Blueprint('invite', __name__, url_prefix='/service/<service_id>/invite')
|
||||
|
||||
@@ -28,7 +29,8 @@ def create_invited_user(service_id):
|
||||
return jsonify(result="error", message=errors), 400
|
||||
save_invited_user(invited_user)
|
||||
invitation = _create_invitation(invited_user)
|
||||
email_invited_user.apply_async(encrypted_invitation=invitation, queue_name='email-invited-user')
|
||||
encrypted_invitation = encryption.encrypt(invitation)
|
||||
email_invited_user.apply_async([encrypted_invitation], queue='email-invited-user')
|
||||
return jsonify(data=invited_user_schema.dump(invited_user).data), 201
|
||||
|
||||
|
||||
@@ -61,6 +63,6 @@ def _create_invitation(invited_user):
|
||||
'service_id': str(invited_user.service_id),
|
||||
'service_name': invited_user.service.name,
|
||||
'token': token,
|
||||
'expiry_date': expiration_date
|
||||
'expiry_date': str(expiration_date)
|
||||
}
|
||||
return invitation
|
||||
|
||||
Reference in New Issue
Block a user