diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js index 5f0330b4b2..18c5bf2eee 100644 --- a/awx/ui/client/src/shared/form-generator.js +++ b/awx/ui/client/src/shared/form-generator.js @@ -794,9 +794,21 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat } if (field.genHash) { - html += "\n\n"; + const defaultGenHashButtonTemplate = ` + + + `; + const genHashButtonTemplate = _.get(field, 'genHashButtonTemplate', defaultGenHashButtonTemplate); + html += `${genHashButtonTemplate}\n\n`; } // Add error messages diff --git a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js index 3e8dc913b7..7463b5f9a7 100644 --- a/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js +++ b/awx/ui/client/src/templates/job_templates/add-job-template/job-template-add.controller.js @@ -44,6 +44,7 @@ $scope.parseType = 'yaml'; $scope.credentialNotPresent = false; $scope.canGetAllRelatedResources = true; + $scope.webhook_key_help = i18n._('Webhook services can use this as a shared secret.'); // // webhook credential - all handlers, dynamic state, etc. live here @@ -105,6 +106,8 @@ $scope.webhookCredential.modalSelectedName = null; }; + $scope.handleWebhookKeyButtonClick = () => {}; + $('#content-container').append($compile(` { @@ -125,7 +129,6 @@ export default $scope.webhookCredential.isModalReady = false; $scope.webhookCredential.modalSelectedId = null; $scope.webhookCredential.modalSelectedName = null; - }; $scope.handleWebhookCredentialSelect = () => { @@ -137,6 +140,23 @@ export default $scope.webhookCredential.modalSelectedName = null; }; + $scope.handleWebhookKeyButtonClick = () => { + Rest.setUrl(jobTemplateData.related.webhook_key); + Wait('start'); + Rest.post({}) + .then(({ data }) => { + $scope.currentlySavedWebhookKey = data.webhook_key; + $scope.webhook_key = data.webhook_key; + }) + .catch(({ data }) => { + const errorMsg = `Failed to generate new webhook key. POST returned status: ${status}`; + ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: errorMsg }); + }) + .finally(() => { + Wait('stop'); + }); + }; + $('#content-container').append($compile(` " + i18n._("Enabled webhook for this job template.") + "

", dataPlacement: 'right', @@ -407,10 +406,9 @@ function(NotificationsList, i18n) { type:'select', defaultText: i18n._('Choose a Webhook Service'), ngOptions: 'svc.label for svc in webhook_service_options track by svc.value', - ngShow: "enable_webhooks && enable_webhooks !== 'false'", + ngShow: "enable_webhook && enable_webhook !== 'false'", ngDisabled: "!(job_template_obj.summary_fields.user_capabilities.edit || canAddJobTemplate) || !canGetAllRelatedResources", id: 'webhook-service-select', - required: false, column: 1, awPopOver: "

" + i18n._("Select a webhook service.") + "

", dataTitle: i18n._('Webhook Service'), @@ -420,36 +418,49 @@ function(NotificationsList, i18n) { webhook_url: { label: i18n._('Webhook URL'), type: 'text', - ngShow: "enable_webhooks && enable_webhooks !== 'false'", - column: 2, + ngShow: "job_template_obj && enable_webhook && enable_webhook !== 'false'", awPopOver: "webhook_url_help", awPopOverWatch: "webhook_url_help", dataPlacement: 'top', dataTitle: i18n._('Webhook URL'), dataContainer: "body", - ngDisabled: '!(job_template_obj.summary_fields.user_capabilities.edit || canAddJobTemplate)' + readonly: true }, webhook_key: { label: i18n._('Webhook Key'), type: 'text', - ngShow: "enable_webhooks && enable_webhooks !== 'false'", + ngShow: "enable_webhook && enable_webhook !== 'false'", genHash: true, - column: 2, + genHashButtonTemplate: ` + + + + `, + genHashButtonClickHandlerName: "handleWebhookKeyButtonClick", awPopOver: "webhook_key_help", awPopOverWatch: "webhook_key_help", dataPlacement: 'right', - dataTitle: i18n._("Webhook Config Key"), + dataTitle: i18n._("Webhook Key"), dataContainer: "body", - ngDisabled: '!(job_template_obj.summary_fields.user_capabilities.edit || canAddJobTemplate)', - awRequiredWhen: { - reqExpression: 'enable_webhooks', - alwaysShowAsterisk: true - } + readonly: true, + required: false, }, webhook_credential: { label: i18n._('Webhook Credential'), type: 'custom', - ngShow: "enable_webhooks && enable_webhooks !== 'false'", + ngShow: "enable_webhook && enable_webhook !== 'false'", control: `