Send email invitation to invited user

This commit is contained in:
Rebecca Law
2016-02-29 15:56:00 +00:00
parent df278a8e6e
commit 3879350c12
8 changed files with 36 additions and 14 deletions

View File

@@ -30,8 +30,9 @@ export DELIVERY_CLIENT_USER_NAME='dev-notify-delivery'
export DELIVERY_CLIENT_SECRET='dev-notify-secret-key'
export FIRETEXT_API_KEY=[contact team member for api key]
export FIRETEXT_NUMBER="Firetext"
export INVITATION_EMAIL_FROM='invites@notifications.service.gov.uk'
export INVITATION_EXPIRATION_DAYS=2
export NOTIFY_EMAIL_DOMAIN='dev.notify.com'
export NOTIFY_EMAIL_DOMAIN='dev.notify.works'
export NOTIFY_JOB_QUEUE='[unique-to-environment]-notify-jobs-queue' # NOTE unique prefix
export NOTIFICATION_QUEUE_PREFIX='[unique-to-environment]-notification_development' # NOTE unique prefix
export SECRET_KEY='dev-notify-secret-key'

View File

@@ -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)

View File

@@ -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

View File

@@ -11,6 +11,7 @@ class Config(object):
DELIVERY_CLIENT_USER_NAME = os.environ['DELIVERY_CLIENT_USER_NAME']
DELIVERY_CLIENT_SECRET = os.environ['DELIVERY_CLIENT_SECRET']
INVITATION_EXPIRATION_DAYS = int(os.environ['INVITATION_EXPIRATION_DAYS'])
INVITATION_EMAIL_FROM = os.environ['INVITATION_EMAIL_FROM']
NOTIFY_APP_NAME = 'api'
NOTIFY_LOG_PATH = '/var/log/notify/application.log'
NOTIFY_JOB_QUEUE = os.environ['NOTIFY_JOB_QUEUE']

View File

@@ -7,6 +7,7 @@ export AWS_REGION='eu-west-1'
export DANGEROUS_SALT='dangerous-salt'
export DELIVERY_CLIENT_USER_NAME='dev-notify-delivery'
export DELIVERY_CLIENT_SECRET='dev-notify-secret-key'
export INVITATION_EMAIL_FROM='invites'
export INVITATION_EXPIRATION_DAYS=2
export NOTIFY_JOB_QUEUE='notify-jobs-queue-test'
export NOTIFICATION_QUEUE_PREFIX='notification_development-test'
@@ -18,4 +19,4 @@ export TWILIO_AUTH_TOKEN="test"
export TWILIO_NUMBER="test"
export FIRETEXT_API_KEY="Firetext"
export FIRETEXT_NUMBER="Firetext"
export NOTIFY_EMAIL_DOMAIN="test.notify.com"
export NOTIFY_EMAIL_DOMAIN="test.notify.work"

View File

@@ -3,4 +3,5 @@
set -e
source environment.sh
celery -A run_celery.notify_celery worker --loglevel=INFO --logfile=/var/log/notify/application.log --concurrency=4 -Q sms,sms-code,email-code,email,process-job,bulk-sms,bulk-email
celery -A run_celery.notify_celery worker --loglevel=INFO --logfile=/var/log/notify/application.log --concurrency=4 -Q sms,sms-code,email-code,email,process-job,bulk-sms,bulk-email,email-invited-user

View File

@@ -353,8 +353,9 @@ def test_email_invited_user_should_send_email(notify_api, mocker):
invitation['expiry_date'])
email_invited_user(encryption.encrypt(invitation))
aws_ses_client.send_email.assert_called_once_with(current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
email_from = "{}@{}".format(current_app.config['INVITATION_EMAIL_FROM'],
current_app.config['NOTIFY_EMAIL_DOMAIN'])
aws_ses_client.send_email.assert_called_once_with(email_from,
invitation['to'],
'Invitation to GOV.UK Notify',
expected_content)

View File

@@ -3,6 +3,7 @@ import uuid
from datetime import datetime, timedelta
from app import encryption
from tests import create_authorization_header
import app.celery.tasks
@@ -50,11 +51,11 @@ def test_create_invited_user(notify_api, sample_service, mocker):
'service_id': str(sample_service.id),
'service_name': sample_service.name,
'token': 'the-token',
'expiry_date': expiry_date
'expiry_date': str(expiry_date)
}
app.celery.tasks.email_invited_user.apply_async.assert_called_once_with(
encrypted_invitation=encrypted_invitation,
queue_name='email-invited-user')
[encryption.encrypt(encrypted_invitation)],
queue='email-invited-user')
def test_create_invited_user_invalid_email(notify_api, sample_service, mocker):