From 66a52655df9f5d6d5919a3a1a1791556f4e8ee03 Mon Sep 17 00:00:00 2001 From: beeankha Date: Tue, 12 Feb 2019 16:17:57 -0500 Subject: [PATCH] Change email notification success/fail messages and add a timeout feature --- awx/main/notifications/email_backend.py | 3 ++- .../src/notifications/add/add.controller.js | 7 ++++--- .../list.controller.js | 11 +++++++--- .../notificationTemplates.form.js | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/awx/main/notifications/email_backend.py b/awx/main/notifications/email_backend.py index 074e1f5142..6339519115 100644 --- a/awx/main/notifications/email_backend.py +++ b/awx/main/notifications/email_backend.py @@ -17,7 +17,8 @@ class CustomEmailBackend(EmailBackend): "use_tls": {"label": "Use TLS", "type": "bool"}, "use_ssl": {"label": "Use SSL", "type": "bool"}, "sender": {"label": "Sender Email", "type": "string"}, - "recipients": {"label": "Recipient List", "type": "list"}} + "recipients": {"label": "Recipient List", "type": "list"}, + "timeout": {"label": "Timeout", "type": "int"}} recipient_parameter = "recipients" sender_parameter = "sender" diff --git a/awx/ui/client/src/notifications/add/add.controller.js b/awx/ui/client/src/notifications/add/add.controller.js index 8bb236eb06..7093a80680 100644 --- a/awx/ui/client/src/notifications/add/add.controller.js +++ b/awx/ui/client/src/notifications/add/add.controller.js @@ -122,7 +122,6 @@ export default ['Rest', 'Wait', 'NotificationsFormObject', $scope.notification_template_form[subFldName].$setPristine(); } } else { - $scope[fld] = null; $scope.notification_template_form[fld].$setPristine(); } } @@ -200,10 +199,12 @@ export default ['Rest', 'Wait', 'NotificationsFormObject', if (field.type === 'number') { $scope[i] = Number($scope[i]); } - if (i === "username" && $scope.notification_type.value === "email" && value === null) { + if (i === "username" && $scope.notification_type.value === "email" && (value === null || !value + )) { $scope[i] = ""; } - if (field.type === 'sensitive' && value === null) { + if (field.type === 'sensitive' && (value === null || !value + )) { $scope[i] = ""; } return $scope[i]; diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index 2fd571a740..8e5e4f1c2a 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -117,7 +117,7 @@ $scope.testNotification = function() { var name = $filter('sanitize')(this.notification_template.name), - pending_retries = 10; + pending_retries = 25; Rest.setUrl(defaultUrl + this.notification_template.id + '/test/'); Rest.post({}) @@ -131,7 +131,7 @@ } else { ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Call to notifcatin templates failed. Notification returned status: ' + status + msg: 'Call to notification templates failed. Notification returned status: ' + status }); } }) @@ -152,9 +152,14 @@ content: ` ${name}: Notification sent.` }); $state.reload(); + } else if (res && res.data && res.data.status && res.data.status === "failed" && res.data.error === "timed out") { + ngToast.danger({ + content: `
${name}: ${i18n._("Notification timed out.")}
` + }); + $state.reload(); } else if (res && res.data && res.data.status && res.data.status === "failed") { ngToast.danger({ - content: ` ${name}: Notification failed.` + content: `
${name}: Notification failed.
${res.data.error}
` }); $state.reload(); } else if (res && res.data && res.data.status && res.data.status === "pending" && pending_retries > 0) { diff --git a/awx/ui/client/src/notifications/notificationTemplates.form.js b/awx/ui/client/src/notifications/notificationTemplates.form.js index d97f171f7e..af32a6a186 100644 --- a/awx/ui/client/src/notifications/notificationTemplates.form.js +++ b/awx/ui/client/src/notifications/notificationTemplates.form.js @@ -132,6 +132,26 @@ export default ['i18n', function(i18n) { subForm: 'typeSubForm', ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' }, + timeout: { + label: i18n._('Timeout'), + type: 'number', + integer: true, + default: 30, + min: 1, + max: 120, + spinner: true, + dataTitle: i18n._('Timeout'), + dataPlacement: 'right', + dataContainer: 'body', + awRequiredWhen: { + reqExpression: "email_required", + init: "false" + }, + awPopOver: "

" + i18n._("The amount of time (in seconds) before the email notification stops trying to reach the host and times out. Ranges from 1 to 120 seconds.") + "

", + ngShow: "notification_type.value == 'email' ", + subForm: 'typeSubForm', + ngDisabled: '!(notification_template.summary_fields.user_capabilities.edit || canAdd)' + }, channels: { label: i18n._('Destination Channels'), type: 'textarea',