From 42de7e02193aa059a6b66b1137ead9f72cdc9801 Mon Sep 17 00:00:00 2001 From: Jakub Hadvig Date: Tue, 27 Nov 2018 13:30:00 +0100 Subject: [PATCH] Bug 1652645 - Webhook urls in configuration page are invalid with undefined included --- app/scripts/directives/util.js | 10 ++++++++++ app/scripts/filters/resources.js | 3 +++ app/scripts/services/secrets.js | 2 +- app/views/browse/build-config.html | 9 ++++----- .../directives/_copy-webhook-trigger.html | 12 +++++++++++ dist/scripts/scripts.js | 15 +++++++++++--- dist/scripts/templates.js | 20 +++++++++++++++---- 7 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 app/views/directives/_copy-webhook-trigger.html diff --git a/app/scripts/directives/util.js b/app/scripts/directives/util.js index e90bff8384..2703766bed 100644 --- a/app/scripts/directives/util.js +++ b/app/scripts/directives/util.js @@ -57,6 +57,16 @@ angular.module('openshiftConsole') } }; }) + .directive('copyWebhookTrigger', function() { + return { + restrict: 'E', + scope: { + webhookUrl: "=", + secretRef: "=?" + }, + templateUrl: 'views/directives/_copy-webhook-trigger.html', + }; + }) .directive('copyToClipboard', function() { return { restrict: 'E', diff --git a/app/scripts/filters/resources.js b/app/scripts/filters/resources.js index 53fa046188..90c3b7b5e0 100644 --- a/app/scripts/filters/resources.js +++ b/app/scripts/filters/resources.js @@ -182,6 +182,9 @@ angular.module('openshiftConsole') var secretsVersion = APIService.getPreferredVersion('secrets'); if (canIFilter(secretsVersion, 'list')) { secret = SecretsService.getWebhookSecretValue(secret, webhookSecrets); + if (!secret) { + return ''; + } return DataService.url({ // arbitrarily many subresources can be included // url encoding of the segments is handled by the url() function diff --git a/app/scripts/services/secrets.js b/app/scripts/services/secrets.js index 3fe332d4d9..157b79931e 100644 --- a/app/scripts/services/secrets.js +++ b/app/scripts/services/secrets.js @@ -152,7 +152,7 @@ angular.module("openshiftConsole") // to list Secrets if (_.get(secret, 'secretReference.name') && webhookSecrets) { var matchingSecret = _.find(webhookSecrets, {metadata:{name: secret.secretReference.name}}); - return decodeSecretData(matchingSecret.data).WebHookSecretKey; + return _.has(matchingSecret, 'data') ? decodeSecretData(matchingSecret.data).WebHookSecretKey : ''; } else { return _.get(secret, 'secret'); } diff --git a/app/views/browse/build-config.html b/app/views/browse/build-config.html index 3a671cf36c..c249be91de 100644 --- a/app/views/browse/build-config.html +++ b/app/views/browse/build-config.html @@ -386,29 +386,28 @@

Triggers - +
GitHub Webhook URL:
- +
GitLab Webhook URL:
- +
Generic Webhook URL:
- +
diff --git a/app/views/directives/_copy-webhook-trigger.html b/app/views/directives/_copy-webhook-trigger.html new file mode 100644 index 0000000000..4f19476664 --- /dev/null +++ b/app/views/directives/_copy-webhook-trigger.html @@ -0,0 +1,12 @@ +
+ +
+
+ + Not available +
diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index 132fd647d8..825a79ccf2 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -3371,7 +3371,7 @@ metadata: { name: e.secretReference.name } }); -return i(n.data).WebHookSecretKey; +return _.has(n, "data") ? i(n.data).WebHookSecretKey : ""; } return _.get(e, "secret"); } @@ -11128,6 +11128,15 @@ $(this).hide(), $(".reveal-contents", t).show(); }); } }; +}).directive("copyWebhookTrigger", function() { +return { +restrict: "E", +scope: { +webhookUrl: "=", +secretRef: "=?" +}, +templateUrl: "views/directives/_copy-webhook-trigger.html" +}; }).directive("copyToClipboard", function() { return { restrict: "E", @@ -15232,11 +15241,11 @@ return null; }).filter("webhookURL", [ "canIFilter", "APIService", "DataService", "SecretsService", function(e, t, n, r) { return function(a, o, i, s, c) { var l = t.getPreferredVersion("secrets"); -return e(l, "list") ? (i = r.getWebhookSecretValue(i, c), n.url({ +return e(l, "list") ? (i = r.getWebhookSecretValue(i, c)) ? n.url({ resource: "buildconfigs/webhooks/" + encodeURIComponent(i) + "/" + encodeURIComponent(o.toLowerCase()), name: a, namespace: s -})) : n.url({ +}) : "" : n.url({ resource: "buildconfigs/webhooks/", name: a, namespace: s diff --git a/dist/scripts/templates.js b/dist/scripts/templates.js index e92e6d3f4a..480c13f9b8 100644 --- a/dist/scripts/templates.js +++ b/dist/scripts/templates.js @@ -1897,28 +1897,28 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( "
Bitbucket Webhook URL:\n" + "
\n" + "
\n" + - "\n" + + "\n" + "
\n" + "
\n" + "
\n" + "
GitHub Webhook URL:\n" + "
\n" + "
\n" + - "\n" + + "\n" + "
\n" + "
\n" + "
\n" + "
GitLab Webhook URL:\n" + "
\n" + "
\n" + - "\n" + + "\n" + "
\n" + "
\n" + "
\n" + "
Generic Webhook URL:\n" + "
\n" + "
\n" + - "\n" + + "\n" + "
\n" + "
\n" + "
\n" + @@ -5422,6 +5422,18 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function( ); + $templateCache.put('views/directives/_copy-webhook-trigger.html', + "
\n" + + "\n" + + "
\n" + + "
\n" + + "\n" + + "\n" + + "Not available\n" + + "
" + ); + + $templateCache.put('views/directives/_custom-icon.html', "\"\"\n" + ""