Link to tasks panel in notifications

* Adjutant-UI now supports views for Tasks, we should link to
  it in the default notification templates.
* To make this possible, and other potential uses, deprecate
  the TOKEN_SUBMISSION_URL in favor of HORIZON_URL
* clean up some formatting issues with the notification template

Change-Id: I1419fafe94812e64a0b3984f9f38528ec67ac8e4
This commit is contained in:
Adrian Turjak 2017-09-28 18:03:35 +13:00
parent efdb2ae24d
commit 7a448a369e
7 changed files with 43 additions and 9 deletions

View File

@ -85,8 +85,17 @@ def send_stage_email(task, email_conf, token=None):
'actions': actions 'actions': actions
} }
if token: if token:
if settings.HORIZON_URL:
tokenurl = settings.HORIZON_URL
if not tokenurl.endswith('/'):
tokenurl += '/'
tokenurl += 'token/'
else:
tokenurl = settings.TOKEN_SUBMISSION_URL
if not tokenurl.endswith('/'):
tokenurl += '/'
context.update({ context.update({
'tokenurl': settings.TOKEN_SUBMISSION_URL, 'tokenurl': tokenurl,
'token': token.token 'token': token.token
}) })

View File

@ -32,3 +32,7 @@ class ActionNotFound(BaseException):
class SerializerMissingException(BaseException): class SerializerMissingException(BaseException):
""" Serializer configured but it does not exist """ """ Serializer configured but it does not exist """
class ConfirmationException(BaseException):
""" Missing or incorrect configuration value. """

View File

@ -70,6 +70,13 @@ class EmailNotification(NotificationEngine):
context = { context = {
'task': task, 'notification': notification} 'task': task, 'notification': notification}
if settings.HORIZON_URL:
task_url = settings.HORIZON_URL
if not task_url.endswith('/'):
task_url += '/'
task_url += 'management/tasks/'
context['task_url'] = task_url
if notification.error: if notification.error:
subject = "Error - %s notification" % task.task_type subject = "Error - %s notification" % task.task_type
else: else:

View File

@ -7,7 +7,7 @@ There is a task that needs some attention.
Related Task: Related Task:
uuid: {{ task.uuid }} uuid: {{ task.uuid }}
ip_address: {{ task.ip_address }} ip_address: {{ task.ip_address }}
keystone_user: {{ task.keystone_user }} keystone_user: {{ task.keystone_user|safe }}
project_id: {{ task.project_id }} project_id: {{ task.project_id }}
task_type: {{ task.task_type }} task_type: {{ task.task_type }}
cancelled: {{ task.cancelled }} cancelled: {{ task.cancelled }}
@ -17,11 +17,17 @@ created_on: {{ task.created_on }}
approved_on: {{ task.approved_on }} approved_on: {{ task.approved_on }}
completed_on: {{ task.completed_on }} completed_on: {{ task.completed_on }}
action_notes: action_notes:
{% for action, notes in task.action_notes.items %}- {{ action }} {% for action, notes in task.action_notes.items %}- {{ action|safe }}
{% for note in notes %} - {{ note }} {% for note in notes %} - {{ note|safe }}
{% endfor %}{% endfor %} {% endfor %}{% endfor %}
Notification details: Notification details:
uuid: {{ notification.uuid }} uuid: {{ notification.uuid }}
notes: notes:
{{ notification.notes }} {{ notification.notes|safe }}
{% if task_url %}
Task link:
{{ task_url }}{{ task.uuid }}
{% endif %}

View File

@ -27,6 +27,7 @@ import os
import sys import sys
import yaml import yaml
from adjutant.utils import setup_task_settings from adjutant.utils import setup_task_settings
from adjutant.exceptions import ConfirmationException
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Application definition # Application definition
@ -148,7 +149,14 @@ USERNAME_IS_EMAIL = CONFIG['USERNAME_IS_EMAIL']
# Keystone admin credentials: # Keystone admin credentials:
KEYSTONE = CONFIG['KEYSTONE'] KEYSTONE = CONFIG['KEYSTONE']
TOKEN_SUBMISSION_URL = CONFIG['TOKEN_SUBMISSION_URL'] TOKEN_SUBMISSION_URL = CONFIG.get('TOKEN_SUBMISSION_URL')
if TOKEN_SUBMISSION_URL:
print("'TOKEN_SUBMISSION_URL' is deprecated, use 'HORIZON_URL' instead")
HORIZON_URL = CONFIG.get('HORIZON_URL')
if not HORIZON_URL and not TOKEN_SUBMISSION_URL:
raise ConfirmationException("Must supply 'HORIZON_URL'")
TOKEN_EXPIRE_TIME = CONFIG['TOKEN_EXPIRE_TIME'] TOKEN_EXPIRE_TIME = CONFIG['TOKEN_EXPIRE_TIME']

View File

@ -71,7 +71,7 @@ KEYSTONE = {
'auth_url': "http://localhost:5000/v3", 'auth_url': "http://localhost:5000/v3",
} }
TOKEN_SUBMISSION_URL = 'http://localhost:8080/token/' HORIZON_URL = 'http://localhost:8080/'
TOKEN_EXPIRE_TIME = 24 TOKEN_EXPIRE_TIME = 24
@ -399,7 +399,7 @@ conf_dict = {
"DEFAULT_TASK_SETTINGS": DEFAULT_TASK_SETTINGS, "DEFAULT_TASK_SETTINGS": DEFAULT_TASK_SETTINGS,
"TASK_SETTINGS": TASK_SETTINGS, "TASK_SETTINGS": TASK_SETTINGS,
"DEFAULT_ACTION_SETTINGS": DEFAULT_ACTION_SETTINGS, "DEFAULT_ACTION_SETTINGS": DEFAULT_ACTION_SETTINGS,
"TOKEN_SUBMISSION_URL": TOKEN_SUBMISSION_URL, "HORIZON_URL": HORIZON_URL,
"TOKEN_EXPIRE_TIME": TOKEN_EXPIRE_TIME, "TOKEN_EXPIRE_TIME": TOKEN_EXPIRE_TIME,
"ROLES_MAPPING": ROLES_MAPPING, "ROLES_MAPPING": ROLES_MAPPING,
"PROJECT_QUOTA_SIZES": PROJECT_QUOTA_SIZES, "PROJECT_QUOTA_SIZES": PROJECT_QUOTA_SIZES,

View File

@ -56,7 +56,7 @@ KEYSTONE:
auth_url: http://localhost/identity/v3 auth_url: http://localhost/identity/v3
domain_id: default domain_id: default
TOKEN_SUBMISSION_URL: http://192.168.122.160:8080/token/ HORIZON_URL: http://localhost:8080/
# time for the token to expire in hours # time for the token to expire in hours
TOKEN_EXPIRE_TIME: 24 TOKEN_EXPIRE_TIME: 24