From bc3f08bb4a1bf8f1d59be5e783fe8e48cfcc0fba Mon Sep 17 00:00:00 2001 From: Dale Smith Date: Wed, 16 Mar 2016 15:54:47 +0000 Subject: [PATCH] Updated email templates and made them configurable in /etc. Change-Id: I4dbce8f179511a779594fe2b05640c003005c813 --- conf/conf.yaml | 8 ++--- .../templates/initial_password_completed.txt | 9 +++-- .../v1/templates/initial_password_token.txt | 11 +++--- .../v1/templates/invite_user_completed.txt | 10 +++--- .../api/v1/templates/invite_user_token.txt | 19 ++++------ .../v1/templates/password_reset_completed.txt | 9 +++-- .../api/v1/templates/password_reset_token.txt | 13 ++++--- stacktask/api/v1/utils.py | 36 ++++++++++--------- stacktask/settings.py | 17 +++++++-- 9 files changed, 74 insertions(+), 58 deletions(-) diff --git a/conf/conf.yaml b/conf/conf.yaml index c36b50c..e07fd45 100644 --- a/conf/conf.yaml +++ b/conf/conf.yaml @@ -111,7 +111,7 @@ DEFAULT_TASK_SETTINGS: TASK_SETTINGS: create_project: # Additonal actions for views: - # - The order of the actions matters. These will run after the + # - The order of the actions matters. These will run after the # default action, in the given order. actions: - AddAdminToProject @@ -134,7 +134,7 @@ TASK_SETTINGS: # To not send this email, set the value to null initial: null token: - subject: Invitation to an OpenStack Project + subject: Invitation to an OpenStack project template: invite_user_token.txt completed: subject: Invitation Completed @@ -162,10 +162,10 @@ TASK_SETTINGS: emails: initial: null token: - subject: Setup Your OpenStack Password + subject: Set your OpenStack password template: initial_password_token.txt completed: - subject: New User Setup Completed + subject: Welcome to OpenStack! template: initial_password_completed.txt errors: SMTPException: diff --git a/stacktask/api/v1/templates/initial_password_completed.txt b/stacktask/api/v1/templates/initial_password_completed.txt index 1911ffe..ac61f65 100644 --- a/stacktask/api/v1/templates/initial_password_completed.txt +++ b/stacktask/api/v1/templates/initial_password_completed.txt @@ -1,5 +1,8 @@ -Hello, +Thank you for joining Openstack! -You have successfully setup your new OpenStack user and should be able to access the dashboard and APIs. +Your account is now active and you can access the dashboard and APIs. -Thank you for using our service. \ No newline at end of file +You can find examples and documentation on using Openstack at http://www.openstack.org/ + +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/templates/initial_password_token.txt b/stacktask/api/v1/templates/initial_password_token.txt index 4fcfa03..4d3b020 100644 --- a/stacktask/api/v1/templates/initial_password_token.txt +++ b/stacktask/api/v1/templates/initial_password_token.txt @@ -1,8 +1,11 @@ Hello, -You can setup your initial OpenStack user password by following this link: -{{ tokenurl }}{{ token }}/ +Almost there! -Once setup you will have access to the web dashboard. +Please follow this link to define your password to access Openstack: +{{ tokenurl }}{{ token }} -Thank you for using our service. \ No newline at end of file +Once this is done you will have access to the dashboard and APIs. + +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/templates/invite_user_completed.txt b/stacktask/api/v1/templates/invite_user_completed.txt index 1b0dff1..587990b 100644 --- a/stacktask/api/v1/templates/invite_user_completed.txt +++ b/stacktask/api/v1/templates/invite_user_completed.txt @@ -1,7 +1,7 @@ -Hello, +You have successfully joined the project '{{ task.keystone_user.project_name }}' on Openstack. -You have successfully completed your OpenStack project invitation. +You can switch projects on the dashboard via the project drop down list on the top menu. +When using the command line tools or APIs, you can define the project name and ID you want to connect to. -You should now have access to your new project via the dashboard and APIs. - -Thank you for using our service. \ No newline at end of file +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/templates/invite_user_token.txt b/stacktask/api/v1/templates/invite_user_token.txt index 5d7a08e..f52f862 100644 --- a/stacktask/api/v1/templates/invite_user_token.txt +++ b/stacktask/api/v1/templates/invite_user_token.txt @@ -1,15 +1,10 @@ -Hello, +You have been invited by {{ task.keystone_user.username }} to join the project '{{ task.keystone_user.project_name }}' on Openstack. +Please click on this link to accept the invitation: {{ tokenurl }}{{ token }} -Someone has invited you to join their OpenStack project. -Project id: {{ actions.NewUser.project_id }} -Roles:{% for role in actions.NewUser.roles %} -- {{ role }}{% endfor %} +New users will be asked to define a password when accepting the invitation. +Existing users will be added to the project and do not need to provide additional information. -To complete this invitation just follow this link: -{{ tokenurl }}{{ token }}/ +This link will expire automatically in 24 hours. If expired, you will need to request another one from the person who invited you. -If you are a new user you will just have to setup your password for a user with this email address, but if you already have a user, you simply have to confirm your invitation. - -This link will expire in 24 hours at which point you will need to request another one from the person who invited you. - -Thank you for using our service. +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/templates/password_reset_completed.txt b/stacktask/api/v1/templates/password_reset_completed.txt index 99b44bd..4ed406e 100644 --- a/stacktask/api/v1/templates/password_reset_completed.txt +++ b/stacktask/api/v1/templates/password_reset_completed.txt @@ -1,7 +1,6 @@ -Hello, +This email is to confirm that your Openstack account password has now been changed. -You have successfully reset your OpenStack user password. +If you did not request this password change, please get in touch with your systems administrator to report suspicious activity and secure your account. -If you did not request this reset get in touch with your infrastructure admins. - -Thank you for using our service. \ No newline at end of file +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/templates/password_reset_token.txt b/stacktask/api/v1/templates/password_reset_token.txt index b34491a..9fd950c 100644 --- a/stacktask/api/v1/templates/password_reset_token.txt +++ b/stacktask/api/v1/templates/password_reset_token.txt @@ -1,10 +1,13 @@ Hello, -To reset your OpenStack user password follow this link: -{{ tokenurl }}{{ token }}/ +We have received a request to reset your Openstack password. -This link will expire in 24 hours at which point you will need to request another one. +Please click the link below to reset your password: +{{ tokenurl }}{{ token }} -If you did not request this reset, either ignore this email and allow it to expire, or get in touch with your infrastructure admins if you are worried. +This link will expire automatically in 24 hours. If expired, you will need to request your password to be reset again. -Thank you for using our service. +If you did not request this password change, please get in touch with your systems administrator to report suspicious activity and secure your account. + +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/utils.py b/stacktask/api/v1/utils.py index c6a99be..0f319bf 100644 --- a/stacktask/api/v1/utils.py +++ b/stacktask/api/v1/utils.py @@ -48,13 +48,18 @@ def send_email(task, email_conf, token=None): if not email_conf: return - template = loader.get_template(email_conf['template']) + text_template = loader.get_template( + email_conf['template'], + using='include_etc_templates') html_template = email_conf.get('html_template', None) if html_template: - html_template = loader.get_template(html_template) + html_template = loader.get_template( + html_template, + using='include_etc_templates') emails = set() actions = {} + # find our set of emails and actions that require email for action in task.actions: act = action.get_action() email = act.get_email() @@ -71,27 +76,24 @@ def send_email(task, email_conf, token=None): create_notification(task, notes, error=True) return + context = { + 'task': task, + 'actions': actions + } if token: - context = { - 'task': task, - 'actions': actions, + context.update({ 'tokenurl': settings.TOKEN_SUBMISSION_URL, - 'token': token.token, - } - else: - context = {'task': task, 'actions': actions} + 'token': token.token + }) try: - message = template.render(context) + message = text_template.render(context) + html_message = None if html_template: html_message = html_template.render(context) - send_mail( - email_conf['subject'], message, email_conf['reply'], - [emails.pop()], fail_silently=False, html_message=html_message) - else: - send_mail( - email_conf['subject'], message, email_conf['reply'], - [emails.pop()], fail_silently=False) + send_mail( + email_conf['subject'], message, email_conf['reply'], + [emails.pop()], fail_silently=False, html_message=html_message) except SMTPException as e: notes = { 'errors': diff --git a/stacktask/settings.py b/stacktask/settings.py index 6688a7d..c192254 100644 --- a/stacktask/settings.py +++ b/stacktask/settings.py @@ -29,9 +29,6 @@ import yaml from stacktask.utils import setup_task_settings BASE_DIR = os.path.dirname(os.path.dirname(__file__)) - -TEMPLATE_DEBUG = True - # Application definition INSTALLED_APPS = ( @@ -82,6 +79,20 @@ USE_TZ = True STATIC_URL = '/static/' +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'NAME': 'default', + }, + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'DIRS': ['/etc/stacktask/templates/'], + 'NAME': 'include_etc_templates', + }, +] + # Setup of local settings data if 'test' in sys.argv: from stacktask import test_settings